Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Passing parameter to a loaded external .SWF

Community Beginner ,
Nov 26, 2018 Nov 26, 2018

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

}

TOPICS
ActionScript
427
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Beginner , Nov 26, 2018 Nov 26, 2018

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

Translate
Community Expert ,
Nov 26, 2018 Nov 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 26, 2018 Nov 26, 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 26, 2018 Nov 26, 2018

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 26, 2018 Nov 26, 2018

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 26, 2018 Nov 26, 2018

you made output local to a function so it’s not available outside that function.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 26, 2018 Nov 26, 2018

Thank you, you are right. It now works. Thanks a lot.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 26, 2018 Nov 26, 2018
LATEST

you’re welcome.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines