如何通过变量从.swf文件到。至于文件?文件、变量、swf

2023-09-08 13:20:22 作者:高冷病友

我在。作为一个主要的和我在.as.It的正常工作负载瑞士法郎,现在我想取变量从.swf文件,并通过它进入。作为。我怎样才能做到这一点?请。帮帮我! 我的.swf文件编码

 函数FORMATMESSAGE(chatData:对象)
{
VAR数:UINT = chatData.user;
跟踪(chatData.user);
}
私有函数addText()
    {
_loader =新的Loader();
_loader.x = 10;
_loader.y = 200;
_loader.load(新的URLRequest(receive.swf)); //在这里我可以加载Swf.Here我怎么能存取权限数量的变量?
 的addChild(_loader);
    }
 

解决方案

首先要记住的是,这将不会跨越的ActionScript虚拟机版本。含义只有AVM2和AVM2可以使沟通(这是可能的AVM1之间,但需要更别出心裁)。

添加完成事件侦听器名为 _loader.contentLoaderInfo 属性的onLoad

  _loader.x = 10;
_loader.y = 200;
_loader.contentLoaderInfo.addEventListener(引发Event.COMPLETE,的onLoad);
 
苹果手机怎么才能打开swf的文件

现在的的onLoad 功能将需要提取加载的内容和一点点的铸造。

 函数的onLoad(EVT:事件):无效{
    VAR目标:的DisplayObject =的LoaderInfo(evt.target).content为的DisplayObject; //铸成的DisplayObject
    跟踪(自述=,目标[your_variable]); //跟踪输出your_variable
}
 

有更清洁的得到这个工作,但是这将允许你提取嵌套SWF的价值。

I have a main in .as and I load .swf in my .as.It's Working fine,Now I want the take variable From .swf and Pass it Into .as. How can i do this? pls. help! My .swf file coding

function formatMessage(chatData:Object)
{
var number:uint = chatData.user;
trace(chatData.user);
}
private function addText()
    {
_loader = new Loader();
_loader.x=10;
_loader.y=200;
_loader.load(new URLRequest("receive.swf"));//Here i Can Load the Swf.Here how Can i acces  the Variable of number ?
 addChild(_loader);
    }

解决方案

First thing to keep in mind is that this will not work across ActionScript VM versions. Meaning only AVM2 and AVM2 can make communication (it is possible between AVM1, but takes more ingenuity).

Add a completion event listener to the _loader.contentLoaderInfo property called onLoad

_loader.x=10;
_loader.y=200;
_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoad);

Now with the onLoad function will need to extract the loaded content and a little casting.

function onLoad(evt:Event):void {
    var target:DisplayObject = LoaderInfo(evt.target).content as DisplayObject; // cast as DisplayObject
    trace("readMe = ", target["your_variable"]); // trace output "your_variable"
}

There are cleaner forms of getting this done, but this will allow you extract the value from the nested SWF.