+ Post New Thread
Results 1 to 7 of 7
Coding Thread, (Flash) AS 3.0 adding a delay to a script before proceeding to next frame in Coding and Web Development; Hello, I am in the middle of creating or trying to create an interactive game. Basically the idea of the ...
  1. #1

    Join Date
    May 2006
    Location
    West Bromwich
    Posts
    2,190
    Thank Post
    299
    Thanked 215 Times in 185 Posts
    Rep Power
    56

    (Flash) AS 3.0 adding a delay to a script before proceeding to next frame

    Hello,

    I am in the middle of creating or trying to create an interactive game. Basically the idea of the game is the user has to dress a Teddy in a space suit ready for his adventure. When the user has done this then they will be moved on to the "next level" where they have to put Teddy inside the Rocket. When they complete this bit Teddy will then take off to the Moon.

    Simple enough i thought...

    So i have got to the point where i have the first level completed. I have two ways i could tackle the progression to the next stage. 1, have a delay after the completion of the first stage or 2, have a button pop up that the user clicks to progress.

    The only problem is i don't know how to do either. I have tried looking through the help guide but to be honest may as well be in klingon . So how would i go about doing either or if someone is really good at actionscript and feeling generous, both.

    Here's the script i have so far. It all happens on frame 1, with the next part happening on whatever frame. I don't think it matters...

    Code:
    stop();
    var startX:Number;
    var startY:Number;
    var counter:Number = 0;
    head_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickUp);
    head_mc.addEventListener(MouseEvent.MOUSE_UP, dropIt);
    body_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickUp);
    body_mc.addEventListener(MouseEvent.MOUSE_UP, dropIt);
    legs_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickUp);
    legs_mc.addEventListener(MouseEvent.MOUSE_UP, dropIt);
    righthand_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickUp);
    righthand_mc.addEventListener(MouseEvent.MOUSE_UP, dropIt);
    lefthand_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickUp);
    lefthand_mc.addEventListener(MouseEvent.MOUSE_UP, dropIt);
    rightfoot_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickUp);
    rightfoot_mc.addEventListener(MouseEvent.MOUSE_UP, dropIt);
    leftfoot_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickUp);
    leftfoot_mc.addEventListener(MouseEvent.MOUSE_UP, dropIt);
    function pickUp(event:MouseEvent):void {
        event.target.startDrag(true);
    	reply_txt.text = "";
    	startX = event.target.x;
    	startY = event.target.y;
    }
    function dropIt(event:MouseEvent):void {
        event.target.stopDrag();
    	var myTargetName:String = "target" + event.target.name;
    var myTarget:DisplayObject = getChildByName(myTargetName);
    if (event.target.dropTarget != null && event.target.dropTarget.parent == myTarget){
        reply_txt.text = "Good Job!";
    	event.target.removeEventListener(MouseEvent.MOUSE_DOWN, pickUp);
    event.target.removeEventListener(MouseEvent.MOUSE_UP, dropIt);
    event.target.buttonMode = false;
    counter++;
    } else {
        reply_txt.text = "Try Again!";
    		event.target.x = startX;
    		event.target.y = startY;
    }
    if(counter == 7){
        reply_txt.text = "Well done. Teddy is now dressed!";
    }
    }
    head_mc.buttonMode = true;
    body_mc.buttonMode = true;
    legs_mc.buttonMode = true;
    righthand_mc.buttonMode = true;
    lefthand_mc.buttonMode = true;
    rightfoot_mc.buttonMode = true;
    leftfoot_mc.buttonMode = true;
    PS i found this stuff on this website if anyone is interested. Quite good really and lucky i found it to get this far.

    Hope you can help. I will share the results when i finished if anyone is daft enough to be interested. Need to touch up on the graphics though

  2. #2

    rush_tech's Avatar
    Join Date
    Jul 2006
    Location
    Nottingham
    Posts
    1,408
    Thank Post
    111
    Thanked 265 Times in 201 Posts
    Rep Power
    194
    I've no idea but I know a man that does linky ask there very helpful

  3. Thanks to rush_tech from:

    HodgeHi (25th October 2009)

  4. #3

    Join Date
    May 2006
    Location
    West Bromwich
    Posts
    2,190
    Thank Post
    299
    Thanked 215 Times in 185 Posts
    Rep Power
    56
    Thanks for that. Might just become my second home from home. This being my first of course.

  5. #4

    rush_tech's Avatar
    Join Date
    Jul 2006
    Location
    Nottingham
    Posts
    1,408
    Thank Post
    111
    Thanked 265 Times in 201 Posts
    Rep Power
    194
    Yes it's quite good! Subscribe to their mailshot they give away allsorts of flash goodies

  6. #5

    dhicks's Avatar
    Join Date
    Aug 2005
    Location
    Knightsbridge
    Posts
    5,624
    Thank Post
    1,240
    Thanked 778 Times in 675 Posts
    Rep Power
    235
    Quote Originally Posted by HodgeHi View Post
    1, have a delay after the completion of the first stage or 2, have a button pop up that the user clicks to progress.
    Option 2 sounds best - have a message on frame 2 saying "Congratulations, Teddy is now dressed!", along with a "Next" button. When your counter hits 7, instead of setting your message text, use gotoAndPlay() to go to frame 2, i.e.:

    Code:
    if(counter == 7) {
        gotoAndPlay(2);
    }
    Have your "Next" button on frame 2 have something similar to go on to frame 3 when it is clicked.

    --
    David Hicks

  7. Thanks to dhicks from:

    HodgeHi (1st November 2009)

  8. #6

    Join Date
    May 2006
    Location
    West Bromwich
    Posts
    2,190
    Thank Post
    299
    Thanked 215 Times in 185 Posts
    Rep Power
    56
    Thanks dhicks. I have only just seen your post. I will give it a go. It's been absolutely ages since i last did any Flash work, and the work i did never involved Actionscript anyway

    Thanks again. I will post up a link to show you the finish product once it's complete. Graphics have been touched up a little now. Not too good still though since i had my graphics tablet nicked when they took my Macbook pro

  9. #7

    Join Date
    Feb 2009
    Posts
    45
    Thank Post
    1
    Thanked 5 Times in 5 Posts
    Rep Power
    12

    Fade from image to image

    The following might give you an idea
    You can still load up a button & then fade/transition from that if you like

    fadeEffect.duration = FADE_IMAGE_SECONDS * 1000;
    fadeEffect.play();

    sets the timer duration & triggers it
    When the timer event fires - you action the next piece of code
    In the timer event
    Case some variable so that you can sequence through your program states
    On other events you can set the state variable and / or fire new timers



    package
    {
    import flash.display.MovieClip;
    import flash.events.Event;
    import flash.display.Loader;
    import flash.events.TimerEvent;
    import flash.net.URLRequest;
    import mx.effects.easing.Cubic;
    import mx.effects.Fade;
    import mx.events.EffectEvent;

    /**
    * ...
    * @author
    */
    public class Upton extends MovieClip
    {
    // Number of seconds to show an image file
    private const SHOW_IMAGE_SECONDS:int = 4;
    // Number of seconds to fade to next image file
    private const FADE_IMAGE_SECONDS:int = 2;
    // Number of image files to loop through
    // files are to be found in /images
    // images files are to be named image1.jpg, image2.jpg .....
    private const MAX_IMAGES:int = 17;

    private var index:int = 1;
    private var fadeEffect:Fade = new Fade();
    private var loader:Loader = new Loader();

    public function Upton()
    {
    // setup Image loader
    loader.contentLoaderInfo.addEventListener(Event.CO MPLETE, imgLoaded);
    // setup Fader
    fadeEffect.addEventListener(EffectEvent.EFFECT_END , fadeComplete);
    fadeEffect.startDelay = 0;
    fadeEffect.easingFunction = Cubic.easeInOut;
    fadeEffect.alphaFrom = 1;
    fadeEffect.target = this;
    // Load 1st image
    loadMyImage();
    }

    private function fadeComplete(e:EffectEvent):void
    {
    // fade complete -
    if (fadeEffect.alphaTo == 1)
    {
    fadeEffect.alphaTo = 0;
    fadeEffect.duration = FADE_IMAGE_SECONDS * 1000;
    fadeEffect.play();
    }
    else
    {
    removeChildAt(0);
    // load next image
    if (index > MAX_IMAGES) {
    index = 1;
    }
    loadMyImage();
    }

    }

    function loadMyImage():void
    {
    var urlReq:URLRequest = new URLRequest("images/image" + index++ + ".jpg");
    loader.load(urlReq);
    }

    private function imgLoaded(e:Event):void
    {
    var loader4:Loader = Loader(e.target.loader);
    addChild(loader4.content);
    fadeEffect.alphaTo = 1;
    fadeEffect.duration = SHOW_IMAGE_SECONDS * 1000;
    fadeEffect.play();
    }
    }

    new Upton();
    }

SHARE:
+ Post New Thread

Similar Threads

  1. [Video] Typhoon hits Hong Kong in stop frame.
    By mattx in forum Jokes/Interweb Things
    Replies: 0
    Last Post: 7th October 2009, 08:07 AM
  2. Action Script 2.0 to 3.0 CS4 Flash
    By andy_nic in forum Coding
    Replies: 0
    Last Post: 28th July 2009, 08:28 AM
  3. Digital Photo Frame
    By penfold in forum General Chat
    Replies: 10
    Last Post: 22nd December 2008, 08:42 AM
  4. Script to delay Trend Update
    By mattx in forum Scripts
    Replies: 3
    Last Post: 10th November 2008, 08:46 PM
  5. Script not deleting/adding printer correctly
    By dave.81 in forum Scripts
    Replies: 2
    Last Post: 5th June 2008, 01:17 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •