addtoStage的加载外部SWF时,正确的用法 [英] Correct usage of addtoStage when loading external swf
问题描述
我加载外部SWF文件到父SWF文件。
previously,我得到错误1009和固定,通过使用监听事件来运行任何脚本之前瑞士法郎添加到舞台。
在SWF但是不能完全加载的时候嵌入到父SWF在这个网址看到 http://viewer.zmags.com/publication/ 06b68a69?viewType =酒馆preVIEW#/ 06b68a69 / 1
下面是code我使用。
感谢您的任何输入。
包
{
进口com.greensock.TweenLite;
进口flash.display.DisplayObject;
匹配import flash.display.Bitmap;
进口flash.display.BitmapData;
进口flash.display.S preadMethod;
进口flash.display.Sprite;
进口的flash.display.Stage;
进口对象类型:flash.events.Event;
进口flash.events.MouseEvent;
进口flash.events.TimerEvent;
进口flash.utils.Timer;
进口flash.utils.getDefinitionByName;
公共类slider5扩展Sprite
{
公共变种thumbPath:字符串=Trailchair_thumb;
公共变种featPath:字符串=Trailchair;
公共变种sliderIndex:数= 1;
公共变种currBg:位图=新位图();
公共变种thumbCount:数= 8;
公共变种thumbHolder:雪碧=新的Sprite();
公共变种thumbMask:雪碧=新的Sprite();
公共变种THUMBX:数= 0;
公共变种thmPadding:数= 10;
公共变种thmWidth:数字;
公共变种navLeft:雪碧=新的Sprite();
公共变种navRight:雪碧=新的Sprite();
公共变种定时器:定时器=新的定时器(5000,0);
公共变种sliderDir:字符串=FWD;
公共职能slider5()
{
的addEventListener(Event.ADDED_TO_STAGE,onAddedToStage);
}
公共职能onAddedToStage(五:事件):无效{
removeEventListener(Event.ADDED_TO_STAGE,onAddedToStage);
//背景图片
currBg.alpha = 1;
stage.addChildAt(currBg,0);
changeBg(sliderIndex);
//与图形长方形thumbMask精灵
thumbMask.x = 87;
thumbMask.y = 572;
thumbMask.graphics.beginFill(0XFFFFFF);
thumbMask.graphics.drawRect(0,0,406,181);
stage.addChildAt(thumbMask,2);
//该thumbSlider
thumbHolder.x = 228;
thumbHolder.y = 573;
stage.addChildAt(thumbHolder,1);
thumbHolder.mask = thumbMask;
buildThumbs();
//添加导航
navLeft.x = 100;
navLeft.y = 609;
navRight.x = 496;
navRight.y = 609;
stage.addChildAt(navLeft,4);
stage.addChildAt(navRight,4);
VAR navBmp:位图=新位图();
navBmp.bitmapData =新navarrow(109109);
VAR navBmp_Rt:位图=新位图();
navBmp_Rt.bitmapData =新navarrow(109109);
navLeft.addChild(navBmp);
navLeft.scaleX * = -1;
navRight.addChild(navBmp_Rt);
navLeft.useHandCursor = TRUE;
navLeft.buttonMode =真;
navRight.useHandCursor = TRUE;
navRight.buttonMode =真;
navLeft.name =左;
navRight.name =正确的;
navLeft.addEventListener(MouseEvent.CLICK,navClick);
navRight.addEventListener(MouseEvent.CLICK,navClick);
//添加活动项目框架
VAR框架:雪碧=新的Sprite();
frame.x = 226;
frame.y = 570;
frame.graphics.lineStyle(10,为0x000000);
frame.graphics.drawRect(0,0,131,181);
stage.addChildAt(帧,6);
timer.addEventListener(TimerEvent.TIMER,timeEvt);
timer.start();
}
公共职能changeBg(指数):无效
{
//从我们的库设置的第一张幻灯片,并添加到舞台
VAR currBg_Class:类= getDefinitionByName(featPath +指数)为类;
currBg.bitmapData =新currBg_Class(597842);
//褪色它
TweenLite.from(currBg,0.5%,{阿尔法:0});
}
公共职能buildThumbs():无效
{
VAR currThm:类;
对于(VAR我:UINT = 1; I< = thumbCount;我++)
{
currThm = getDefinitionByName(thumbPath + I)为类;
VAR thmBmp:位图=新位图();
thmBmp.bitmapData =新currThm(126176);
thmBmp.x = THUMBX;
thumbHolder.addChild(thmBmp);
THUMBX + = thmBmp.width + thmPadding;
}
thmWidth = thmBmp.width + thmPadding;
}
公共职能navClick(E):无效
{
timer.reset();
timer.start();
VAR DIR:字符串= e.currentTarget.name;
如果(DIR ==左和放大器;&安培; thumbHolder.x< 228)
{
sliderIndex--;
TweenLite.to(thumbHolder,0.5%,{X:thumbHolder.x + thmWidth});
//thumbHolder.x = thumbHolder.x + thmWidth;
}
否则,如果(DIR ==右和安培;&安培; thumbHolder.x> - 724)
{
sliderIndex ++;
TweenLite.to(thumbHolder,0.5%,{X:thumbHolder.x - thmWidth});
//thumbHolder.x = thumbHolder.x - thmWidth;
}
如果(sliderIndex == thumbCount)
{
sliderDir =BK;
}
如果(sliderIndex == 1)
{
sliderDir =FWD;
}
changeBg(sliderIndex);
}
公共职能timeEvt(E):无效
{
如果(sliderDir ==FWD)
{
navRight.dispatchEvent(新事件(MouseEvent.CLICK));
}
否则,如果(sliderDir ==BK)
{
navLeft.dispatchEvent(新事件(MouseEvent.CLICK));
}
}
}
}
如果你仍然需要它,你可以尝试这两个建议。注意:我不知道Zmags并初步认为,这是你自己的域名。这就是为什么我建议你使用Loader类。它的工作对我来说,当我做了一个parent.swf的加载测试包含您的code child.swf的测试版。它实际加载的子SWF没有问题。
-
从扩展雪碧继承MovieClip更改
-
避免检查,以增加在这个项目中上演
说明:
- 在继承MovieClip,而不是雪碧
我长话短说闪光灯不会喜欢你的swf扩展雪碧再被打开由父加载器,扩展影片剪辑。该ZMag玩家将继承MovieClip。它的逻辑和文档也证实了这一点的方式。无论是解决您的问题或不只是使用ZMags时随身携带影片剪辑。
- 避免阶段在code引用。
看着这个Zmags Q&放大器; A文件建立:
的http://community.zmags.com/articles/Knowledgebase/Common-questions-on-flash-integration
看问题4。在他们的回答这两个脱颖而出。
- 舞台参数的参考,在上传的SWF相互冲突与发布
- 不善或局部引用的资源在您上传的SWF不能找到
难道真的有必要在这一个ADDED_TO_STAGE检查?如果它不会伤害那么我建议撤去stage_added检查从功能slider5(),而是剪切/粘贴在那里code你必须从功能onAddedToStage(五:事件)。
希望它帮助。
I am loading an external swf file into a parent swf file.
Previously, I was getting error 1009 and fixed that by using a listener event to add the swf to the stage before running any scripts.
The swf however fails to load completely when embedded into a parent swf as seen in this URL http://viewer.zmags.com/publication/06b68a69?viewType=pubPreview#/06b68a69/1
Here is the code I am using.
Thank you for any input.
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));
}
}
}
}
If you still need it you can try these two suggestions. Note I didnt know about Zmags and initially assumed that it was your own domain name. That's why I suggested you use the Loader class. It worked for me when I did a test version of a parent.swf' that loaded a test 'child.swf' containing your code. It actually loaded the child swf without problems.
Change from extending Sprite to extending MovieClip
Avoid checking for added to stage in this project
Explanations:
- Extending MovieClip instead of Sprite
I Long story short Flash wont like your swf extending Sprite then being opened by a parent loader that extends Movieclip. The ZMag player will be extending MovieClip. It's logical and the docs do confirm this in a way. Whether it fixes your issue or not just keep it MovieClip when using ZMags.
- Avoiding Stage referencing in your code..
Looking at this Zmags Q&A documentaion:
http://community.zmags.com/articles/Knowledgebase/Common-questions-on-flash-integration
Looking at Question 4.. In their answer these two stand out.
- Reference of the stage parameter in the uploaded SWF conflicting with the publication
- Badly or locally referenced resources in the SWF you uploaded which cannot be found
Is it really necessary to have an added_to_stage check in this? If it wont hurt then I suggest dropping the stage_added checking from function slider5() and instead cut/paste in there the code you have from the function onAddedToStage(e:Event).
Hope it helps.
这篇关于addtoStage的加载外部SWF时,正确的用法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!