A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: Image movement during runtime

  1. #1
    Member
    Join Date
    Sep 2010
    Posts
    32

    Image movement during runtime

    I want my image to move during runtime?

    1. Load image with Loader.
    2. Transfer image to ImageDisplay variable.
    3. Add Child to display at index 1.
    4. Start timer delayed by 2 Sec.
    5. Once timer ends, add ImageDisplay inside enterframe function

    Is there a way to handle or get a return from the timer once its done?
    Making a gallery that slide last image out the way with intervals of 2 sec,
    is there a better way to do this?

    Layer 1:
    Basically, When image loads, wait 2 seconds
    Actionscript Code:
    var imageNumber:Number = 0;

    var imageDisplay:Bitmap = new Bitmap;

    // Setting Timer
    var imageChg:Timer = new Timer(2000, 1);
        imageChg.addEventListener(TimerEvent.TIMER, chgNow);
       
             function chgNow(e:TimerEvent):void{
           
                      Now I want image to move left during runtime inside Layer 2
                     ~Ex. every frame move 10 px left?
             }

    // Loading Image
    var imageLoader:Loader = new Loader();
        imageLoader.load(new URLRequest('/images/'+fileNames[imageNumber]));
        imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoaded);
           
            function imageLoaded(e:Event):void{
           
                // Transfer Image
                imageDisplay = Bitmap(imageLoader.content);
                addChildAt(imageDisplay, 1);
               
                // Change Image after 2 Sec
                imageChg.start();
             }

    Layer 2:
    How to trigger image movement once timer complete?
    Actionscript Code:
    stage.addEventListener(Event.ENTER_FRAME,myFunction);
               
        function myFunction(event:Event) {
           
                  If(imageChg == Done){ <~~~~~~?

                        imageDisplay.x -= 10;
                  }

           
        }
    Last edited by onenonly; 05-21-2012 at 01:30 AM.

  2. #2
    Total Universe Mod jAQUAN's Avatar
    Join Date
    Jul 2000
    Location
    Honolulu
    Posts
    2,429
    Just add a listener to your Timer for TimerEvent.TIMER_COMPLETE and in its handler, assign the enter frame listener.

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center