Copy link to clipboard
Copied
I have this code. Each buttons returns a number that I want to pass as a parameter to the other SWF. How can I achieve this? I never used parameters yet and I'm searching a lot in the forums without success.
Thank you.
import flash.events.Event;
import flash.net.URLRequest;
import fl.display.ProLoader;
var loadClip: ProLoader = new ProLoader();
addChild(loadClip);
F1.addEventListener(MouseEvent.CLICK,btnpressed);
F2.addEventListener(MouseEvent.CLICK,btnpressed);
F3.addEventListener(MouseEvent.CLICK,btnpressed);
function btnpressed(e:MouseEvent):void{
e.target.removeEventListener(MouseEvent.CLICK,btnpressed);
e.target.enabled = false;
e.target.visible = false;
var btnName:String = e.target.name;
var input:String = btnName;
var pattern:RegExp = /F/;
var output:String = input.replace(pattern, "");
trace(output);
loadClip.load(new URLRequest("cadeaux.swf"));
}
So what should I do to access parent's variables from the loaded child? Currently it returns "null". I want to access "output" variable. Thanks.
Child:
var btnPressed:String = MovieClip(this.parent.parent).output; trace(btnPressed);
Copy link to clipboard
Copied
you don't need to pass anything. cadeaux's main timeline's parent.parent is the timeline that's the parent of loadClip.
cast that parent.parent as a movieclip and you can directly reference objects from cadeaux.
Copy link to clipboard
Copied
I didn't think about this. So I just need to input MovieClip(this.parent.parent); to accès the variables in the parent movie from the child. I did this in another project a long time ago, I forgot about this while doing other programming languages.
Copy link to clipboard
Copied
MovieCLip(this.parent.parent) from the loaded swf's main timeline would reference the parent of your proloader.
Copy link to clipboard
Copied
So what should I do to access parent's variables from the loaded child? Currently it returns "null". I want to access "output" variable. Thanks.
Child:
var btnPressed:String = MovieClip(this.parent.parent).output; trace(btnPressed);
Copy link to clipboard
Copied
you made output local to a function so it’s not available outside that function.
Copy link to clipboard
Copied
Thank you, you are right. It now works. Thanks a lot.
Copy link to clipboard
Copied
you’re welcome.