We help IT Professionals succeed at work.

Loding Unloding movie clips with AS3

brainhax
brainhax asked
on
i am making some calls with ZendAmf , to DB ...
and once i initiate a call , i just load a FAKE loading animation on my screen , and when i receive response i remove it ...

so if i initiate the calls too many times(clicking on the button again and again ) , too many faker loading animations come to screen .

and when the response comes it only Unloads one ... is there a way to remove all of them ?
var ajaxFakerUrl:String='loader.swf';
var urlReqFaker:URLRequest=new URLRequest(ajaxFakerUrl);
var ldrFaker:Loader = new Loader();
ldrFaker.load(urlReqFaker);
MovieClip(root).addChild(ldrFaker);

ldrFaker.x=stage.width/2-30;
ldrFaker.y=250;

Open in new window

Comment
Watch Question

Author

Commented:
i m removing  by ::
MovieClip(root).removeChild(ldrFaker);

Commented:
Here is my suggestion...  Why not disable the button once you press it and reactivate it when you get the response back from the backend???  That way, you'll never make multiple calls which could be taxing to the database if you have big audience...

CyanBlue

Author

Commented:
umm , nice one , but its not exactly a button ,
its a movie clip with a text box inside it ,

how it can be disabled ? coz there is a event listner attached to ON CLICK of MC

Commented:
That still is a button that you can click on, right???  Just use MovieClip.buttonMode = false; to disable it...

CyanBlue

Author

Commented:
oky i wil try that , thanks :)

Author

Commented:
MovieClip.buttonMode = false;
just hides the Handy pointer which comes on the movie clip .

but eventListner is never disabled ..
two ways to handle it.

one
===
whereever u r doing buttonMode = false; you also remove the event listener
and when the response comes back and you do buttonMode=true, also add the eventlistener back there.

two
===
take a global or instance variable depending upon ur scenario
for instance isLoading
make it false by default.

then wrap your code which loads and shows the loading animation inside
if(!isLoading){
  // your code to load and show loader here
 isLoading = true;
}

and as soon as u get he response back make isLoading = false; and remove the loading animation.

this check will make sure that the animation is loaded only once during each load