Actionscript 3 加载外部swf时正确使用addtoStage

Actionscript 3 加载外部swf时正确使用addtoStage,actionscript-3,stack-overflow,Actionscript 3,Stack Overflow,我正在将外部swf文件加载到父swf文件中 之前,我遇到了错误1009,并通过在运行任何脚本之前使用侦听器事件将swf添加到后台来修复该错误 但是,如此URL所示,当嵌入到父swf中时,swf无法完全加载 这是我正在使用的代码 谢谢你的意见 package { import com.greensock.TweenLite; import flash.display.DisplayObject; import flash.display.Bitmap; impo

我正在将外部swf文件加载到父swf文件中

之前,我遇到了错误1009,并通过在运行任何脚本之前使用侦听器事件将swf添加到后台来修复该错误

但是,如此URL所示,当嵌入到父swf中时,swf无法完全加载

这是我正在使用的代码

谢谢你的意见

package 
{
    import com.greensock.TweenLite;
    import flash.display.DisplayObject;
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.display.SpreadMethod;
    import flash.display.Sprite;
    import flash.display.Stage;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.events.TimerEvent;
    import flash.utils.Timer;
    import flash.utils.getDefinitionByName;

    public class slider5 extends Sprite
    {

        public var thumbPath:String = "Trailchair_thumb";
        public var featPath:String = "Trailchair";

        public var sliderIndex:Number = 1;
        public var currBg:Bitmap = new Bitmap();

        public var thumbCount:Number = 8;
        public var thumbHolder:Sprite = new Sprite();

        public var thumbMask:Sprite = new Sprite();

        public var thumbX:Number = 0;
        public var thmPadding:Number = 10;
        public var thmWidth:Number;

        public var navLeft:Sprite = new Sprite();
        public var navRight:Sprite = new Sprite();

        public var timer:Timer = new Timer(5000,0);
        public var sliderDir:String = "fwd";


        public function slider5()
        {
            addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
        }

        public function onAddedToStage(e:Event):void{
        removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage);

            //THE BACKGROUND IMAGE
            currBg.alpha = 1;
            stage.addChildAt(currBg, 0);
            changeBg(sliderIndex);


            //The thumbMask a sprite with graphic rectangle
            thumbMask.x = 87;
            thumbMask.y = 572;
            thumbMask.graphics.beginFill(0xFFFFFF);
            thumbMask.graphics.drawRect(0,0, 406, 181);
            stage.addChildAt(thumbMask, 2);


            //The thumbSlider
            thumbHolder.x = 228;
            thumbHolder.y = 573;
            stage.addChildAt(thumbHolder, 1);
            thumbHolder.mask = thumbMask;

            buildThumbs();

            //add the nav
            navLeft.x = 100;
            navLeft.y = 609;

            navRight.x = 496;
            navRight.y = 609;

            stage.addChildAt(navLeft, 4);
            stage.addChildAt(navRight, 4);

            var navBmp:Bitmap = new Bitmap();
            navBmp.bitmapData = new navarrow(109,109);

            var navBmp_Rt:Bitmap = new Bitmap();
            navBmp_Rt.bitmapData = new navarrow(109,109);

            navLeft.addChild(navBmp);
            navLeft.scaleX *=  -1;

            navRight.addChild(navBmp_Rt);

            navLeft.useHandCursor = true;
            navLeft.buttonMode = true;
            navRight.useHandCursor = true;
            navRight.buttonMode = true;

            navLeft.name = "left";
            navRight.name = "right";

            navLeft.addEventListener(MouseEvent.CLICK, navClick);
            navRight.addEventListener(MouseEvent.CLICK, navClick);


            //add the active item frame
            var frame:Sprite = new Sprite();
            frame.x = 226;
            frame.y = 570;
            frame.graphics.lineStyle(10, 0x000000);
            frame.graphics.drawRect(0,0,131, 181);

            stage.addChildAt(frame, 6);

            timer.addEventListener(TimerEvent.TIMER, timeEvt);
            timer.start();

        }


        public function changeBg(index):void
        {
            //set the first slide from our library and add to the stage
            var currBg_Class:Class = getDefinitionByName( featPath + index ) as Class;
            currBg.bitmapData = new currBg_Class(597,842);

            //fade it in
            TweenLite.from(currBg, 0.5, {alpha:0});
        }

        public function buildThumbs():void
        {
            var currThm:Class;

            for (var i:uint = 1; i<=thumbCount; i++)
            {
                currThm = getDefinitionByName( thumbPath + i ) as Class;
                var thmBmp:Bitmap = new Bitmap();
                thmBmp.bitmapData = new currThm(126,176);
                thmBmp.x = thumbX;
                thumbHolder.addChild(thmBmp);

                thumbX +=  thmBmp.width + thmPadding;
            }

            thmWidth = thmBmp.width + thmPadding;
        }


        public function navClick(e):void
        {

            timer.reset();
            timer.start();
            var dir:String = e.currentTarget.name;

            if (dir=="left" && thumbHolder.x < 228 )
            {
                sliderIndex--;
                TweenLite.to(thumbHolder, 0.5, {x:thumbHolder.x + thmWidth});
                //thumbHolder.x = thumbHolder.x + thmWidth;
            }
            else if (dir=="right" && thumbHolder.x > - 724 )
            {
                sliderIndex++;
                TweenLite.to(thumbHolder, 0.5, {x:thumbHolder.x - thmWidth});
                //thumbHolder.x = thumbHolder.x - thmWidth;
            }

            if (sliderIndex == thumbCount)
            {
                sliderDir = "bk";
            }

            if (sliderIndex == 1)
            {
                sliderDir = "fwd";
            }

            changeBg(sliderIndex);
        }


        public function timeEvt(e):void
        {
            if (sliderDir == "fwd")
            {
                navRight.dispatchEvent(new Event(MouseEvent.CLICK));
            }
            else if (sliderDir == "bk")
            {
                navLeft.dispatchEvent(new Event(MouseEvent.CLICK));
            }
        }



    }
}
包
{
进口com.greensock.TweenLite;
导入flash.display.DisplayObject;
导入flash.display.Bitmap;
导入flash.display.BitmapData;
导入flash.display.SpreadMethod;
导入flash.display.Sprite;
导入flash.display.Stage;
导入flash.events.Event;
导入flash.events.MouseEvent;
导入flash.events.TimerEvent;
导入flash.utils.Timer;
导入flash.utils.getDefinitionByName;
公共类slider5扩展了Sprite
{
公共变量thumbPath:String=“Trailchair\u thumb”;
公共路径:String=“Trailchair”;
公共变量sliderIndex:Number=1;
public var currBg:Bitmap=新位图();
公共变量thumbCount:Number=8;
public-var-thumbHolder:Sprite=new-Sprite();
public-var-thumbsmask:Sprite=new-Sprite();
公共变量thumbX:Number=0;
公共变量:数字=10;
公共宽度:数字;
public var navLeft:Sprite=new Sprite();
public-var-navRight:Sprite=new-Sprite();
公共var定时器:定时器=新定时器(5000,0);
public-var-sliderDir:String=“fwd”;
公共功能幻灯片5()
{
addEventListener(Event.ADDED_至_阶段,OnAddedStatage);
}
AddedStatage上的公共函数(e:事件):无效{
移除EventListener(Event.ADDED_至_阶段,OnAddedStatage);
//背景图像
currBg.alpha=1;
阶段。添加childat(currBg,0);
changeBg(sliderIndex);
//拇指遮罩是一个带有图形矩形的精灵
拇指面罩x=87;
拇指面罩y=572;
thumbsmask.graphics.beginll(0xFFFFFF);
图形学drawRect(0,0406181);
阶段。addChildAt(拇指面具,2);
//拇指滑块
拇指夹x=228;
拇指夹y=573;
阶段。添加儿童(拇指夹,1);
thumbHolder.mask=拇指面具;
buildThumbs();
//添加导航
navLeft.x=100;
navLeft.y=609;
navRight.x=496;
navRight.y=609;
阶段。添加Childat(导航左,4);
第二阶段:addChildAt(navRight,4);
var navBmp:Bitmap=新位图();
navBmp.bitmapData=新的导航箭头(109109);
var navBmp_Rt:Bitmap=新位图();
navBmp_Rt.bitmapData=新的导航箭头(109109);
addChild(navBmp);
navLeft.scaleX*=-1;
navRight.addChild(navBmp\u Rt);
navleet.useHandCursor=true;
navLeft.buttonMode=true;
navRight.useHandCursor=true;
navRight.buttonMode=true;
navleet.name=“left”;
navRight.name=“right”;
添加EventListener(MouseEvent.CLICK,navClick);
navRight.addEventListener(MouseEvent.CLICK,navClick);
//添加活动项框架
变量帧:Sprite=新Sprite();
帧x=226;
帧y=570;
frame.graphics.lineStyle(10,0x000000);
frame.graphics.drawRect(0,0131181);
阶段。添加Childat(第6帧);
timer.addEventListener(TimerEvent.timer,timeEvt);
timer.start();
}
公共功能变更BG(索引):无效
{
//从我们的库中设置第一张幻灯片并添加到舞台
var currBg_Class:Class=getDefinitionByName(featPath+index)作为类;
currBg.bitmapData=新的currBg_类(597842);
//淡入
TweenLite.from(currBg,0.5,{alpha:0});
}
公共函数buildThumbs():void
{
var-currThm:类;
对于(变量i:uint=1;i-724)
{
sliderIndex++;
TweenLite.to(thumbHolder,0.5,{x:thumbHolder.x-thmWidth});
//thumbHolder.x=thumbHolder.x-宽度;
}
如果(sliderIndex==拇指计数)
{
sliderDir=“bk”;
}
如果(sliderIndex==1)
{
sliderDir=“fwd”;
}
changeBg(sliderIndex);
}
公共功能时间EVT(e):无效
{
如果(滑块方向==“前进”)
{
dispatchEvent(新事件(MouseEvent.CLICK));
}
else if(sliderDir==“bk”)
{
dispatchEvent(新事件(MouseEvent.CLICK));
}
}
}
}

如果您仍然需要它,您可以尝试以下两个建议。注意:我不知道Zmags,最初假设它是你自己的域名。这就是我建议您使用Loader类的原因。当我做一个parent.swf'的测试版本,加载一个包含您的代码的测试'child.swf'时,它对我起到了作用。它实际上加载了子swf,没有任何问题

  • 从扩展Sprite更改为扩展MovieClip

  • 避免检查此项目中是否已添加到阶段

  • 说明:

  • 扩展MovieClip而不是Sprite
  • 我长话短说Flash不喜欢你的swf扩展精灵然后被扩展Movieclip的父加载程序打开。ZMag播放器将扩展MovieClip。这是合乎逻辑的,文档确实以某种方式确认了这一点。无论它是否解决了您的问题,只要在使用ZMags时保持MovieClip即可

  • 避免在代码中引用阶段
  • 查看此Zmags问答文档: