flex 4:swfloader as2 游戏,我可以捕获使用 mx.events.EventDispatcher 发送的自定义事件吗?
我正在为动作脚本 2 Flash 应用程序构建一个 Flex 4 容器。 我使用
组件来加载游戏。
我知道我可以从动作脚本 3 应用程序捕获事件甚至自定义事件。
动作脚本 3(不是 2)的工作示例:
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955"
minHeight="600" creationComplete="init()">
<fx:Script>
<![CDATA[
import mx.controls.Alert;
import Red5Event;
private function handleRed5Event(e:Red5Event):void {
Alert.show("yay");
}
private function init():void {
this.fileSwf.content.addEventListener(Red5Event.CONTROL_TYPE
,handleRed5Event);
}
]]>
</fx:Script>
<mx:SWFLoader id="fileSwf" source="file.swf" />
</s:Application>
然后在 Flash 应用程序中,我扩展了事件类,添加了正确的控件类型并将 bubbles
设置为 true,因此每当我调度一个事件时,它可能会被被flex应用程序捕获。
我知道使用 as2 我可以使用以下示例调度自定义事件:
import mx.events.EventDispatcher;
class Sender {
// these three lines are needed to use EventDispatcher
public var addEventListener:Function;
public var removeEventListener:Function;
public var dispatchEvent:Function;
public function Sender() {
// this line must be in the constructor of the class
EventDispatcher.initialize(this);
// dispatch an event once per second
}
public function sendEvent():Void {
dispatchEvent({type:"xpoControl"});
trace("event sent!");
}
}
我可以以某种方式在 Action script 2 flash 应用程序中调度 Flex 4 容器能够捕获的事件吗?
谢谢!
I'm building a flex 4 container for action script 2 flash applications.
I use <mx:SWFLoader>
component to load the game.
I know that i can catch events or even custom events from an action script 3 application.
working example for action script 3 (not 2):
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955"
minHeight="600" creationComplete="init()">
<fx:Script>
<![CDATA[
import mx.controls.Alert;
import Red5Event;
private function handleRed5Event(e:Red5Event):void {
Alert.show("yay");
}
private function init():void {
this.fileSwf.content.addEventListener(Red5Event.CONTROL_TYPE
,handleRed5Event);
}
]]>
</fx:Script>
<mx:SWFLoader id="fileSwf" source="file.swf" />
</s:Application>
then in the flash application i extend the event class, adding the proper control type and setting bubbles
to true, so whenever i dispatch an event, it's probably being catched by the flex application.
I understood that using as2 i can dispatch custom events using the following example:
import mx.events.EventDispatcher;
class Sender {
// these three lines are needed to use EventDispatcher
public var addEventListener:Function;
public var removeEventListener:Function;
public var dispatchEvent:Function;
public function Sender() {
// this line must be in the constructor of the class
EventDispatcher.initialize(this);
// dispatch an event once per second
}
public function sendEvent():Void {
dispatchEvent({type:"xpoControl"});
trace("event sent!");
}
}
can i somehow dispatch an event in action script 2 flash application that the flex 4 container will be able to catch?
thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
事实上,有解决方法。您是对的,因为由于安全限制,您尝试实现此目的的方式实际上是不可能的。但是,您可以通过 LocalConnection 类构建我称之为编组器适配器的东西。您需要在 AS2 中使用 localConnection 与 flex 4 端进行通信的方法。您将必须使用简单类型并更通用地传递 Red5Event 的属性,但您应该能够使用自定义“编组器适配器”来完成您需要的任务。
祝你好运,
杰里米
Actually, there are work-arounds. You are correct in that the way you're trying to accomplish this isn't really possible because of security restrictions. However, you could build what I like to call a marshaller-adapter via the LocalConnection class. You will need to have a method in AS2 that uses a localConnection to communicate with the flex 4 side. You will have to use simple types and pass the properties of your Red5Event more generically, but you should be able to accomplish what you need with your custom 'marshaller-adapter'.
Best of luck,
Jeremy