Search code examples
actionscript-3flashframes

as3 totalFrames return 1


I am trying to load one animation.
I want to know the end of the animation and avoid it in a loop.

var myLoader:Loader = new Loader( );
var myLoaderReq:URLRequest = new URLRequest("anim.swf");
myLoader.load(myLoaderReq);
addEventListener(Event.ENTER_FRAME , enterFrameListener );
addChild(myLoader);

myLoader.x = 10;
myLoader.y = 20;


function enterFrameListener(event:Event):void
{
  var mc:MovieClip = event.currentTarget as MovieClip;

  trace(mc.currentFrame);
  if( mc.currentFrame == mc.totalFrames )
  {
      mc.removeEventListener(Event.ENTER_FRAME , enterFrameListener );
      trace("end of movie reached");
  }
}

for test i uses swf downloaded from http://www.leconcombre.com/movies/movies1us.html

any ideas how to do that?

thnx


Solution

  • The currentTarget you are using is refer to

    addEventListener(Event.ENTER_FRAME , enterFrameListener );
    

    Which should be your MainTimeline, if you add one more frame then should be return 2 of totalFrames.

    As BadFeelingAboutThis saids, just replace:

    var mc:MovieClip = event.currentTarget as MovieClip;
    

    by

    var mc:MovieClip = myLoader.content as MovieClip;
    

    You also have to confirm you are attempting to manipulate the MainTimeline of anim.swf.