A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: Birth control?

  1. #1
    Senior Member
    Join Date
    Oct 2005
    Posts
    198

    Birth control?

    Hi,

    I have a site in progress, but am running into a problem with the transition that plays while external images/swfs are loaded. Before, I inserted the conditional statement, if(transLoad==0),multiple mouse clicks would result in endless children being added---Let me try to explain, I have a series of buttons which load external swfs upon Click events..ex
    Code:
    link1.addEventListener(MouseEvent.CLICK, clickOne,false,0, true);
    the function clickOne would call the transition function below:
    Code:
    function addtrans() {
    			if (transLoad==0) {
    				transLoad=1;
    				var transmc:Sprite=new TVNoisebk  ;
    				transmc.alpha=.8;
    				transmc.x=-20;
    				transmc.y=250;
    				transmc.scaleY=0;
    				transition.addChild(transmc);
    				TweenMax.to(hal, 1,{alpha:1});
    				TweenMax.to(transmc, 1, {x:-20,y:-100,scaleX:1, scaleY:1,ease:Quart.easeIn});
    				myChannel=mySound.play();
    			} else {
    				removetrans();
    			}
    
    
    		}
    Theres a listener which keeps track of the amount loaded:

    Code:
    swfHolder.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, progressHandler, false, 0, true);
    and a listener which is called upon load complete which calls the function to remove the transition:
    Code:
    		function removetrans() {
    
    			TweenMax.to(hal, 1,{alpha:0});
    
    			myChannel.stop();
    			trace("swf loaded");
    			transTxt.text="";
    			while (transition.numChildren) {
    				transition.removeChildAt(0);
    			}
    			transLoad=0;
    
    		}
    My problem is that any given button can be pressed multiple times while the external swf is loading and that's why I stuck in the transLoad variable and made the addtrans function conditional..Ideally, Id like to stop the buttons from reloading the external content if it is already in the process of loading that content--Is there a way to check for this? I have the listener in place:
    Code:
    swfHolder.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, progressHandler, false, 0, true);
    How would I prevent the buttons from calling the external swfs while the load event is in progress? I realize that I could set the transLoad variable within the progressHandler function, but actually that produces worse results...Is there a better way?

    Thanks,
    ---Yvette
    Last edited by yvillicana; 08-12-2009 at 01:06 PM.

  2. #2
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Use Booleans for true/false flags rather than 0/1, that's what they're for.

    You could keep track of the url for the currently loading or last loaded content, and simply not initiate a load if it would be redundant.

  3. #3
    Senior Member
    Join Date
    Oct 2005
    Posts
    198

    Thumbs down

    Thanks 5TonsofFlax,
    still a little confused--I changed it to a Boolean--Its still kind of buggy so I tried to implement your latter suggestion but cant get the syntax correct.

    I added this code to the loader:
    Code:
    var swfHolder = new Loader();
    		function loadSwf(target:String) {
    			
    			if(lastLoaded!=target){
    			mainImage.addChild(swfHolder);
    			swfHolder.load(new URLRequest(target));
    			}
    but cant figure out how to define the lastLoaded--I tried inserting the code at the COMPLETE event listener for the swfHolder but cant figure out how to reference the clip
    Code:
    function onswfLoad(evt:Event):void {
    			lastLoaded=?????
    			swfHolder.contentLoaderInfo.removeEventListener(ProgressEvent.PROGRESS, progressHandler);
    			swfHolder.contentLoaderInfo.removeEventListener(Event.OPEN, onswfOpen);
    			swfHolder.content.addEventListener("labelChange", changeLabel, false, 0, true);
    			swfHolder.content.addEventListener("transKill", killTrans, false, 0, true);
    			removetrans();

  4. #4
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    I would initialize lastLoaded to null in the setup code, and set lastLoaded to target right after kicking off the swfHolder load. That way it will prevent multiple loads of the same content even before it's finished loading.

    If you have error handlers on swfHolder for security, io, or other errors, set lastLoaded back to null there so that you can try again.

  5. #5
    Senior Member
    Join Date
    Oct 2005
    Posts
    198
    Thanks much--Seems much better now!

    --Yvette

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