将 ID 从主 swf 传递到子 swf

发布于 2024-08-07 19:30:40 字数 941 浏览 0 评论 0原文

我有一个主影片剪辑,它根据按钮单击加载适当的 swf。按钮和相应的 swf 通过 XML 加载。我为实现此目的而采用的方法可以在这里找到: 示例代码

现在,这似乎工作得很好。但是,我的问题是,我不想为每次按钮单击调用单独的 SWF,而是想维护一个通用的 SWF 并仅更改适当的 XML 内容,使其更加动态。

这就是我被卡住的地方,我决定为xml上的每个按钮添加一个ID,并将其传递给Common SWF(子swf),这样根据ID,我可以加载相应的XML内容,而不是调用每次单击按钮都有单独的 swf。 XML 现在如下所示:

<?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>

现在,我可以推送此 ID 并在主影片剪辑上跟踪它,但不知道如何将其传递给 Common/Child SWF。我不是 AS3 专家,但我每天都在学习它。因此,如果有人可以帮助我解决这个问题,我将非常感激。提前致谢。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

请叫√我孤独 2024-08-14 19:30:40

SWF-Button 必须实现 id 属性设置器的函数。该方法可以参考Loader-SWF方法,读取Clicks。

样本:

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

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);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文