EnterFrame vs Timer

Published to AIR for android my app and it runs smooth.. but on iPhone the app gets real chunky when my EnterFrame function is called..  I am going to try switching to a Timer event, but wondering what others have experienced.. will it make a noticible difference in performance?

also as far as hardware acceleration what do people experience as the optimal settings.. and whats the difference between the flash and packager acceleration?

Similar Messages

  • Flash Slideshow - playpausebutton

    I have created a slideshow based on the template for slideshow provided by Flash and some other blogs posts i have found.
    I have a layer with a picture on consecutive frames.
    I have another later that has just my text to display always.
    I have created another layer called Buttons and in the first keyframe i typed stop();  And added buttons by draging and dropping <back button
    and > foward button. I used script:
    for the back button
    on (release) {
    if (this._currentframe == 1) {
    gotoAndStop (this._totalframes);
    } else {
    prevFrame ();
    and for the foward
    on (release) {
    if (this._currentframe == this._totalframes) {
    gotoAndStop (1);
    } else {
    nextFrame ();
    I have gotten them to work if you hit the button, it changes to the next picture.
    I want the pictures to continously play and i want to add a Pause/Play button .
    If you hit the pause it will stop and then you can resume the slideshow by hitting the button again which will be a Play button.
    I cannot #1 get the show to just move on its own (i guess i have to add additional frames to each photo?)
    I have been searching for a Pause Play button ALLLLL day. Please help.

    1.From what I understand you got the scope of the buttons wrong.
    I suppose you want to do this:
    for the back button
    on (release) {
    //in this case "this._parent" adresses the main timeline
    if (this_parent._currentframe == 1) {
    this_parent.gotoAndStop (this_parent._totalframes);
    } else {
    this_parent.prevFrame ();
    //same thing for the fwd button
    2.If you find the setInterval function to much effort you can always "cheat" a timer with enterFrame
    var timer = 0;
    var playing:Boolean = true;
    //the framerate of your movie
    var framespersecond= 30;
    _root.onEnterFrame{
      if(playing){
       timer++;
       if(timer%(5*framespersecond)){
         dosomethingevery5seconds();
         //reset timer to reduce counting time
         timer=0;
    function dosomethingevery5seconds():void{
      //go to the next picture after 5 seconds;
    _root.nextFrame();
    pause_btn.onRelease = function(){
      playing = false;
    play_btn.onRelease = function(){
      playing = true;

  • Handle stage RESIZE.Event

    I've a flash site 100x100% in browser window.
    When I open new tab in browser window Event.RESIZE doesn't
    dispatched.
    Have any idea how to handle this event except EnterFrame or
    Timer listeners?

    stage.scaleMode = StageScaleMode.NO_SCALE;
    var count = 0;
    stage.addEventListener(Event.RESIZE, resizeHandler);
    function resizeHandler(evt:Event):void {
    _txt.text = count++;
    use this code

  • An enterFrame event and a timer conflict

    I have a hitTest on an enterFrame event that adds a movieClip.
    I then want the movie clip to be on a timer that changes it to another movieClip.
    As you can imagine, there is a conflict because the hitTest always finds the original Mc an so over-rides the timer.
    I know this is a logic problem but I cant seem to figure it out.I am pretty sure I am thinking about this the wrong way.
    any suggestions?
    here is some of the code:
    //this is the hitTest
    this.addEventListener(Event.ENTER_FRAME,leftPillarHit);
    function leftPillarHit(ev:Event):void {
    if (drawer.myCursor.hitTestObject(leftPillarHitTest)) {
    rightPillar.visible=false;
    leftPillar.visible=true;
    if(leftPillar.visible=true){
    movieClipTimer.start();
    this is the timer:
    rightPillar.visible=false;
    //swap two movie clips on timer
    var movieClipTimer:Timer=new Timer(5000,0);
    movieClipTimer.addEventListener(TimerEvent.TIMER, changeImage);
    function changeImage(evt:TimerEvent):void {
    leftPillar.visible=! leftPillar.visible;
    rightPillar.visible=! rightPillar.visible;

    I don't know that this will solve the problem (I don't understand the problem), but the following line is not correct:
    if(leftPillar.visible=true){
    should be either
    if(leftPillar.visible==true){
    OR
    if(leftPillar.visible){

  • Timer to enterframe problem

    I had a problem earlier of building a grid of boxes for an animated mask. I had figured that out. All the boxes will scale up together to fill the stage as a mask.
    I've been trying to add a timer to add a delay to each row or colum (depending on which way I want to animate) scaling up, before it gose to the next series.
    This is what I have that would scale it all at once. (place it into a moviceclip, and ad the mask command in the maintimeline, and wha-la)
    function buildgrid ()
    for (var c:Number= 0; c <= (colofboxs-1); c++)
    for (var i:Number= 0; i <= (rowofboxs-1); i++)
    square=new box();
    square.y=((betweenclum+square.height)*c) + (square.height/2)
    square.x=((betweenrow+(square.width))*i)+ (square.width/2)
    //square.scaleX=0
    //square.scaleY=0
    addChild(square)
    //square.addEventListener(Event.ENTER_FRAME, scaleit)
    function scaleit(event:Event)
    //my_mc.mask = boxes[10];
    //event.target.scaleX +=.02;
    //event.target.scaleY +=.02;
    if (event.target.scaleX>=1.5)
    event.target.removeEventListener(Event.ENTER_FRAME, scaleit);
    When I tried different combination of timers, it always built the whole thing (without a delay)
    Can anyone help with this problem?

    Thanks for the reply, but I was able to get it to work.
    The problem was the first loop. it appeared to complete its loop(s) before calling the function
    (not sure if that is the actual reason)
    I substittuted the first function with an if statement (replacing the loop). Since its not trying to execute all of it loops,
    it passed the info needed onto the other function once, the other function ran its loop, increased the conditional variable (c)
    by one. The timer then delayed and called the the first function to compare the condition and continue, or stop.
    var square:box;
    square=new box();
    var rowofboxs:Number=(Math.floor(stage.stageWidth/square.width)-1);
    var colofboxs:Number=(Math.floor(stage.stageHeight/square.height)-1);
    var betweenrow:Number=(stage.stageWidth-(square.width*rowofboxs))/(rowofboxs-1)
    var betweenclum:Number=(stage.stageHeight-(square.height*colofboxs))/(colofboxs-1)
    var c:Number=0
    var scalerate:Number=.05
    var maskTimer:Timer= new Timer(1,1)
    maskTimer.addEventListener(TimerEvent.TIMER,colum)
    maskTimer.start();
    function colum(e:Event)
    if (c<= (colofboxs-1))
    row()
    function row()
    for (var r:Number= 0; r <= (rowofboxs-1); r++)
    square = new box();
    square.y=((betweenclum+square.height)*c) + (square.height/2)
    square.x=((betweenrow+square.width)*r) + (square.width/2)
    square.scaleX=.25
    square.scaleY=.25
    addChild(square);
    square.addEventListener(Event.ENTER_FRAME, scaleup);
    c+=1
    maskTimer.delay=3000;
    maskTimer.reset();
    maskTimer.start();
    function scaleup (event:Event)
    if (event.target.scaleX<=1.5)
    event.target.scaleX+=.05
    event.target.scaleY+=.05
    else
    event.target.removeEventListener(Event.ENTER_FRAME, scaleup);

  • I need help moving two objects at the same time

    I am try to create a code that will move a mini map to where the user wants in a game. As a test I created a square and converted it to a movie and named it sq. Then I created another square and converted it to a button and named it bt. I also made bt half the size of sq and placed bt at the center of sq. I then created a drag code which like this:
    sq.addEventListener(MouseEvent.MOUSE_DOWN, startDragging); // Start dragging square by user
    sq.addEventListener(MouseEvent.MOUSE_UP, stopDragging); // Stop dragging square by user
    function stopDragging(evt:MouseEvent):void
    sq.stopDrag();
    bt.x=sq.x;
    bt.y=sq.y;
    // this moved bt to sq(x,y) when mousebutton was released
    function startDragging(evt:MouseEvent):void
    sq.startDrag();
    bt.x=sq.x;
    bt.y=sq.y;
    // this moved bt to sq(x,y) when mouse button was pushed down
    I am trying to get sq and bt to move smootly together, but as it stands right now it just jumps from place to place.
    I have tried looking for some kind of linking code in abode help search, however, I am not sure want to look for exactlly

    The mouseDown and mouseUp events are single action events, so the button will only change positions on either the mouseDown or the mouseUp events. If you add a mouseMove event listener, then you can change the location of the button every time the square moves. Alternately, you could use an enterframe event to change the location of the button relative to the square. Try this code:
    sq.addEventListener(MouseEvent.MOUSE_DOWN, startDragging); // Start dragging square by user
    sq.addEventListener(MouseEvent.MOUSE_UP, stopDragging); // Stop dragging square by user
    sq.addEventListener(MouseEvent.MOUSE_MOVE,dragButton);
    function stopDragging(evt:MouseEvent):void
    sq.stopDrag();
    function startDragging(evt:MouseEvent):void
    sq.startDrag();
    function dragButton(evt:MouseEvent):void {
              bt.x = sq.x;
              bt.y = sq.y;

  • Movie bundle one at a time?

    If I buy a movie bundle, will I be able to load one movie at a time to my iPad to save memory? I plan to load one movie at a time on my iPad when I need it to save memory space at all times.

    CLBeech, Thank you very much! That script finally worked, but
    I did have to add an enterFrame function to make it work because
    the function was not activating when I entered the frame. Here is
    the code I added:
    onEnterFrame = function () {
    removeBrick();}
    The problem with this is that the bricks unload at the frame
    rate I have set rather than at the designated interval, so they are
    very slow. I seem to be missing something. How can I get the
    removeBrick function to play when I enter the frame without calling
    out an enterFrame command?
    Thanks for all your help. This is a load off of my mind just
    to get that code working.

  • Sound to play one at a time

    How do I make a command saying:
    if sound is playing - dont play sound, else, play sound?
    so that the sound effect only plays one at a time. So if holding down SPACEBAR for example, the sound will play and only after the sound finishes, can it loop if SPACEBAR is still pressed.
    Thanks in advance.

    Ok, I'll just copy and paste the relevent parts: (This is for a car-racing game)
    onClipEvent(enterFrame)
         HAND = Key.isDown(Key.SPACE)
         if (HAND) {
            speed  *= handbrake
            //sound
            var screechSnd:Sound = new Sound();
            screechSnd.attachSound("TireScreech");
               screechSnd.start();
            // SKIDDIES
            if (speed > MAXskiddisplay) {
            steer = steer_handbrake;
            if (!skidding) setLastpos();
            skidding=skid(HAND);}
            traction = handbrake_traction/surface; }
        else {
            skidding=false;
            traction = Math.max(traction_max, Math.abs((speed-MAXturnSpd)/surface))
            steer = steer_normal }
    So basically, when the handbrake (spacebar) is pressed, the handbrake effect will be applied to the car and it will skid (which works), but the problem is I also want a sound to play when it spacebar is pressed.
    The sound does play, however, when pressed, the sound plays many times over at the same time, rather than letting the sound finish for the sound to repeat itself again (if spacebar is still pressed - that is).
    Thanks again in advance

  • How can I make a Day countdown timer in flash

    Here's my code, and below the code is the error message
    // register function
    addEventListener('enterFrame',daytimer_handler);
    // calls repeatedly
    function daytimer_handler(evt:Event):void{
    // current date
    var today:Date = new Date(2013, 4, 22);
    // current Year
    var currentYear = today.getFullYear(2013);
    // current month
    var currentMonth = today.getMonth(April);
    // current day
    var currentDay = today.getDate(Monday);// current time
    var currentTime = today.getTime(12:00:00 PM);
    // target date (5 days from now change to your need
    var targetDate:Date = new Date(currentYear, currentMonth, currentDay+5);
    var targetDay = targetDate.getTime(April/27/2013);
    // time remaining
    var timeLeft = targetDay-currentTime;
    var sec = Math.floor(timeLeft/1000);
    var min = Math.floor(sec/60);
    var hours = Math.floor(min/60);
    var days = Math.floor(hours/24);
    // convert sec to string
    sec = String(sec%60);
    // if less than add a 0
    if (sec.length<2) {
    sec = "0"+sec;
    min = String(min%60);
    if (min.length<2) {
    min = "0"+min;
    hours = String(hours%24);
    if (hours.length<2) {
    hours = "0"+hours;
    days = String(days);
    if (timeLeft>0) {
    // display day string
    var dayCounter:String = days;
    timer_display.text = dayCounter;
    } else {
    trace("Happy Birthday!");
    var newTime:String = "0";
    timer_display.text = newTime;
    removeEventListener('enterFrame',daytimer_handler);
    error message:
    Description:
    1084: Syntax error: expecting rightparen before colon.  
    Source:
    var currentTime = today.getTime(12:00:00 PM)

    There are numerous syntax errors in your code, especially usage of Date methods - getFullYear, getMonth, etc. To begin with, this code should look like this:
    import flash.events.Event;
    // register function
    addEventListener(Event.ENTER_FRAME, daytimer_handler);
    // calls repeatedly
    function daytimer_handler(e:Event):void
    // current date
              var today:Date = new Date(2013, 4, 22);
    // current Year
              var currentYear = today.getFullYear();
    // current month
              var currentMonth = today.getMonth();
    // current day
              var currentDay = today.getDate(); // current time
              var currentTime = today.getTime();
    // target date (5 days from now change to your need
              var targetDate:Date = new Date(currentYear, currentMonth, currentDay + 5);
              var targetDay = targetDate.getTime();
    // time remaining
              var timeLeft = targetDay - currentTime;
              var sec = Math.floor(timeLeft / 1000);
              var min = Math.floor(sec / 60);
              var hours = Math.floor(min / 60);
              var days = Math.floor(hours / 24);
    // convert sec to string
              sec = String(sec % 60);
    // if less than add a 0
              if (sec.length < 2)
                        sec = "0" + sec;
              min = String(min % 60);
              if (min.length < 2)
                        min = "0" + min;
              hours = String(hours % 24);
              if (hours.length < 2)
                        hours = "0" + hours;
              days = String(days);
              if (timeLeft > 0)
    // display day string
                        var dayCounter:String = days;
                        timer_display.text = dayCounter;
              else
                        trace("Happy Birthday!");
                        var newTime:String = "0";
                        timer_display.text = newTime;
                        removeEventListener('enterFrame', daytimer_handler);

  • Countdown Timer Error Msg: "Warning: 1090: Migration issue"

    Hey folks,
    New to Flash here (using CS3), trying to create a countdown
    timer.
    Following is the error message I receive when trying to test
    the
    movie:
    "Warning: 1090: Migration issue: The onEnterFrame is not
    triggered
    automatically by Flash Player at run time in ActionScript
    3.0. You
    must first register this handler for the event using
    addEventListener
    ( 'enterFrame', callback_handler).
    Does anyone know what this means? And please "dumb it down"
    for this newbie. :)
    Following is the actionscript I'm using:
    this.onEnterFrame = function() {
    var today:Date = new Date();
    var currentYear = today.getFullYear();
    var currentTime = today.getTime();
    var targetDate:Date = new Date(2007,5,10);
    var targetTime = targetDate.getTime();
    var timeLeft = targetTime - currentTime;
    var sec = Math.floor(timeLeft/1000);
    var min = Math.floor(sec/60);
    var hrs = Math.floor(min/60);
    var days = Math.floor(hrs/24);
    sec = String(sec % 60);
    if (sec.length < 2) {
    sec = "0" + sec;
    min = String(min % 60);
    if (min.length < 2) {
    min = "0" + min;
    hrs = String(hrs % 24);
    if (hrs.length < 2) {
    hrs = "0" + hrs;
    days = String(days);
    var counter:String = days + ":" + hrs + ":" + min + ":" +
    sec;
    time_txt.text = counter;
    Thanks in advance!!!

    It just means that you can't do things the "old" way. You
    have to use the
    AS3 event model, like so:
    this.addEventListener("enterFrame", enterFrameHandler);
    function enterFrameHandler(evt:Event) {
    var today:Date = new Date();
    var currentYear = today.getFullYear();
    var currentTime = today.getTime();
    var targetDate:Date = new Date(2007,5,10);
    var targetTime = targetDate.getTime();
    var timeLeft = targetTime - currentTime;
    var sec = Math.floor(timeLeft/1000);
    var min = Math.floor(sec/60);
    var hrs = Math.floor(min/60);
    var days = Math.floor(hrs/24);
    sec = String(sec % 60);
    if (sec.length < 2) {
    sec = "0" + sec;
    min = String(min % 60);
    if (min.length < 2) {
    min = "0" + min;
    hrs = String(hrs % 24);
    if (hrs.length < 2) {
    hrs = "0" + hrs;
    days = String(days);
    var counter:String = days + ":" + hrs + ":" + min + ":" +
    sec;
    time_txt.text = counter;

  • Is it possible to make a timer with AS3 which is accurate upto one millisecond.

    I am new to AS3. I have somehow developed a auditory and visual reaction timer by taking script from here and there. I know its not accurate and I also know that I will write it correctly when I have learned the script thoroughly,
    But I was checking the net about the timer class and various posts on it and  I am vexed with a question "if its possible to make an accurate timer with AS3?" can somebody please tell me for sure. and I will be grateful if I know how to make it correctly. I can post the code which I have written ( assembled ).

    the answer is, maybe. but for, for most coders, the answer is, no.
    getTimer() is accurate to within 1 ms.  but that allows you to determine time/elapsed time and does not call or execute code on a regular timed schedule. it can be used with the timer class or enterframe events to do some things accurately.
    however, the timer class is not accurate in the way beginning coders think.  it will, on average, allow calling a function at close to the designated interval if there are no performance issues with your swf.  it does not allow each function call to occur at a regular interval.

  • Weird doubles in "on enterFrame"

    I have striped my projects in order to nail down a problem to the bare 1 movie script with:
    on enterFrame
      put _movie.frame
    end enterFrame
    And for some weird reason, I consistently get doubles like this in the Msg window:
    -- 1
    -- 1
    -- 2
    -- 2
    -- 3
    -- 3
    -- 4
    -- 4
    I tried doing a new movie from scratch just to check, but it seems fine. Why would that
    happen in my old movie? I checked tempo, doesn't change anything, removed xtras,
    double checked some preferences that might influence but nothing.
    If you have had this problem before and found out the source let me know,
    Thank you
    I have this with Trace on:
    == Frame: 1
    --> put _movie.frame
    -- 1
    --> end enterFrame
    --> put _movie.frame
    -- 1
    --> end enterFrame
    == Frame: 2
    --> put _movie.frame
    -- 2
    --> end enterFrame
    --> put _movie.frame
    -- 2
    --> end enterFrame
    == Frame: 3
    --> put _movie.frame
    -- 3
    --> end enterFrame
    --> put _movie.frame
    -- 3
    --> end enterFrame
    What on earth causes this?
    Message was edited by: SunLight

    Try changing your handler to this:
    on enterFrame me
      put _movie.frame, me
    end enterFrame
    I am guessing that you created a behavior and attached it to a sprite, and then you later changed that behavior to a movie script.
    If I am right, then you might see something like:
    -- 1 <offspring "" 4 532f770>
    -- 1 <Void>
    -- 2 <offspring "" 4 532f770>
    -- 2 <Void>
    The sprite receives the #enterFrame event and prints out the frame number plus its value of "me", then the same script receives the #enterFrame event as a movie event, but this time the value of "me" is VOID.
    However, this interpretation depends on you have at least one sprite in your barebones movie, in addition to your movie script.
    Another possible suspect might be a timeOut object, which can send additional movie events to behaviors, but that does not fit the description that you have given.

  • Two-dimensional time-line?

    hi, everybody:
    There are two frames in the time-line: frame 1 has a static movie clip naming "mcRect" in which a rectangle was drawn, and frame 2 has something different with frame 1.
    I put some scripts on frame1, as bellow:
    // --- my script begin ------------------------------------------
    stop();
    var i: Number = 0;
    this.onEnterFramw = function()
         mcRect._x = mcRect._y = ++i;
    // --- my script end --------------------------------------------
    When i test the movie, it stop at frame 1 as expected, mean that the time-line has been halted.
    But the movie clip "mcRect" namely the rectangle keep moving down-right with the frame rate, this like there has another time-line which is perpendicular to the main time-line.
    Is this guess right ?
    Does anybody knows the inside detail of the time-line concept?

    It is behaving as I told you.  Your definition of what happens during the enterframe is defined in the function...
    this.onEnterFrame = function()
         mcRect._x = mcRect._y = ++i;
    The line you added is outside of that function so it will not execute more than once.

  • Once a timer is at 40 go to the next frame.

    Hey there,
    When a timer in my game hits 40 I want it to go to the next frame. Here is what I have:
    onClipEvent (enterFrame) {
              var atFrame:Boolean = false;
              if (_root.timer == 40) {
                        atFrame = true;
              } else {
                        _root.timer++;
              if (atFrame == true) {
                        myRandom = random(3);
                        if (myRandom == 0) {
                                  gotoAndStop("game1");
                        if (myRandom == 1) {
                                  gotoAndStop("game2");
                        if (myRandom == 2) {
                                  gotoAndStop("game3");
    Where "game1-3" are the names of my frames. And timer is the name of my dynamicText.
    Any suggestions as to why this isn't working would be greatly appreciated.
    Kind Regards, Eric

    first of all your variable must be initiated
    _root.timer=0
    Yor code is insede a MovieClip?
    I change the code
    _root.timer = 0;
    onClipEvent (enterFrame) {
              var atFrame:Boolean = false;
              if (++_root.timer == 40) {
                        goGame();
    function goGame() {
         myRandom = int(Math.random()*3);
          if (myRandom == 0) {
              _root.gotoAndStop("game1");
         if (myRandom == 1) {
              _root.gotoAndStop("game2");
         if (myRandom == 2) {
              _root.gotoAndStop("game3");

  • ExitFrame is executing 3 times, not once

    I have an exitFrame function in a Behavior script placed on
    frame 10 of my score. Inside of it, there are a pair of trace
    statements, and a function is called. The two trace statements and
    the function execute three times, where I expect that they would
    only fire once. What is causing this? Does the play head exit the
    frame three times? Do I need to delete the whole thing after it
    executes once?
    There is a 3D sprite on the stage that is introduced at frame
    10. Does this create some sort of stutter in the playback?

    Do you have any other scripts on the same screen that use an
    updateStage() command? That will cause everything on the
    stage to
    re-run their prepareFrame, enterFrame, and exitFrame scripts

Maybe you are looking for