Flash / ActionScript 3: reference loader Document Class from loaded Document Class
I have a FLA (say Main.FLA) document class with a child MovieClip on the stage: into the child MovieClip I want to load other swf files: each of the files contains its own Document Class (every swf is a somewhat independet application, say quizzes and so on). For开发者_运维问答 some reason I must use the MAIN document class to store data from the child swfs loaded into the main FLA. HOW do I reference the Main class? I can't find a way...
When I did something similar I used events. I created a class:
package {
import flash.events.Event;
public class QuestionAnsweredEvent extends Event {
public static const QUESTION_ANSWERED:String = "QuestionAnswered";
public var data:*;
public function QuestionAnsweredEvent(type:String, data:*) {
this.data = data;
super(type, true);
}
}
}
Then In the child SWF I dispatch this event:
dispatchEvent(new QuestionAnsweredEvent(QuestionAnsweredEvent.QUESTION_ANSWERED, questionData));
In the Parent SWF I add a standard event listener but inside the function I'm able to grab the event.data property to store the sent data.
Hope that helps. I'm relatively new to this myself but it worked well in my project.
EDIT: In your main class:
swfmovieclip.addEventListener(QuestionAnsweredEvent.QUESTION_ANSWERED,onAnswer);
private function onAnswer(e:QuestionAnsweredEvent):void {
storingVar = e.data; //this can change depending on the type of object you send
}
EDIT2: This is how I load my SWF that dispatches the event containing data:
var ldr:Loader = new Loader();
ldr.load(new URLRequest("RegionalQuestions.swf"));
ldr.addEventListener(QuestionAnsweredEvent.QUESTION_ANSWERED, questionAnswered);
questionsSWF = ldr;
addChild(ldr);
精彩评论