簡體   English   中英

Flash Builder 4.6 Mobile Flex AS3:如何與嵌入式SWF通信

[英]Flash Builder 4.6 Mobile Flex AS3: How to communicate with embedded SWF

我有一個Flash條形碼掃描儀(相機),並想在移動項目中使用它來掃描QR碼。 可以重用此SWF並將其嵌入到移動Flex應用程序中將是很好的。 SWF是在Flash CS5中制作的。

到目前為止,嵌入(並將其添加到場景中並顯示出來)是成功的,但是我如何與SWF通信? 例如,調用該函數的功能或使用事件。

這是一個代碼片段:

[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!');
}

有誰知道與這個“事物”進行交流?

使用外部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'");
        }
    }
}
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM