flash和flex相互调用
问了好多人,都不告诉我。是我想复杂了。
flex代码
<?xml version="1.0" encoding="utf-8"?><mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" xmlns:local="*" creationComplete="init()"> <mx:Script> <![CDATA[ import mx.controls.Alert; private function init():void{ var obj:Object=swf.content; obj.yuanjian.addEventListener("click",click); obj.flexCallFlash(); } private function click(event:Event){ mx.controls.Alert.show("click"); } public function flashCallFlex():void{ mx.controls.Alert.show("flash Call Flex"); } ]]> </mx:Script> <mx:SWFLoader source="image1.swf" id="swf"> </mx:SWFLoader> </mx:WindowedApplication>?flash代码
yuanjian.addEventListener("hello",hello);yuanjian.dispatchEvent(new Event("hello"));yuanjian.addEventListener("click",onclick);this.dispatchEvent(new Event("click"));trace("hello");function hello(event:Event){ trace("event");}function onclick(event:Event){ trace("click"); }function flexCallFlash(){ trace("flex调用了"); Object(this.parent.parent.parent).flashCallFlex();}?