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

Passing parameter to a loaded external .SWF

Community Beginner ,
Nov 26, 2018 Nov 26, 2018

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

}

TOPICS
ActionScript

Views

299

Translate

Translate

Report

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

Votes

Translate

Translate
Community Expert ,
Nov 26, 2018 Nov 26, 2018

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.

Votes

Translate

Translate

Report

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

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.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

LATEST

you’re welcome.

Votes

Translate

Translate

Report

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