views:

154

answers:

2

I'd like to load and onload mc's on the stage when certain buttons are pressed.

The catch is that whilst one of the mc's is playing I dont want any of the buttons to work -- in other words the user has to wait for the short anim to stop playing before they press another button to see another anim (or even the same anim again).

I'm OK with basics of AS2, but I want to do this in AS3.
Is attachMovie and removeMovieClip still the approp method to load/unload mc's from library in AS3.
I'm also unsure how to check if mc is playing in AS3 (is there a property? or maybe set a global variable?).

Any ideas??

A: 

This is the place to start.

bhups
A: 

you want something like:

myBtn.addEventListener(MouseEvent.CLICK,onMyBtnClick)

function onMyBtnClick(e:MouseEvent)
{
   //TODO disable buttons

   //export for actionscript setting in library
   var myMovie:SomeMovieClipFromLibrary = new SomeMovieClipFromLibrary(); 
   addChild(myMovie);
   myMovie.addEventListener(Event.ENTER_FRAME,onMovieEnterFrame);
   myMovie.play();

}

function onMovieEnterFrame(e:Event)
{
  if(e.currentTarget.currentFrame ==e.currentTarget.totalFrames)
  {
    //TODO enable buttons
    e.currentTarget.removeEventListener(Event.ENTER_FRAME,onMovieEnterFrame);
    removeChild(e.currentTarget as DisplayObject);

  }

}
Allan
Thankyou - I am getting somewhere with this approach (it adds the mc) except I receive error 1118 (Implicit coercion of a value with static type Object to a possibly unrelated type flash.display:DisplayObject) in relation to the line of code: removeChild(e.currentTarget);Any thoughts?
ss
To overcome the referencing problem I had with removeChild(e.currentTarget), I have had some success using addChildAt(myMovie, 0) and removeChildAt(0). The use of a consistent index also ensured that only one mc was playing at a time --- this was another feature I needed for this app.
ss
ah yes I think the error was because it should have been removeChild(e.currentTarget as DisplayObject). I will edit it to fix this. Be careful about removing based on indexes, its easy for them to change if you happen to add other display objects. If you use the updated code and ensure that you enable and disable buttons then there should only be one movie playing at a time (finally tested it for myself since i wrote this quickly while leaving work :P)
Allan