swf之间传值

今天要做一个Loading的swf文件,加载主文件,但要加载完成后给主文件赋值,

在网上查了一下,:

载入swf后,如何控制它?

在as3中, swf A载入 swf B。用loader类载入的。但发现载入后,尽管在A中 trace(loader.content)明显能够指向B(因为会输出[Object B]这样的信息),但却无法访问其属性和方法,不知道怎么才能让A控制B啊?
 
 
var L:Loader=new Loader();
var UQ:URLRequest=new URLRequest("B.swf");
L.contentLoaderInfo.addEventListener(Event.INIT,onLoadInit);
L.load(UQ);
function onLoadInit(e:Event) {
var LC:Object=L.content
trace(LC.width);
trace(LC.height);
trace(describeType(LC))
LC.width=10;
}
addChild(L);
 
 

斑竹,我不是这个意思。

content是有很多属性可以读取。但是我需要的是,swf B中,有ducment class中定义的属性和方法,需要读取。但读取不了。
 
 
 
 
这个得通过LoaderContext,ApplicationDomain类来解决,域的指向问题
复制内容到剪贴板
代码:
B.swf中的B类//
package{
        import flash.display.Sprite
        public class B extends Sprite{
        public var className:String="[class B]"
        public function func():void{
        trace("func()")
        }
        }
        }
复制内容到剪贴板
代码:
LoadInClass类来进行读取B.swf///
package {
        import flash.display.Sprite;
    import flash.events.*
    import flash.display.Loader
    import flash.net.URLRequest
    import flash.system.LoaderContext;
    import flash.system.ApplicationDomain;
        public class LoadInClass extends Sprite
        {
                private var L:Loader
                private var UQ:URLRequest
                public function LoadInClass()
                {
                        L=new Loader();
                        UQ=new URLRequest("B.swf");
                        var context:LoaderContext = new LoaderContext();
                        context.applicationDomain = ApplicationDomain.currentDomain;
                        L.contentLoaderInfo.addEventListener(Event.INIT,onLoadInit);
                        L.load(UQ,context);
                        addChild(L);
                }
                private function onLoadInit(e:Event):void{
                var classB:Class=L.contentLoaderInfo.applicationDomain.getDefinition("B") as Class
                var b:Object=new classB()
                trace(b.className)
                b.func()
                }       
                }
                }
 
 
还有是也可用LocalConnection,不过不推荐!
// receivingLC is in http://www.domain.com/receiving.swf
receivingLC.allowDomain('www.anotherdomain.com');
receivingLC.connect('myConnection');

// sendingLC is in http://www.anotherdomain.com/sending.swf
sendingLC.send('www.domain.com:myConnection', 'myMethod');
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

游鱼_

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值