A Flash Developer Resource Site

Page 2 of 5 FirstFirst 12345 LastLast
Results 21 to 40 of 88

Thread: Trace(childName)

  1. #21
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    The hacky way to get around the error would be to simply test that the child is contained before trying to remove it.

    Code:
    if (contains(child)){
      removeChild(child);
    }

  2. #22
    Member
    Join Date
    Sep 2009
    Posts
    72
    I tried that right here... That's basically what I have.. But i added the contains when you click the navigation button.

    Here is the code:

    Code:
    
    function workExistss():void {
    	if (work_mc!=null && contains(work_mc)) {
    		if (work_mc.stage!=null) {
    			trace("YES work exists");
    			removeChild(work_mc);
    		} else {
    			trace("NO work does not exist");
    		}
    	}
    }

  3. #23
    Member
    Join Date
    Sep 2009
    Posts
    72
    ah. alright. fixed it.. One more question for ya if you don't mind..

    O In my work section i have a subnav which goes to motion, print, web, and all. I believe this is a scope issue but I just want to see what you think.

    Once you load, let's say motion, that will goto the root frame label "motion".

    Following that you will click a link there which will take you to a certain frame label in motionss_mc. Inside of motionss_mc I am dispatching an event to the root timeline to close motionss and open back up motion_mc if you so choose
    Code:
    motion_mc.twentythreemographthmb_mc.addEventListener(MouseEvent.CLICK, motionHandler8);
    motion_mc.twentythreemographthmb_mc.buttonMode = true;
    
    function motionHandler8(event:MouseEvent):void {
        if (!motionss_mc) {
            motionss_mc = new mc_motionss();
            motionss_mc.addEventListener("closemotionButtonClick2", backmotionssClicked2);
            motionss_mc.x = 225;
            motionss_mc.y = 200;
        }
    motionss_mc.gotoAndStop("twentythree")
        addChild(motionss_mc);
        removeChild(motion_mc);
    }
    
    function backmotionssClicked2(e:Event):void {
        trace("clickedtrue");
        if (!motion_mc) {
            motion_mc = new mc_motion();
            motion_mc.x = 225;
            motion_mc.y = 200;
        }
        addChild(motion_mc);
        removeChild(motionss_mc);
    }
    That would be the backmotionss_Clicked2 function.

    So in the subnav and continue to a link, close that link with the backmotionss_Clicked2 function then navigate to another section of the subnav...When I do this in that order, motion_mc stays at that section that is currently loaded..

    So I am trying to clear it with this:
    Code:
    var motion_mc = motion_mc
    
    workcatagorydropdown_mc.catagoryinteractive_mc.addEventListener(MouseEvent.CLICK, interactiveHandler);
    
    function interactiveHandler(event:MouseEvent):void {
    
    	newRoot.gotoAndStop("web");
    	stage.invalidate();
    	stage.addEventListener(Event.RENDER, renderedI);
    
    }
    function renderedI(e:Event) {
    
    	motion_mcExistsI();
    	stage.removeEventListener(Event.RENDER,renderedI);
    
    }
    
    function motion_mcExistsI():void {
    	if (motion_mc!=null) {
    		if (motion_mc.stage!=null) {
    			trace("motion does exist");
    			removeChild(motion_mc);
    		} else {
    			trace("no motion does not exist");
    		}
    	}
    }

    Please note that the following code is inside of the subnav which is located a few pages deep. Notice the usage of root.

  4. #24
    Member
    Join Date
    Sep 2009
    Posts
    72
    bump

  5. #25
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    I'm sorry, I didn't follow that. I'm having a very hard time understanding the structure of your movie since there seem to be a lot of layers and similarly named objects. Could you perhaps draw a diagram of your intended design?

    I did notice that you are adding listeners to content in motion_mc before it necessarily exists. That would throw errors if it does not exist. And if motion_mc when those handlers is added is a different instance than later, those handlers won't be triggered because they're not on the new dispatching instance.

    Code:
    var motion_mc = motion_mc;
    Does nothing. Inside a function, it would establish a new function-scoped variable by that name so that if you assigned something to that variable later in the function it would not affect the value of motion_mc outside that function. I'm not sure if that's what you were going for.

    I don't see any code following "the following code", and if you meant the preceding code, it does not use root, so I don't know what you wanted me to notice regarding the usage of root.

  6. #26
    Member
    Join Date
    Sep 2009
    Posts
    72
    Yeah, I can. Did you get a chance to look at the swf?

  7. #27
    Member
    Join Date
    Sep 2009
    Posts
    72
    also, I would be willing to let you look at the .fla if you want? By following i meant previous Actually I did set up a variable for newRoot = root, which is not shown.. and

    function interactiveHandler(event:MouseEvent):void {

    newRoot.gotoAndStop("web");

    That is where I am using the root.
    Last edited by aesthetics7; 02-02-2010 at 04:14 PM.

  8. #28
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    I did look at the swf, it is clearly not removing things as you'd hope for, but it's hard to draw conclusions from that. I'm not getting error messages, but I might not have the debug player installed here at work.

    Unfortunately, I cannot open fla files.

    Using newRoot.gotoAndStop like that is fine. It is essentially no different than just using root.gotoAndStop, with the exception that newRoot would retain a reference even after that instance is removed from the displayList. But since that function is a click handler, that should not be an issue.

  9. #29
    Member
    Join Date
    Sep 2009
    Posts
    72
    Alright, I'm working on a diagram to help you understand this.. Yeah, there are no error messages, it's just not removing the movieclip when it should.

  10. #30
    Member
    Join Date
    Sep 2009
    Posts
    72
    okay, Check this out. Let me know if this helps.

    Please note. Motion_mc is on the root timeline
    Attached Files Attached Files

  11. #31
    Member
    Join Date
    Sep 2009
    Posts
    72
    The problem happens after I press the back button then try to load another movieclip from the subnav.

  12. #32
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    All this code is in the root context right?

    I think instead of trying to keep track of what could possibly be showing and trying to remove that specific thing when you put something new up, you should have a variable to keep track of the currently showing modal content and a function to replace it.

    Code:
    var currentlyShowing:MovieClip = null;
    
    function showModalContent(clip:MovieClip):void{
      if (currentlyShowing != null){
        removeChild(currentlyShowing);
      }
      currentlyShowing = clip;
      addChild(currentlyShowing);
    }
    Now instead of calling addChild and removeChild, simply call showModalContent to get something on the display in that mutually exclusive role.

    I'm really not certain what all that stuff is with the rendered events. It looks like all you're trying to do is remove motion_mc if it's on the display. You could make a removeModalContent function to simply clear any modal content that's up there.
    Code:
    function removeModalContent():void{
      if (currentlyShowing != null){
        removeChild(currentlyShowing);
        currentlyShowing = null;
      }
    }
    You should not have to have different methods to remove content for each particular navigational function.

  13. #33
    Member
    Join Date
    Sep 2009
    Posts
    72
    I would put the showModalContent in the button listener?

    Not all of the code is on the root. The only code that is on the root timeline that you are seeing is the motion_mc code.

  14. #34
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Any time you have removeChild(something); addChild(somethingelse);, just use showModalContent(somethingelse);

    If the subnav code is not in the root context, then motion_mc is undefined there. I would expect a compilation error when you declare and initialize the local motion_mc variable. Anyway, since you are changing the root motion_mc to new instances all the time, you don't want to compare it to a particular motion_mc instance anyway. Instead of all that somethingExists crap, just call root.removeModalContent(). That was probably the source of your issue. motion_mc in that context was not the same thing as motion_mc in the root.

  15. #35
    Member
    Join Date
    Sep 2009
    Posts
    72
    You are saying that I should be putting the removeModalContent(); on the root? Sorry, I'm not familiar with showModalContent and RemoveModalContent

  16. #36
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    I just made them up, I don't expect you would be familiar with them.

    Yeah, define the functions showModalContent and removeModalContent on the root (assuming that is where you want your modal content to be added to). Then call those root functions from anywhere.

    The idea behind those functions is that you don't have to keep track of every permutation that the user could have done. You know that there is at most one thing to remove when you are putting up something else. And because you kept track of what that one thing was last time you showed something, you can easily remove it without caring about what it is.

  17. #37
    Member
    Join Date
    Sep 2009
    Posts
    72
    Since the instance of motion_mc is changing all the time, that wouldn't be a problem?

    I should put that inside of motion_mc no?

  18. #38
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Since each time you show motion_mc, you should show it through showModalContent, then no it does not matter that you use different instances. The latest (and currently showing) will always be in the currentlyShowing variable that showModalContent and removeModalContent reference.

  19. #39
    Member
    Join Date
    Sep 2009
    Posts
    72
    Alright, Check it out. Let me know if i'm doing this correctly b/c I'm obviously not...

    Inside of the subnav I have this:

    Code:
    workcatagorydropdown_mc.catagoryinteractive_mc.addEventListener(MouseEvent.CLICK, interactiveHandler);
    
    function interactiveHandler(event:MouseEvent):void {
    newRoot.removeModalContent();
    	newRoot.gotoAndStop("web");
    
    
    
    }
    AND on the root timeline at the motion framelabel I have this:

    Code:
    var currentlyShowing:MovieClip = null;
    
    function showModalContent(clip:MovieClip):void{
      if (currentlyShowing != null){
        removeChild(currentlyShowing);
      }
      currentlyShowing = clip;
      addChild(currentlyShowing);
    }
    
    
    function removeModalContent():void{
      if (currentlyShowing != null){
        removeChild(currentlyShowing);
        currentlyShowing = null;
      }
    }

  20. #40
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Yeah, that's what I meant. What's the problem?

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