{"id":33,"date":"2008-03-13T20:05:41","date_gmt":"2008-03-14T01:05:41","guid":{"rendered":"http:\/\/www.lonhosford.com\/lonblog\/2008\/03\/13\/flex-liveconnection-and-legacy-flash-swfs\/"},"modified":"2014-03-16T12:59:05","modified_gmt":"2014-03-16T17:59:05","slug":"flex-liveconnection-and-legacy-flash-swfs","status":"publish","type":"post","link":"https:\/\/www.lonhosford.com\/lonblog\/2008\/03\/13\/flex-liveconnection-and-legacy-flash-swfs\/","title":{"rendered":"Flex LiveConnectionand Legacy Flash Swfs"},"content":{"rendered":"<p>The more RIA shops move web apps into Flex the ugly issue of integration of legacy Flash SWFs into Flex may show up.<\/p>\n<p>The likely Flex component to use for loading Flash SWFs is SWFLoader. It can handle Actionscript 2 legacy Flash 8 or CS3 SWFs.<\/p>\n<p>You may also use SWFLoader for cases of separate independent Flash SWFs that also need to be used into a Flex app and you may not have control over the SWF internal development requiring preparedness for just about anything.<\/p>\n<p>For example you get SWFs with independent inputs from places such as FlashVars, external XML or even another SWF container. Perhaps there are internal functions in  place handling these tasks.<\/p>\n<p>However you find that code you need to call from Flex is not available on frame 1. You may find SWFLoader cannot call those functions due to timing inside the Flash SWF and you do not want to recode the SWF.<\/p>\n<p>Then you might find using LocalConnection as a solution. You have the SWF invoke functions in the Flex SWFLoader component to inform ready states such as code available on a certain frame. Then the Flex function can use LocalConnection to call the SWF function.<\/p>\n<p>Here is an example where the requisite code was on frame 10 of the FLA file.<\/p>\n<p>[cc lang=&#8221;actionscript&#8221; tab_size=&#8221;3&#8243; line_numbers = &#8220;true&#8221;]<br \/>\nSystem.security.allowDomain(&#8220;*&#8221;);<br \/>\nvar _fromFlex_lc:LocalConnection = new LocalConnection();<br \/>\n_fromFlex_lc.allowDomain(&#8220;*&#8221;);<\/p>\n<p>_fromFlex_lc.loadXML = function(xmlStr:String):Void<br \/>\n{<br \/>\nMain.getInst().loadXML ( xmlStr );<br \/>\n_fromFlex_lc.close();<br \/>\n}<\/p>\n<p>_fromFlex_lc.connect(&#8220;flex2Swf_lc&#8221;);<br \/>\nvar _outgoing_lc:LocalConnection = new LocalConnection();<br \/>\n_outgoing_lc.allowDomain(&#8220;*&#8221;);<br \/>\n_outgoing_lc.send( &#8220;swf2Flex_lc&#8221;, &#8220;swfReadyToLoad&#8221; );<\/p>\n<p>[\/cc]<br \/>\nHere is the SWFLoader component:<br \/>\n<code tab_size=\"3\" line_numbers=\"true\" lang=\"actionscript\"><br \/>\n<mx:swfloader source=\"pathToSwf\/the.swf\" width=\"550\" height=\"400\"><br \/>\nxmlns:mx=\"http:\/\/www.adobe.com\/2006\/mxml\"  creationComplete=\"initSwfComp()\"&gt;<br \/>\n<mx:script><br \/>\n<!--[CDATA[<br \/>\n    private var fromSwf_lc:LocalConnection;<br \/>\n    private var toSwf_lc:LocalConnection;<br \/>\n    private var swfXmlData:XML;<\/p>\n\n\n\n\n<p>    public function set dataProvider(xmlData:XML):void<br \/>\n    {<br \/>\n        swfXmlData = xml;<br \/>\n    }<br \/>\n    private function initSwfComp():void<br \/>\n    {<br \/>\n        Security.allowDomain(\"*\"); \/\/ If needed for internal SWF<br \/>\n        createLocalConnection();<br \/>\n    }<br \/>\n    private function createLocalConnection():void<br \/>\n    {<\/p>\n\n\n\n\n<p>        toSwf_lc = new LocalConnection();<br \/>\n        toSwf_lc.allowDomain(\"*\");<br \/>\n        fromSwf_lc = new LocalConnection();<br \/>\n        fromSwf_lc.allowDomain(\"*\");<br \/>\n        fromSwf_lc.client = this;<br \/>\n        fromSwf_lc.connect( \"swf2Flex_lc\" );<br \/>\n    }<br \/>\n    public function swfReadyToLoad() : void<br \/>\n    {<\/p>\n\n\n\n\n<p>        sendXMLData();<br \/>\n    }<br \/>\n    private function sendXMLData():void<br \/>\n    {<\/p>\n\n\n\n\n<p>        toSwf_lc.send( \"flex2Swf_lc\", \"loadXMLData\",  swfXmlData.toXMLString());<br \/>\n        fromSwf_lc.close();<br \/>\n    }<\/p>\n\n\n\n\n<p>]]--><br \/>\n<\/mx:script><br \/>\n<\/mx:swfloader><\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The more RIA shops move web apps into Flex the ugly issue of integration of legacy Flash SWFs into Flex may show up. The likely Flex component to use for loading Flash SWFs is SWFLoader. It can handle Actionscript 2 legacy Flash 8 or CS3 SWFs. You may also use SWFLoader for cases of separate [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[3],"class_list":["post-33","post","type-post","status-publish","format-standard","hentry","category-general","tag-adobe-flash"],"_links":{"self":[{"href":"https:\/\/www.lonhosford.com\/lonblog\/wp-json\/wp\/v2\/posts\/33","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.lonhosford.com\/lonblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.lonhosford.com\/lonblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.lonhosford.com\/lonblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.lonhosford.com\/lonblog\/wp-json\/wp\/v2\/comments?post=33"}],"version-history":[{"count":2,"href":"https:\/\/www.lonhosford.com\/lonblog\/wp-json\/wp\/v2\/posts\/33\/revisions"}],"predecessor-version":[{"id":3327,"href":"https:\/\/www.lonhosford.com\/lonblog\/wp-json\/wp\/v2\/posts\/33\/revisions\/3327"}],"wp:attachment":[{"href":"https:\/\/www.lonhosford.com\/lonblog\/wp-json\/wp\/v2\/media?parent=33"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.lonhosford.com\/lonblog\/wp-json\/wp\/v2\/categories?post=33"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.lonhosford.com\/lonblog\/wp-json\/wp\/v2\/tags?post=33"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}