Skip to main content
Participating Frequently
August 5, 2009
Question

FrameRate and AS animation

  • August 5, 2009
  • 2 replies
  • 1227 views

I am doing a simple animation by loading in 11 images to the display list and then setting their visible property true of false in the following loop

private function onEnterframe(event:Event):void {

if (moveFlag)

{

if (InDirect)

{

if (visble < 10)

{

layr.getChildAt(visble).visible = false;

layr.getChildAt(visble+1).visible = true;

visble++;

etc...

The problem is that this appear to execute all ant once going from the first animation to the last with out any intervening images. I have lowered the frame rate to as low as one frame per second and it still does not work. I've traced this and found that the visible property of each image does get set to true.

It does work if I tie the eventlistener to a more discrete event such as mouseDown.

Thanks.

Mike H

This topic has been closed for replies.

2 replies

sleezoVTAuthor
Participating Frequently
August 6, 2009

Well, your's surely works like it is supposed to (and I appreciate the example). Is there any reason that an Enter_Frame event would occur more rapidly when it is in .as file as opposed to a frame script?  Tracing my code, the Enter_Frame is being called much faster than 24 fps.

kglad
Community Expert
Community Expert
August 6, 2009

if an enterframe listener function is being called more rapidly than the swf's fps, you have more than one listener calling that function.

sleezoVTAuthor
Participating Frequently
August 6, 2009

Bingo!

What I didn't realize was that

addEventListener(Event.ENTER_FRAME,onEnterframe);

was inside the loop I used to load in the images and so every time I added an image/layer I also added another listener--11 of them!

I moved the addEventListern out of the loop and used your suggested code

this.addEventListener(Event.ENTER_FRAME,onEnterframe);

so I only had on-- this did the trick.

Thanks!

Mike

kglad
Community Expert
Community Expert
August 5, 2009

do all those display object start with their visible property = true or = false?

sleezoVTAuthor
Participating Frequently
August 5, 2009

all but the first is set visible  = false.

kglad
Community Expert
Community Expert
August 5, 2009

and what's calling onEnterframe()?