A Flash Developer Resource Site

Results 1 to 20 of 20

Thread: nested child calling root parent function help me!

  1. #1
    Senior Member
    Join Date
    Jan 2001
    Posts
    190

    Question nested child calling root parent function help me!

    sup playaz! So i've been reading and searching for 2 days on this and so I've finally decided to ask for help. I'm switching from as2 to as3 and everything was going swimmingly with my new site until i tried to use a _root call to a function on the main timeline by a loaded movieClip that is loaded nested into 2 other movieclips. the movieClip needs to tell the _root when it's done playing so the root knows to load the next one in line through a php call. Everything works except for the _root call. In as3 there's no such thing as root anymore so I figured no big deal, i'll just find out what the new thing is and holy crap wtf! I can't figure this out!! I've read from doing stuff like custom eventLisnters (which i am trying now) and casting the root as a movieClip and then I read this whole crazy tutorial on building an event structure and the proper MVC way of coding and blah blah blah ALL I WANT TO DO is tell the _root that the loaded MC has reached the end of its timeline. Basically if it were as2 i could just go _root.loadNext(); and it would work. Does anybody have any clue how to make a loaded MC talk to the _root timeline and call a funciton from there?

    I'll keep trying and if i figure it out I'll post what i come up with here. Thanks

  2. #2
    Senior Member
    Join Date
    Jan 2001
    Posts
    190

    test files below!

    I made some test flas so we can all figure this out. I have a parent fla that loads the nested movieClip that tries to call back a function on the parent when it's done playing. Make it work and get a star!

    http://www.threebrain.com/bs/files/childParentHelp.zip

    let's do this!

  3. #3
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    In as3 there's no such thing as root anymore.
    Not true. Root is still there, just called "root" instead of "_root", and it's handled a little more type-strictly. But swfs in as3 always act like the old lockroot was set to true, so the loaded swf's root will be itself, and not the main timeline. You could use a parent.parent... chain, but that's ugly as sin.

    Instead, use the event model to bubble an event from the loaded swf up the displaylist until it hits something that cares about the event.

    In last frame of loaded swf:
    Code:
    dispatchEvent(new Event("allDone", true));
    In main timeline:
    Code:
    addEventListener("allDone", loadNext);
    
    function loadNext(event:Event = null):void{
     //... whatever you do in loadNext.
    }
    "allDone" is the event type here, and it's arbitrary. All you need to make sure of is that both the loading and loaded are using the same value.

  4. #4
    Senior Member
    Join Date
    Jan 2001
    Posts
    190
    holy crap! i'll go try it now! thanks! :-O

  5. #5
    Senior Member
    Join Date
    Jan 2001
    Posts
    190
    it aint work. :'(

    http://threebrain.com/bs/files/testChildrenParent.html

    here's the code i tried.

    main timeline
    Code:
    import fl.transitions.Tween;
    import fl.transitions.easing.*;
    import fl.transitions.TweenEvent;
    import flash.net.URLVariables;
    import flash.net.URLRequest;
    import flash.net.URLLoader;
    import flash.net.URLRequestMethod;
    import flash.events.*;
    import flash.display.Loader;
    
    textTest.text="I have no child to talk to in me";
    
    var loadit = new Loader();
    mc_inner1.mc_inner2.addChild(loadit);
    loadit.load(new URLRequest("testLoader.swf"));
    
    addEventListener("allDone", loadNext);
    
    function loadNext(event:Event = null):void {
    	textTest.text="my inner child talked to me!!";
    }
    and in the loaded child
    Code:
    dispatchEvent(new Event("allDone", true));
    
    stop();
    what i do wrong? I'll keep looking at it. man i was so excited hahaha :'(

  6. #6
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Did you get any errors? Is mc_inner1 on the display?

    Add the listener before telling loadit to load. The event may be dispatching before the listener is added.

  7. #7
    Senior Member
    Join Date
    Jan 2001
    Posts
    190
    I put it above the loadit and still aint work. I donno if mc_inner1 is "on the display" cause I don't know what that means :-[ Does it mean that theirs a display array that lists all the stuff in it? Below is a link to the 2 files where i attempted your event dispatch

    http://threebrain.com/bs/files/childParentHelp2.zip

    I'll keep messing with it but i'm stuck and feel like this

  8. #8
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Unfortunately, I only have CS3 (and I hate to use that), so I cannot open your fla files. However, I did create a simple flashdevelop project which shows the principle.

    In the attached zip, you will find Alice.as and Bob.as. Alice loads Bob and listens for an event. Bob dispatches that event. Both of them report their own and their root's ids.

    Here's the output I get:
    Code:
    alice says id=alice
    alice says root.id=alice
    bob says id=bob
    bob says root.id=bob
    alice got an alldone from bob
    Attached Files Attached Files

  9. #9
    Senior Member
    Join Date
    Jan 2001
    Posts
    190

    cs3 files

    oh snap. I saved the files down to CS3 for ya. I'll take a look at your as you just put up now.

    http://www.threebrain.com/bs/files/CS3.zip

    thanks! looking...

  10. #10
    Senior Member
    Join Date
    Jan 2001
    Posts
    190
    hahaha looking at your files and sheesh! what is all this stuff. What is roottest.as3proj ? did you do this in flex or some such? I'll keep looking at it....

  11. #11
    Senior Member
    Join Date
    Jan 2001
    Posts
    190
    oh wow! i see how you put my loadit and stuff in there! gonna work at it. My stuff isn't in a package though. perhaps that's what is screwing it up :-\ thanks i'll work on this more...

  12. #12
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    as3proj is how flashdevelop saves projects. That's not important. Just look at Alice.as and Bob.as.

    roottest.swf in the bin folder is the main loader swf. Bob.swf is from Bob.

    Alice loads Bob with a Loader, and you get the output I showed above. You should be able to look at the code in the two .as files and apply it to your own project. I will attempt to open your updated cs3 version and see what I can do, but I'm currently busy with paid work so it might be a while.

  13. #13
    Senior Member
    Join Date
    Jan 2001
    Posts
    190

    paid work lol

    hahahaha thanks sorry to slow down your paid work lol. I am doin what you said! am close maybe. no rush. thanks again. I'm beginning to have breakthroughs that i can use for so much stuff so this is mad exciting if i get it workin i'll post it back here yaaay

  14. #14
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Your problem was that your inner movie (testLoader) was published for AS2. Changing it to as3 fixed the issue.

  15. #15
    Senior Member
    Join Date
    Jan 2001
    Posts
    190
    hahahahahahaha what??? 2 days bro! hahaha 2 frign days! oh you mean with the new stuff you told me today. going...

  16. #16
    Senior Member
    Join Date
    Jan 2001
    Posts
    190
    hahahahaha hahahaha holy crap it worked!!! yeeeeessss!!!! YOU HAVE EARNED A STAR!!

    man this is so awesome!!!! wow now i can put my new site up soon! i heart you forever!

    PS. wow that's a cool way to do stuff now! better than _root by far. just make events and then give them a shout out yaaaaay!

    thanks so much yaaaay. Nameste

  17. #17
    Senior Member
    Join Date
    Jan 2001
    Posts
    190

    hahahahah yaaaaay!!!!!

    oh man! i got it working with the php now!!! you rock so hard. so now it loads the cartoon from yesterday -- or will haha once i make them starting tonight!! yes!! take a look at your glorious event thing in action!

    Ignore the shart art right now it's still just a sketch! hahahaha click the button with this guy on it :-P for a surprise! I should have all the dudes animated and stuff by like tomorrow night or something. You rock for helping me!

    http://www.threebrain.com/2010/3brain2010.html


  18. #18
    Senior Member
    Join Date
    Jan 2001
    Posts
    190

    Bob and Alice LOL!!!

    hahahaha hey! i was just watching this show called "Through the Wormhole" with Morgan Freeman and there was this scientist trying to send messages back in time with lasers and hahahaha the one sending was Alice and the one recieving was Bob!! WTF is that why you named your .as files Bob and Alice???? haha it can't be a mere coincidence! did you send me this flash help from the future???

  19. #19
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    In cryptography and other fields, Alice and Bob are placeholder names. Usually the scenario involves passing messages. In cryptography, there is often a third person, Carol, who is trying to intercept a message from Alice to Bob.

    http://en.wikipedia.org/wiki/Alice_and_Bob

  20. #20
    Senior Member
    Join Date
    Jan 2001
    Posts
    190
    LOL so i reckon I'm Zoe then

Tags for this Thread

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