A Flash Developer Resource Site

Page 1 of 5 12345 LastLast
Results 1 to 20 of 88

Thread: Trace(childName)

  1. #1
    Member
    Join Date
    Sep 2009
    Posts
    72

    Trace(childName)

    I have an issue that i'm running into here.. I have a set of code that is tracing that a movieclip exists on the screen, however it has not been loaded yet? What can cause this?

  2. #2
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    You're going to have to be a lot more specific and post some code if you want answers that are more than wild guesses.

    Here's a wild guess: You're tracing a variable and getting something like [object MovieClip]. That movieclip object exists, but isn't on the displayList. Trace doesn't care whether something is on the displayList.

  3. #3
    Member
    Join Date
    Sep 2009
    Posts
    72
    How can I tell is something is on the displayList?

    Okay,

    This is the issue, I have movieclips on the timeline. In certain areas such as subnavs they are added with addChild and taken off with removeChild.. When I click "work" it will load correctly, but when I click personal then work it states that work already exists.



    Here is a section

    Work button code:
    Code:
    var unimetal_homeref_mc:MovieClip;
    nav_mc.workbtn_mc.addEventListener(MouseEvent.CLICK, buttonClick1);
    function buttonClick1(event:MouseEvent):void {
    	gotoAndStop("work");
    
    	stage.invalidate();
    	stage.addEventListener(Event.RENDER,renderedF);
    
    	
    }
    function renderedF(e:Event) {
    	unimetal_homeref_mcExists();
    	motionss_mcExists();
    	home_mcExists();
    	//work_mcExists();
    	workss_mcExists();
    	motion_mcExists();
    	workpersonalssExists();
    	workpersonalExists();
    	printss_mcExists();
    }
    
    
    
    function unimetal_homeref_mcExists():void {
    	if (unimetal_homeref_mc!=null) {
    		if (unimetal_homeref_mc.stage!=null) {
    			trace("YESdudemar unimetalhomeref exists");
    			removeChild(unimetal_homeref_mc);
    		} else {
    			trace("NO home ref does not exist");
    		}
    	}
    }
    
    
    ////////////////////////////////////////
    
    Here is the personal button code:
    
    nav_mc.personalbtn_mc.addEventListener(MouseEvent.CLICK, buttonClick2);
    
    function buttonClick2(event:MouseEvent):void {
    	gotoAndStop("personal");
    	stage.invalidate();
    	stage.addEventListener(Event.RENDER,renderedP);
    }
    
    function renderedP(e:Event) {
    	//removeChild(work_mc)
    	work_mcExistsp();
    	motionss_mcExistsp();
    	workss_mcExistsp();
    	home_mcExistsp();
    	//workpersonalssExistsp();
    	unimetal_homeref_mcExistsp();
    	printss_mcExistsp();
    	motion_mcExistsp();
    	//workpersonalExistsp();
    }
    
    
    function work_mcExistsp():void {
    	if (work_mc!=null) {
    		if (work_mc.stage!=null) {
    			trace("YES work_mc exists");
    			removeChild(work_mc);
    		} else {
    			trace("NO work_mc does not exist");
    		}
    	}
    }
    Last edited by 5TonsOfFlax; 01-26-2010 at 06:30 PM. Reason: wrap code in code tags

  4. #4
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Do you mean that work_mcExistsp is called again when you click the work button? Yes, that would be the case. Since you clicked the personal button first, you added renderedP as a render event listener to the stage. You never removed that listener, so when you then click work, both renderedP and renderedF will be called.

  5. #5
    Member
    Join Date
    Sep 2009
    Posts
    72
    Well, It has a different name and it's commented out right now..So would I remove that listener after the fact of the click, or would I remove it on another button?

  6. #6
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    You can remove the listener as soon as you don't want it to execute again. In this case, that is probably at the end of the listener itself. This little snippet should allow a listener to remove itself.
    Code:
    function someListener(e:Event):void{
      //body of listener goes here
    
      e.currentTarget.removeEventListener(e.type, arguments.callee);
    }

  7. #7
    Member
    Join Date
    Sep 2009
    Posts
    72
    function buttonClick2(event:MouseEvent):void {
    gotoAndStop("personal");
    stage.invalidate();
    stage.addEventListener(Event.RENDER,renderedP);
    }

    function renderedP(e:Event) {

    work_mcExistsp();
    motionss_mcExistsp();
    home_mcExistsp();
    //workpersonalssExistsp();
    unimetal_homeref_mcExistsp();
    printss_mcExistsp();
    motion_mcExistsp();
    stage.removeEventListener(Event.RENDER,renderedP);

    }


    That's what I did and it seemed to work perfect so far. Thanks!

  8. #8
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Or that, yeah.

  9. #9
    Member
    Join Date
    Sep 2009
    Posts
    72
    okay, one weird thing here...Everything works correctly but I found one way to break it muahhaahha. So, if i go from work>personal>work>personal the last personal page won't load..The error is a display child must be a blabhlahlb, but it works those other times? Strange huh? Also, vice versa from personal to work breaks it as well. By breaking it mean the page just won't show up.

  10. #10
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    The "blabhlahlb" is probably "child of the caller", which means that either the object isn't on the displaylist at all at that point, or it is a child of something else. Since you haven't posted the code where you add these things to the displaylist, I can't really help with that.

  11. #11
    Member
    Join Date
    Sep 2009
    Posts
    72
    Yes. That's what it is I'll post up the code for both of those buttons.

    Forgive me, I know it's a chuck of code. I just want to make sure all the bases are covered.

    Code:
    var unimetal_homeref_mc:MovieClip;
    nav_mc.workbtn_mc.addEventListener(MouseEvent.CLICK, buttonClick1);
    
    function buttonClick1(event:MouseEvent):void {
    	gotoAndStop("work");
    	stage.invalidate();
    	stage.addEventListener(Event.RENDER,renderedF);
    }
    
    function renderedF(e:Event) {
    	unimetal_homeref_mcExists();
    	motionss_mcExists();
    	home_mcExists();
    	//work_mcExists();
    	//workss_mcExists();
    	motion_mcExists();
    	workpersonalssExists();
    	workpersonalExists();
    	printss_mcExists();
    	stage.removeEventListener(Event.RENDER,renderedF);
    
    }
    
    function unimetal_homeref_mcExists():void {
    	if (unimetal_homeref_mc!=null) {
    		if (unimetal_homeref_mc.stage!=null) {
    			trace("YESdudemar unimetalhomeref exists");
    			removeChild(unimetal_homeref_mc);
    		} else {
    			trace("NO home ref does not exist");
    		}
    	}
    }
    
    function motionss_mcExists():void {
    	if (motionss_mc!=null) {
    
    		if (motionss_mc.stage!=null) {
    			trace("YESdudemar motion ss does exist");
    			removeChild(motionss_mc);
    		} else {
    			trace("NO motionSS does not exist");
    		}
    	}
    }
    function home_mcExists():void {
    	if (home_mc!=null) {
    
    		if (home_mc.stage!=null) {
    			trace("YESdudemar home exists");
    			removeChild(home_mc);
    		} else {
    			trace("NO HOme does not exist");
    		}
    	}
    }
    
    
    function workss_mcExists():void {
    	if (workss_mc!=null) {
    		if (workss_mc.stage!=null) {
    			trace("YESdudemar workss exists");
    			removeChild(workss_mc);
    		} else {
    			trace("NO workss does not exist");
    		}
    	}
    }
    
    function motion_mcExists():void {
    	if (motion_mc!=null) {
    		if (motion_mc.stage!=null) {
    			trace("YES motion exists");
    			removeChild(motion_mc);
    		} else {
    			trace("NO motion_mc does not exist");
    		}
    	}
    }
    
    
    function workpersonalssExists():void {
    	if (workpersonalss_mc!=null) {
    		if (workpersonalss_mc.stage!=null) {
    			trace("YES workpersonallsss exists");
    			removeChild(workpersonalss_mc);
    		} else {
    			trace("NO work personalss does not exist");
    		}
    	}
    }
    
    function workpersonalExists():void {
    	if (workpersonal_mc!=null) {
    		if (workpersonal_mc.stage!=null) {
    			trace("YES work personal does exist");
    			removeChild(workpersonal_mc);
    		} else {
    			trace("NO work personal does not exist");
    		}
    	}
    }
    
    function printss_mcExists():void {
    	if (printss_mc!=null) {
    		if (printss_mc.stage!=null) {
    			trace("YESdudemar printss does exist");
    			removeChild(printss_mc);
    		} else {
    			trace("NO PRINTss_MC does not exist");
    		}
    	}
    }
    
    //////////////////////////////////
    nav_mc.personalbtn_mc.addEventListener(MouseEvent.CLICK, buttonClick2);
    
    function buttonClick2(event:MouseEvent):void {
    	gotoAndStop("personal");
    	stage.invalidate();
    	stage.addEventListener(Event.RENDER,renderedP);
    }
    
    function renderedP(e:Event) {
    
    	work_mcExistsp();
    	motionss_mcExistsp();
    	workss_mcExistsp();
    	home_mcExistsp();
    	//workpersonalssExistsp();
    	unimetal_homeref_mcExistsp();
    	printss_mcExistsp();
    	motion_mcExistsp();
    	stage.removeEventListener(Event.RENDER,renderedP);
    
    }
    
    function motionss_mcExistsp():void {
    	if (motionss_mc!=null) {
    		if (motionss_mc.stage!=null) {
    			trace("YESdudemar motion ss does exist");
    			removeChild(motionss_mc);
    		} else {
    			trace("NO motion ss does not exist");
    		}
    	}
    }
    function motion_mcExistsp():void {
    	if (motion_mc!=null) {
    		if (motion_mc.stage!=null) {
    			trace("YES motion exists");
    			removeChild(motion_mc);
    		} else {
    			trace("NO motion_mc does not exist");
    		}
    	}
    }
    function printss_mcExistsp():void {
    	if (printss_mc!=null) {
    		if (printss_mc.stage!=null) {
    			trace("YESdudemar printss does exist");
    			removeChild(printss_mc);
    		} else {
    			trace("NO PRINTss_MC does not exist");
    		}
    	}
    }
    function unimetal_homeref_mcExistsp():void {
    	if (unimetal_homeref_mc!=null) {
    		if (unimetal_homeref_mc.stage!=null) {
    			trace("YESdudemar unimetal does exist");
    			removeChild(unimetal_homeref_mc);
    		} else {
    			trace("NO home ref does not exist");
    		}
    	}
    }
    /*
    function workpersonalssExistsp():void {
    if (workpersonalss_mc!=null) {
    if (workpersonalss_mc.stage!=null) {
    trace("YES work personalss does exist");
    removeChild(workpersonalss_mc);
    } else {
    trace("NO work personalss does not exist");
    
    }
    }
    }
    */
    function workss_mcExistsp():void {
    	if (workss_mc!=null) {
    		if (workss_mc.stage!=null) {
    			trace("YES workss does exist");
    			removeChild(workss_mc);
    		} else {
    			trace("NO workss does not exist");
    		}
    	}
    }
    
    function work_mcExistsp():void {
    	if (work_mc!=null) {
    		if (work_mc.stage!=null) {
    			trace("YES work_mc exists");
    			removeChild(work_mc);
    		} else {
    			trace("NO work_mc does not exist");
    		}
    	}
    }
    
    function home_mcExistsp():void {
    	if (home_mc!=null) {
    		if (home_mc.stage!=null) {
    			trace("YESdudemar home-mc does exist");
    			removeChild(home_mc);
    		} else {
    			trace("NO home_mc does not exist");
    		}
    	}
    }
    Here is the sequence:

    Work clicked = no error, page loads
    Personal Clicked = no error, page loads
    Work Clicked = Error, page still loads

    Error:
    ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
    at flash.display:isplayObjectContainer/removeChild()
    at SILVERCOLLECTIVEv13cs4_fla::MainTimeline/workpersonalExists()[SILVERCOLLECTIVEv13cs4_fla.MainTimeline::frame1:35 3]
    at SILVERCOLLECTIVEv13cs4_fla::MainTimeline/renderedF()[SILVERCOLLECTIVEv13cs4_fla.MainTimeline::frame1:27 4]
    Personal Clicked = No error, Page does not load, Traces "YES work personal does exist"

  12. #12
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    That code still doesn't have the addChild calls. I suspect that you are adding it to a different parent at some point, probably the stage.

  13. #13
    Member
    Join Date
    Sep 2009
    Posts
    72
    True, I'll post that up shortly. If i never access that how could it create an error? Would the error be removing the child?

  14. #14
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    That error happens when you try to remove a child from something it is not a child of. That could be because you've already removed it. Or it could be because it was added as a child of something else, which would implicitly remove it. Or it could be because it was never added to that object in the first place.

  15. #15
    Member
    Join Date
    Sep 2009
    Posts
    72
    Alright, I get it.. This is what is happening here. The main pages are based on the timeline, then once you get into say you go to work_mc then you load an image in there I am using an addChild event to trigger workss_mc to be loaded. However in workss_mc there is an option to go back. When you do go back, this removes workss_mc and adds work_mc. So this is my question, how can I pull this off instead of how i currently have it since it's obviously not working correctly.

  16. #16
    Member
    Join Date
    Sep 2009
    Posts
    72
    So if I remove the workpersonalExists from the work button and if I remove work_mcExistsp function it will work correctly navigating but now it won't remove that movieclip once it's loaded from pressing the back button..

  17. #17
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    If I understand correctly (and there's a good chance I don't since this is so convoluted), you want a single thing on the screen at a time.

    If that's the case, then just set a variable to point to the currently showing content. When showing new content, if that variable is non-null, remove the existing content, add the new content, then set the variable to the new content.

  18. #18
    Member
    Join Date
    Sep 2009
    Posts
    72
    Yes, that is correct. A single thing on the screen at a time. If you want to take a look
    go to:

    http://iankemp.com/silver/SILVERCOLLECTIVEv13cs4.swf

    Feel free to give me some feedback too.. So, go into work, then click something and click back and just mess around in there. You'll see. I'll take a shot at what you are trying to say and show you what I come up with.

  19. #19
    Member
    Join Date
    Sep 2009
    Posts
    72
    Alright i've been storming my brain about this and I can't figure it out..

    So this is what has to happen. Work_mc has to be removed when you click personal_btn under only one occurrence. When it is loaded from workss_mc. When it is loaded from workss_mc it is done with addChild.

    So this is the navigation in a whole.

    Button
    Work -> work_mc(selection of work)(on timeline) -> workss_mc (this contains all work) added as a child
    Personal -> personal_mc(selection of work)(on timeline) -> persoanlss_mc (this contains all personal work) added as a child

    So the goal is here, is once you are in personalss_mc or workss_mc you need to be able to go back to personal_mc or work_mc to look at the selection of work here, so by doing this I am using addChild & removeChild. This is where the problem lies, if a user does this then decides to swap pages then the page overlaps work_mc or personal_mc.

  20. #20
    Member
    Join Date
    Sep 2009
    Posts
    72
    Technically, I guess I could get rid of workss_mc and personalss_mc and put them all into work_mc and personal_mc. Then I would run into all sorts of other things as well b/c once you are in workss_mc or personalss_mc there is also a prev and next button which will go to the next frame if the user decides to navigate that way. hmm

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