Skip to main content
Petteri_Paananen
Inspiring
August 19, 2009
Répondu

passing commands from child to child

I have a main movie (main.swf). I load child1.swf and child2.swf into it with URLLoader. Is there any way to make a button to child1.swf which would take a user to some frame in timeline of child2.swf?

Something like

parent.child2.goToFrame(5);

I have tried different combinations without luck...

Ce sujet a été fermé aux réponses.
Meilleure réponse par Ned Murphy

I tried it this way:

Child1.swf:

var SN = 3;
btn1.addEventListener(MouseEvent.CLICK, nextPage5);

function nextPage5(e){
    MovieClip(parent.parent).nextPageAlt();
}

Main.swf:

function nextPageAlt():void{
    var mc = MovieClip(loader.content);
    mc.goToFrame(SN);
}

But it didn´t work... I got following warning:

ReferenceError: Error #1065: Variable SN is not defined.
    at sourceCS3_fla::MainTimeline/nextPageAlt()
    at UI_fla::MainTimeline/nextPage5()


I thought by your earlier reply you meant you were taking the OOPC route (I've no bias either way).  That's why I suggested reaching into the child.  But if you're going the parent route, then you should be able to just pass the variable in the function call.

Child1.swf:

var SN = 3;
btn1.addEventListener(MouseEvent.CLICK, nextPage5);

function nextPage5(e){
    MovieClip(parent.parent).nextPageAlt(SN);
}

Main.swf:

function nextPageAlt(SN):void{
    var mc = MovieClip(loader.content);
    mc.goToFrame(SN);
}

To go the reaching in route you would need to target the loader.content of the child and get the SN variable that way.

1 commentaire

Ned Murphy
Legend
August 19, 2009

Here's a link to a post that will provide a couple options for your consideration.  One approach would be the way you were trying to do it, just with the correction needed to make it happen.  The other way would be the more OOPolitcally correct way to approach it.

http://forums.adobe.com/thread/470135?tstart=120

Petteri_Paananen
Inspiring
August 19, 2009

Thanks Ned..

I got the basic idea, now my button in Child1.swf triggers a function in main.swf.... Now I´m wondering how I could define a variable in Child1.swf and pass it to main.swf...

Ned Murphy
Legend
August 19, 2009

You can just have Child1 set the variable value and then have the main movie reach into the child to get it when it executes the function you added.