Hello Guys!
I´m having a problem here: I did two classes and one of this “swf” is loaded into another throught a movieClipLoader class.
I did a very simple example of my doubt:
Class internal swf:
class Interno extends MovieClip {
private var bt:MovieClip;
private var env:MovieClip
function Interno(e:MovieClip) {
super();
this.env = e;
trace("construtor interno iniciado");
}
public function sayHello():Void {
trace("hello!!");
}
}
And the root swf:
import mx.utils.Delegate;
import utils.LoadPP;
class Principal extends MovieClip {
private var timeline:MovieClip;
private var bt:MovieClip;
private var load:LoadPP;
private var listener:Object;
private var alvo:MovieClip;
function Principal(e:MovieClip) {
super();
this.listener = new Object();
this.timeline = e;
this.bt = e.bt_mc;
this.alvo = new MovieClip();
this.alvo = this.timeline.load_mc;
this.load = new LoadPP();
this.listener.onLoadComplete = Delegate.create(this, leu);
this.load.carregue("interno.swf", this.alvo);
this.bt.onRelease = Delegate.create(this, btRelease);
}
public function leu(oque:String):Void {
trace("oque: " + oque);
acessarMetodo();
}
public function acessarMetodo():Void {
this.alvo.sayHello();
}
public function btRelease():Void {
trace("bt clicado");
this.alvo.sayHello();
}
}
The loader class is so simple, but, anyway:
import mx.utils.Delegate;
class utils.LoadPP extends MovieClipLoader {
private var broadcaster:Object;
private var listener:Object;
private var oqueCarregar:String;
private var ondeCarregar:MovieClip;
function LoadPP(o:Object) {
super();
initListMethods();
//
this.listener = new Object();
this.broadcaster = new Object();
AsBroadcaster.initialize(this.broadcaster);
this.broadcaster.addListener(o);
}
public function carregue(oque:String, onde:MovieClip):Void {
this.oqueCarregar = oque;
this.ondeCarregar = onde;
this.loadClip(oque, onde);
}
private function initListMethods():Void {
this.addListener(this.listener);
//
this.listener.onLoadStart = Delegate.create(this, onLoadStart);
this.listener.onLoadProgress = Delegate.create(this, onLoadProgress);
this.listener.onLoadComplete = Delegate.create(this, onLoadComplete);
}
// Delegates:
private function onLoadStart(target_mc:MovieClip):Void {
trace("onLoadStart: " + target_mc);
};
private function onLoadProgress(target_mc:MovieClip, numBytesLoaded:Number, numBytesTotal:Number):Void {
var numPercentLoaded:Number = numBytesLoaded / numBytesTotal * 100;
trace("onLoadProgress: " + target_mc + " is " + numPercentLoaded + "% loaded");
};
private function onLoadComplete(target_mc:MovieClip, status:Number):Void {
this.broadcaster.broadcastMessage("onLoadComplete", this.oqueCarregar);
};
public function getOqueCarreguei() {
return this.oqueCarregar;
}
}
So. The problem is:
When I load the external swf, how can I access its methods ? Because, if I put it into a mc like the “this.alvo” attribute (wich is “_root.load_mc”), and I try:
// at the "root" swf:
this.alvo.sayHello();
It does not work !! It does not access the methods !!!
rsss.
Files and classes above in zip files:
http://www.ppwebart.com/kirupa/teste.zip
Any suggestions ?
Cheers!
Pedro Paulo