I have a panorama viewer in Flash in which I want to embed a small Flex application. I've managed to load the Flex swf into the Flash like this:
private var loader:Loader = new Loader();
var req:URLRequest = new URLRequest("SimpleImageViewer.swf");
loader.load(req);
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, imgViewerLoaded);
imgViewerLoaded(event:Event)
{
imageViewer = loader.content;
addChild(imageViewer);
imageViewer.showImage("test.jpg", "Test Image");
}
Now, the thing is that I need to be able to call a method on the imageViewer, which I've defined in my Flex App like this:
public function showImage(source:String, heading:String = ""):void
{
//Show the image
}
It is also being added to the ExternalInterface using
ExternalInterface.addCallback("showImage", showImage);
How can I call that method from my AS3 Flash? Just calling it as imageViewer.showImage(...) gives this error:
ReferenceError: Error #1069: Property showImage not found on _SimpleImageViewer_mx_managers_SystemManager and there is no default value.
at UserInterface/imgViewerLoaded()
This is the entire SimpleImageViewer.mxml file:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" minWidth="100" minHeight="100" backgroundColor="#2B2B2B" creationComplete="onCreationComplete(event)" backgroundGradientAlphas="[1.0, 1.0]" backgroundGradientColors="[#2B2B2B, #2B2B2B]" verticalScrollPolicy="off" horizontalScrollPolicy="off">
<mx:Image x="0" y="0" width="100%" height="100%" horizontalAlign="center" verticalAlign="middle" scaleContent="true" maintainAspectRatio="true" id="picture"/>
<mx:Image width="100%" height="42" x="0" y="0" id="headingBg" source="@Embed(source='/bilder/topList.png')" scaleContent="true" maintainAspectRatio="false"/>
<mx:Label x="4" y="0" width="100%" height="43" id="headingTxt" fontFamily="Arial" fontSize="32" color="#FFFFFF" textAlign="center"/>
<mx:Script>
<![CDATA[
import mx.events.FlexEvent;
import mx.events.ResizeEvent;
public function showImage(source:String, heading:String = ""):void
{
picture.source = source;
picture.load();
headingTxt.text = heading;
}
protected function onCreationComplete(event:FlexEvent):void
{
ExternalInterface.addCallback("showImage", showImage);
Security.allowDomain("localhost");
}
]]>
</mx:Script>
</mx:Application>
And the ImageViewer interface:
package tikab.lizzan
{
public interface ImageViewer
{
function showImage(source:String, heading:String = ""):void ;
}
}