dcsimg
A Flash Developer Resource Site

Page 2 of 2 FirstFirst 12
Results 21 to 24 of 24

Thread: Links and thumbnails - how do I target these?

  1. #21
    Junior Member
    Join Date
    Apr 2011
    Posts
    14
    I made a function like this:

    Code:
    function cleanStage():void{
    	if(container_mc != null){
    		while (container_mc.numChildren > 0){
    		  container_mc.removeChildAt(0);
    	}
    		while (container_thumbs.numChildren > 0){
    		  container_thumbs.removeChildAt(0);
    	}
    	}
    }
    And then use it in the function that changes the frame like this:
    Code:
    function goHome (e:MouseEvent):void{
    	cleanStage();
    	gotoAndStop("Home");
    }
    It seems to run without error. This is probably a horrible way to solve these things from a professional point of view, but I can only do what seems the most natural to me since I dont have any real training in flash
    Last edited by IceDiver; 04-26-2011 at 02:39 PM.

  2. #22
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    That's pretty much what I meant, but I was going to use a level of indirection instead of checking within cleanStage whether it applied. Something like this:
    Code:
    var cleanup:Function = cleanLinks;
    
    function goHome (e:MouseEvent):void{
    	cleanUp();
    	gotoAndStop("Home");
    }
    
    function cleanLinks():void{
    	while (container_mc.numChildren > 0){
    	  container_mc.removeChildAt(0);
    	}
    }
    
    function noop():void{}
    
    function cleanSomethingElse():void{
      //whatever you have to do to clean up a different state.
    }
    And you could set cleanup to be whichever cleaning function applies when you enter a frame or state.

  3. #23
    Junior Member
    Join Date
    Apr 2011
    Posts
    14
    Okay, so a function variable is basically a variable that is a function, and you define the function of the variable by assigning different functions to it. So if I wanted to clean after being on the "Gallery" page of my site I could make a function called "cleanGallery" and assign it to the cleanup variable?

    That is really cool functionality! I will have to remember that for later.

  4. #24
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Yes, exactly. Notice I defined a noop (as in no operation) function. This is a little easier to handle than checking for the function variable being null in the case where you don't want to do anything.

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