onLoadInit class woes
Ive been wrestling with an actionscript 2 problem for a while now, how to load a movie from within a class and pass data from the class to the movie. All of my attempts failed miserably and it was one of those nagging problems that you just know has a simple answer. Here's what I found.
Heres my code:
this works well. But over the past couple of days it dawned on me that you dont need to create a new listener Object (slaps forhead). You just use the class instance as the listener like this:
So problem solved? Not quite. What we need to do now is make the onLoadInit event a method within the class so the complete code is now:
Heres my code:
public function FormBlock(formXML:XMLNode, target:MovieClip) {You can see that im looking to trace out the data from within the loaded movie. Unfortunately this doesnt work. What you need to do is very simple, although I scratched my head for a while. What you need to do is send the data to the Listener object before the onLoadInit:
formOBJ = this;
// create empty movie clip to load the swf into
container_mc = target.createEmptyMovieClip("formBlock"+ID, DEPTH);
container_mc.formOBJ = formOBJ;
var mclListener:Object = new Object();
//the onLoadInit event just traces out the XML we want to send to the loaded movie
mclListener.onLoadInit = function(target_mc:MovieClip) {
trace("movie loaded");
trace("formXML "+target_mc.formXML);
trace("formXML "+target_mc._parent.formXML);
};
var image_mcl:MovieClipLoader = new MovieClipLoader();
image_mcl.addListener(mclListener);
image_mcl.loadClip("forms/"+TYPE+".swf", container_mc);
}
mclListener.formOBJ = formOBJ;
var mclListener:Object = new Object();
mclListener.onLoadInit = function(target_mc:MovieClip) {
target_mc.formOBJ = this.formOBJ
};
this works well. But over the past couple of days it dawned on me that you dont need to create a new listener Object (slaps forhead). You just use the class instance as the listener like this:
var image_mcl:MovieClipLoader = new MovieClipLoader();
image_mcl.addListener(this);
image_mcl.loadClip("forms/"+TYPE+".swf", container_mc);
So problem solved? Not quite. What we need to do now is make the onLoadInit event a method within the class so the complete code is now:
public function FormBlock(formXML:XMLNode, target_mc:MovieClip) {
formOBJ = this;
container_mc = target_mc.createEmptyMovieClip("formBlock"+ID, DEPTH);
var image_mcl:MovieClipLoader = new MovieClipLoader();
image_mcl.addListener(this);
image_mcl.loadClip("forms/"+TYPE+".swf", container_mc);
}
public function onLoadInit(this_mc:MovieClip) {
this_mc.formOBJ = this.formOBJ;
this_mc.TYPE = this.TYPE;
trace("movie loaded");
trace("formOBJ "+this_mc.formOBJ);
}
