dcsimg
A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: smoothing as3 animation

  1. #1
    Junior Member
    Join Date
    Nov 2010
    Posts
    18

    smoothing as3 animation

    Hi,

    I have a scrolling/zoom in animation done in as3. At times the animation is jerky. I am wondering how I can possibly smooth this out. I am using several quite large mc's that are all being manipulate at the same time. Would it help to make mc's that are off the screen invisible until they are visually needed? I am very new to flash/as3 so I don't know a lot about what might slow down the animation. Any suggestions would be very helpful.

    I am working in cs4. Here is a link to the page I am working on. It is mostly the "Harman" button that I am getting this jerkiness on and then only sometimes. Hover over the logo to expand the menu. I wonder if I just have too much going on at the same time?

    The code I am working with is this:
    Code:
    var harmanTimerIn:Timer = new Timer(40,20);
    harmanTimerIn.addEventListener(TimerEvent.TIMER, harmanAniIn);
    function harmanAniIn(evt:TimerEvent): void {
    	//trace(harmanTimerIn.currentCount);
    	var heightChange:Number = swfHeight/6;
    	var heightChange2:Number = swfHeight/20;
    	if(harmanTimerIn.currentCount > 5 && harmanTimerIn.currentCount < 16) {
    		var preWidth:Number = pan4_7.width;
    		pan4_7.height = pan4_7.height+heightChange;
    		pan4_7.width = pan4_7.height*pan4_7AR;
    		pan4_7.y = pan4_7.y-(heightChange/2);
    		pan4_7.x = pan4_7.x-(pan4_7.width-preWidth)/4;
    		preWidth = pan1_3.width;
    		pan1_3.height = pan1_3.height+heightChange;
    		pan1_3.width = pan1_3.height*pan1_3AR;
    		pan1_3.y = pan1_3.y-(heightChange/2);
    		pan1_3.x = pan4_7.x-pan1_3.width;
    		preWidth = hpan3_6.width;
    		hpan3_6.height = hpan3_6.height+heightChange2;
    		hpan3_6.width = hpan3_6.height*hpan3_6AR;
    		hpan3_6.y = hpan3_6.y-((heightChange2/2)+(heightChange2/10));
    		hpan3_6.x = hpan3_6.x-(hpan3_6.width-preWidth)/4;
    		preWidth = hpan1_2.width;
    		hpan1_2.height = hpan1_2.height+heightChange2;
    		hpan1_2.width = hpan1_2.height*hpan1_2AR;
    		hpan1_2.y = hpan1_2.y-((heightChange2/2)+(heightChange2/10));
    		hpan1_2.x = hpan3_6.x-hpan1_2.width;
    		preWidth = hpan7_9.width;
    		hpan7_9.height = hpan7_9.height+heightChange2;
    		hpan7_9.width = hpan7_9.height*hpan7_9AR;
    		hpan7_9.y = hpan7_9.y-((heightChange2/2)+(heightChange2/10));
    		hpan7_9.x = hpan3_6.x+hpan3_6.width;
    	}
    	if(harmanTimerIn.currentCount > 15) {
    		pan4_7.alpha -= .2;
    		pan1_3.alpha -= .2;
    		pan8_10.alpha -= .2;
    	}
    	if(harmanTimerIn.currentCount == 20) {
    		pan4_7.visible=false;
    		pan1_3.visible=false;
    		pan8_10.visible=false;
    		pan11_13.visible=false;
    		pan14_16.visible=false;
    		logoMain.visible=false;
    		scrollSwitch = "on";
    		page_close.visible=true;
    		harmanTimerIn.stop();
    		harmanTimerIn.reset();
    	}
    }
    Thanks in advance for any help you can give.

  2. #2
    Mod cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    Quote Originally Posted by apersonbeing View Post
    Hi,

    I have a scrolling/zoom in animation done in as3. At times the animation is jerky. I am wondering how I can possibly smooth this out. I am using several quite large mc's that are all being manipulate at the same time.
    You have given the answer for the problem by yourself.
    - The right of the People to create Flash movies shall not be infringed. -
    | www.Flashscript.biz | Flashscript Biz Classes/Components |

  3. #3
    Junior Member
    Join Date
    Nov 2010
    Posts
    18
    So too much at once eh. Would changing the visibility of unseen mc's help at all? Any ideas on how I could lessen the load? Thanks for replying.

  4. #4
    Mod cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    I don't think the visibility affects the performance. I would reduce the size of the objects or reduce the number of animations playing at once.
    - The right of the People to create Flash movies shall not be infringed. -
    | www.Flashscript.biz | Flashscript Biz Classes/Components |

  5. #5
    Junior Member
    Join Date
    Nov 2010
    Posts
    18
    Alright, thanks again.

  6. #6
    Senior Member
    Join Date
    Nov 2001
    Posts
    1,145
    You should use this as last line in your timer event function so that the timer can run independently of than the fps - otherwise your timer will only fire as fast as the fps:

    evt.updateAfterEvent();

    Any loaded jpg or png is a drain on cpu even if it isn't visible or showing. With large pics or large numbers of pics, you should load and unload them as needed - unload() the loader and delete any references to it.
    Last edited by moot; 11-05-2010 at 04:18 PM.

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