flexand,Flex and Flash 通讯

flex与flash通讯首先使用flash cs4建一个as 3的flash文件,建二帧,在第一帧用文本工具写上Hello World,并在第一帧上写上如下代码: 首先使用flash cs4建一个as 3的flash文件,建二帧,在第一帧用文本工具写上Hello World,并在第一帧上写上如下代码:
Java代码
flexand,Flex and Flash 通讯

flexand,Flex and Flash 通讯

flexand,Flex and Flash 通讯

stop(); function gonext():void { gotoAndPlay(2); }//定义一个gonext的函数,作用为跳到第二帧; stop();function gonext():void{gotoAndPlay(2);}//定义一个gonext的函数,作用为跳到第二帧;
Html代码
flexand,Flex and Flash 通讯

flexand,Flex and Flash 通讯

flexand,Flex and Flash 通讯

在第二帧上用文本工具写上; 调用flex函数是一个button,命名为ozbutton, 在第二帧上用文本工具写上;调用flex函数是一个button,命名为ozbutton,
并在第二帧上写下如下代码:
Xml代码
flexand,Flex and Flash 通讯

flexand,Flex and Flash 通讯

flexand,Flex and Flash 通讯

stop(); ozbutton.addEventListener(MouseEvent.CLICK,OzClick); function OzClick(evt:MouseEvent):void { dispatchEvent(new Event("OKTWO")); }//为ozbutton添加一个监听鼠标点击的事件,当鼠标点击时,发送一个OKTWO的广播事件 stop();ozbutton.addEventListener(MouseEvent.CLICK,OzClick);function OzClick(evt:MouseEvent):void{dispatchEvent(new Event("OKTWO"));}//为ozbutton添加一个监听鼠标点击的事件,当鼠标点击时,发送一个OKTWO的广播事件
这样flash的制做就完成了,命名为flash;下面说下在flex里如何调用flash
首先建一个名为flex_flash的flex工程,用一个image的组件来加载刚制做的flash文件;
Xml代码
flexand,Flex and Flash 通讯

flexand,Flex and Flash 通讯

flexand,Flex and Flash 通讯

<mx:Image x="111" y="88" source="flash/flash.swf" complete="FlashComplete(event)" id="flashContent"/> <mx:Image x="111" y="88" source="flash/flash.swf" complete="FlashComplete(event)" id="flashContent"/>
Html代码
flexand,Flex and Flash 通讯

flexand,Flex and Flash 通讯

flexand,Flex and Flash 通讯

当flash加载完成之后会触发complete事件,并调用FlashComplete(event)函数; 当flash加载完成之后会触发complete事件,并调用FlashComplete(event)函数;
Xml代码
flexand,Flex and Flash 通讯

flexand,Flex and Flash 通讯

flexand,Flex and Flash 通讯

private function FlashComplete(event:Event):void { flashMc=flashContent.content as MovieClip; flashMc.addEventListener("OKTWO",SayHello); } private function FlashComplete(event:Event):void { flashMc=flashContent.content as MovieClip; flashMc.addEventListener("OKTWO",SayHello); }
Html代码
flexand,Flex and Flash 通讯

flexand,Flex and Flash 通讯

flexand,Flex and Flash 通讯

flashMc是一个MovieClip类,并把flashContent.content赋值给它,这样flashMc就相当于你刚制做的flash,你可以使用它来调用里面的函数;完整的代码如下 flashMc是一个MovieClip类,并把flashContent.content赋值给它,这样flashMc就相当于你刚制做的flash,你可以使用它来调用里面的函数;完整的代码如下
Xml代码
flexand,Flex and Flash 通讯

flexand,Flex and Flash 通讯

flexand,Flex and Flash 通讯

<?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" initialize="init()"> <mx:Script> <![CDATA[ import mx.controls.Button; import mx.controls.Alert; private var flashMc:MovieClip;//定义一个MC对象 private function FlashComplete(event:Event):void { flashMc=flashContent.content as MovieClip; flashMc.addEventListener("OKTWO",SayHello); } private function NextFrame():void { flashMc.gonext(); } private function SayHello(event:Event):void { Alert.show("HELLO World"); } ]]> </mx:Script> <mx:Image x="111" y="88" source="flash/flash.swf" complete="FlashComplete(event)" id="flashContent"/> <mx:Button x="182" y="222" label="NextFrame" click="NextFrame()" id="b"/></mx:Application
Tags:  flexand

延伸阅读

最新评论

发表评论