0

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

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

但是,当嵌入到父 swf 中时,swf 无法完全加载,如此 URL http://viewer.zmags.com/publication/06b68a69?viewType=pubPreview#/06b68a69/1所示

这是我正在使用的代码。

感谢您的任何意见。

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));
            }
        }



    }
}
4

1 回答 1

0

如果您仍然需要它,可以尝试这两个建议。注意我不知道 Zmags,最初认为它是您自己的域名。这就是为什么我建议你使用 Loader 类。当我做了一个加载包含您的代码的测试“child.swf”的测试版本的 parent.swf 时,它对我有用。它实际上加载了子 swf 没有问题。

  1. 从扩展 Sprite 更改为扩展 MovieClip

  2. 避免在此项目中检查添加到阶段

说明:

  1. 扩展 MovieClip 而不是 Sprite

我长话短说 Flash 不会喜欢你的 swf 扩展 Sprite 然后被扩展 Movieclip 的父加载器打开。ZMag 播放器将扩展 MovieClip。这是合乎逻辑的,文档确实在某种程度上证实了这一点。无论它是否解决了您的问题,都只是在使用 ZMags 时保留它。

  1. 避免在代码中引用阶段..

查看此 Zmags 问答文档:

http://community.zmags.com/articles/Knowledgebase/Common-questions-on-flash-integration

看看问题 4 .. 在他们的回答中,这两个脱颖而出。

  • 上传的 SWF 中的阶段参数引用与发布冲突
  • 您上传的 SWF 中引用错误或本地引用的资源无法找到

是否真的有必要在此进行 added_to_stage 检查?如果它不会受到伤害,那么我建议从函数slider5() 中删除stage_added 检查,而是将你从函数onAddedToStage(e:Event) 中获得的代码剪切/粘贴到那里。

希望能帮助到你。

于 2013-09-19T11:12:29.607 回答