0
votes

I have a main movie clip that loads the appropriate swfs based on the button click. The buttons and the corresponding swfs are loaded through XML. The method I adapted to achieve this can be found here : Sample Code

Now, this seems to be working just fine. But, my problem is instead, of calling a separate SWF for each button click, I want to maintain a common SWF and change only the appropriate XML content, sort of make it more dynamic.

This is where I'm stuck, I decided to add an ID to each button on the xml and pass it to the Common SWF (child swf), so that based on the ID, I can load the corresponding XML content, rather than call separate swfs for each button click. The XML now looks like this:

<?xml version="1.0" encoding="utf-8"?>
<menu>
  <item>
     <label>Gallery1</label>
     <url><![CDATA[swf/gallery.swf]]></url>
     <id>01</id>
  </item>
  <item>
     <label>Gallery2</label>
     <url><![CDATA[swf/gallery.swf]]></url>
     <id>02</id>
  </item>
</menu>

Now, I'm able to push this ID and also have it traced on the main movie clip, but don't know how to pass it to the Common/Child SWF. I'm no expert in AS3 and I'm learning it everyday. So, if someone can help me with this, I would really appreciate it. Thanks in advance.

1

1 Answers

1
votes

SWF-Button must implements function that is setter of id property. This method can have reference to Loader-SWF method taht reads Clicks.

sample:

//LOADER-SWF

// loader code:
Loader.load(urlReference);

// ... //

//in load/add to stage event
var child:IChild = Loader.content;
child.setID(1, clickFunction);

//IChild.as
//Interface
public interface IChild {
   function method setID(id:uint, callBack:Function):void;
}


//BUTTON.swf
//implement IChild

private var _id:uint;
private var _callBack:Function;

// ... //

public function method setID(id:uint, callBack:Function):void{
   _id=id;
   _callBack=callBack;
}

// ... //

private function onClick(e:MouseEvent):void{
   _callBack(_id);
}