views:

138

answers:

1

Hello Friends,

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  A: 

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);
}
Konrad
Hello Konrad,Thanks, for your reply. I can kind of understand what you have written for the Button.swf ( Main Movie Clip).But, can you explain a bit more on whats going on in Loader.swf ? Is the clickFunction in Loader.swf refering to onClick function in button.swf? Also, how do I implement interface for timeline scripting cos I'm not using package classes for the loading swf. Thanks, again for the help.
Vic