Skip to main content
Inspiring
November 26, 2018
Answered

Passing parameter to a loaded external .SWF

  • November 26, 2018
  • 1 reply
  • 451 views

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"));

}

This topic has been closed for replies.
Correct answer KoRnBoy82

MovieCLip(this.parent.parent) from the loaded swf's main timeline would reference the parent of your proloader.


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);

1 reply

kglad
Community Expert
Community Expert
November 26, 2018

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.

KoRnBoy82Author
Inspiring
November 27, 2018

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.

kglad
Community Expert
Community Expert
November 27, 2018

MovieCLip(this.parent.parent) from the loaded swf's main timeline would reference the parent of your proloader.