【问题标题】:Flash Builder 4.6 Mobile Flex AS3: How to communicate with embedded SWFFlash Builder 4.6 Mobile Flex AS3:如何与嵌入式 SWF 通信
【发布时间】:2012-12-19 22:52:30
【问题描述】:

我有一个 Flash 条形码扫描仪(相机),并想在移动项目中使用它来扫描 QR 码。如果可以重新使用此 SWF 并将其嵌入到移动 Flex 应用程序中,那就太好了。 SWF 是在 Flash CS5 中制作的。

到目前为止,嵌入(并将其添加到舞台并显示它)是成功的,但是我如何与 SWF 通信?例如调用它的函数或使用事件。

这是一个代码sn-p:

[Embed(source="../cam/cam.swf")]
private var cam:Class;

....
....

public const EVT_SNAPSHOT : String = "onSnapShot";
public var camera : Object;


public function onInit(e:Event) : void
{
 this.camera = new cam();
 this.camera.addEventListener(Event.ADDED_TO_STAGE, this.cameraInit );
 this.stage.addChild( this.camera as DisplayObject );
}

private function cameraInit(e:Event):void
{
 trace( 'Added to stage' );
 this.stage.addEventListener( EVT_SNAPSHOT, this.cameraDoScan ); // does not bind?
 trace( this.camera.hasOwnProperty('getAppInfo') ); // shows 'false'
}

private function cameraDoScan(e:MouseEvent):void
{
 trace('MouseClick!');
}

有谁知道与这个“东西”交流吗?

【问题讨论】:

    标签: actionscript-3 flash-builder flash communication


    【解决方案1】:

    使用外部 swf 模块最实用的方法是将其加载到当前的 ApplicationDomain 中,这样您就可以访问此加载的 swf 中包含的所有类:

    package
    {
    import flash.display.DisplayObject;
    import flash.display.Loader;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.system.ApplicationDomain;
    import flash.system.LoaderContext;
    import flash.utils.ByteArray;
    import flash.utils.getDefinitionByName;
    
    public class astest extends Sprite
    {
    
        [Embed(source="/../assets/art.swf", mimeType="application/octet-stream")]
        private static const art:Class;
    
        public function astest()
        {
            var artBytes:ByteArray = new art() as ByteArray;
            var loader:Loader = new Loader();
            loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onArtLoaded);
            loader.loadBytes(artBytes, new LoaderContext(false, ApplicationDomain.currentDomain));
        }
    
        protected function onArtLoaded(e:Event):void
        {
            var domain:ApplicationDomain = ApplicationDomain.currentDomain;
            if(domain.hasDefinition("welcome_view"))
            {
                var moduleClass:Class = domain.getDefinition("welcome_view") as Class;
                var module:Object = new moduleClass();
                //module.moduleFunction();
                addChild(module as DisplayObject);
            }else
            {
                trace("loaded swf hasn't class 'welcome_view'");
            }
        }
    }
    }
    

    【讨论】:

      猜你喜欢
      • 2013-10-22
      • 2015-08-05
      • 2012-03-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-09-06
      相关资源
      最近更新 更多