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

AS3: use buttons in external swf

New Here ,
Mar 20, 2013 Mar 20, 2013

Hi,

  

I am making a website in Adobe Flash that imports it´s navigation buttons from an external swf-file.

The problem is how my Main FLA-file will know which of the navigation buttons the users has pressed, since the buttons and it's eventListeners are in the external swf-file.

With other word: can I make my external swf-file return a Number to my website FLA-file, to determine which button that have been pressed? If so, how?

TOPICS
ActionScript
2.5K
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 Expert , Mar 20, 2013 Mar 20, 2013

here are the various was your two swfs can communicate: 

http://kb2.adobe.com/community/publishing/918/cpsid_91887.html

Translate
Community Expert ,
Mar 20, 2013 Mar 20, 2013

here are the various was your two swfs can communicate: 

http://kb2.adobe.com/community/publishing/918/cpsid_91887.html

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
New Here ,
Mar 20, 2013 Mar 20, 2013

Thanks for the link.

I still dont quite understand, could you show be an example?

If I from my FLA-file called Main want to get the variable pageNr from the swf-file Buttons, what should I write?

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 ,
Mar 20, 2013 Mar 20, 2013

are you loading the navigation swf?  if yes, show the loader code.

are the navigation button listener functions on the navigation swf's main timeline?  if no, what timeline are they on relative to the main timeline.

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
New Here ,
Mar 20, 2013 Mar 20, 2013

I made a simple Flash exemple:

Main.fla code:

import flash.display.MovieClip;

import flash.display.Loader;

var mcButtons:MovieClip;

var buttonsLdr:Loader = new Loader();

buttonsLdr.contentLoaderInfo.addEventListener(Event.COMPLETE, buttonsLoaded);

buttonsLdr.load(new URLRequest("Buttons.swf"));

function buttonsLoaded(e:Event):void {

          mcButtons = MovieClip(buttonsLdr.contentLoaderInfo.content);

          buttonsLdr.contentLoaderInfo.removeEventListener(Event.COMPLETE, buttonsLoaded);

          mcButtons.x = 20;

          mcButtons.y = 2;

          addChild(mcButtons);

}

Here are my code for Buttons.fla file:

var page:Number = 0;

b1.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler1);

b2.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler2);

function fl_MouseClickHandler1(event:MouseEvent):void

{

          page = 1;

}

function fl_MouseClickHandler2(event:MouseEvent):void

{

          page = 2;

}

I have only 1 timeline in each FLA files.

EDIT:

I found a YouTube video that explaine LocalConnection function really well, so now I got it to work. (The youtube clipp can be found here: http://www.youtube.com/watch?v=bqxIPYJttjc).
Anyway, thanks all for trying to help me!

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 ,
Mar 20, 2013 Mar 20, 2013
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
Explorer ,
Mar 20, 2013 Mar 20, 2013

I had a similar problem thanks to Ned Murphy, I learned you can dispatch events which can communicate between .swf

(Generally speaking)

Main Movie:

yourObject.addEventListener("myEvent",theEvent);

function theEvent(e:Event):void{

//code here;

}

External .swf:

//attach to whatever needs to fire the event.

dispatchEvent(new Event("myEvent"));

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