SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Sep 2009
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    AddChild/Remove Child Problems??!

    This is the error I am getting..

    This is the situation I am using addChild and removeChild. I have two main movieclips that this is based around. workss_mc and work_mc. workss_mc is the slideshow, work_mc is the selection grid. When you click on an object in work_mc I am adding adding a child (workss_mc) and removing work_mc at the same time. That works fine; however, in workss_mc I have a back button, this back button is used to remove works_mc once it is removed it sends you back to work_mc. Once you are back on work_mc everything should work completely the same, however, it's like it's ignoring the code.

    Does anyone have any idea why?

    Here is the code for the button:
    Code:
    urbanthmb_mc.addEventListener(MouseEvent.CLICK, clickHandler);
    
    function clickHandler(event:Event) {
    	var workss_mc = new mc_workss();
    
    
    myParent.addChild(workss_mc); // we use that stage reference here
    myParent.removeChild(myParent.work_mc); // and here.
    workss_mc.x = 225;
    workss_mc.y = 200;
    workss_mc.gotoAndPlay("urbanflats");
    trace("I heard the event MouseEvent.CLICK");
    }
    Here is the code for the back button
    Code:
    backss_mc.addEventListener(MouseEvent.CLICK, backssClicked);
    function backssClicked(event:MouseEvent) {
    	trace("clicked");
    	var work_mc = new mc_work();
    	myParent.removeChild(this);
    	myParent.addChild(work_mc);
    	work_mc.x=225;
    	work_mc.y=200;
    	this.x=225;
    	this.y=200;
    }
    So everything works fine-it's just once you click the back button.

    myParent.addChild(work_mc);

    It gets added to the stage again. Once it's added then everything in work_mc is thrown off..

  2. #2
    SitePoint Member
    Join Date
    Sep 2009
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    any suggestions?

  3. #3
    SitePoint Wizard jim_morrison3's Avatar
    Join Date
    Apr 2004
    Location
    UK
    Posts
    2,324
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try to run a trace on "this" in your code, as the reference might be wrong, coz in AS3 "this" returns the reference of the class instead of the object on which the action is performed.
    Good Luck!
    There are things known and Things unknown
    And in between are the Doors.
    I love hand Coding.

  4. #4
    SitePoint Member
    Join Date
    Sep 2009
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by jim_morrison3 View Post
    Try to run a trace on "this" in your code, as the reference might be wrong, coz in AS3 "this" returns the reference of the class instead of the object on which the action is performed.
    When I run a trace(this) it returns [object mc_works]

    This removeChild method runs fine, it's just whenever I am adding the child MC_work again that's where the problem comes into play.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •