我有一个方法,需要一些参数,并动态地将三个图像添加到舞台,它还为三个图像添加背景图像。
我想弄清楚以下内容:如何在背景动画片段和三个动态movieClip中的完整补间中进行补间?我可以在共享相同变量的函数中使用函数吗?
如下所示:
public function addImages(BackGround:String,Image1:String,Image2:String,Image3:String):void
{
var symbol_class:Class = getDefinitionByName(BackGround);
var image1_class:Class = getDefinitionByName(Image1);
var image2_class:Class = getDefinitionByName(Image2);
var image3_class:Class = getDefinitionByName(Image3);
var main_bg = new symbol_class();
var image_1 = new image1_class();
var image_2 = new image2_class();
var image_3 = new image3_class();
main_box.addChild(main_bg);
var BGTween:Tween = new Tween(my_thumb, "alpha", Strong.easeIn, 0,1,0.5, true);
BGTween.addEventListener(TweenEvent.MOTION_FINISH, onFinish);
//WHEN BACKGROUND TWEEN IS COMPLETE NOW ADD THE OTHER IMAGES AND FADE THEM IN.
function onFinish(e:TweenEvent):void {
BGTween.removeEventListener(TweenEvent.MOTION_FINISH, onFinish);
main_box.addChild(image_1);
var image_1_tween:Tween = new Tween(image_1, "alpha", Strong.easeIn, 0,1,0.5, true);
main_box.addChild(image_2);
var image_2_tween:Tween = new Tween(image_2, "alpha", Strong.easeIn, 0,1,0.5, true);
main_box.addChild(image_3);
var image_3_tween:Tween = new Tween(image_3, "alpha", Strong.easeIn, 0,1,0.5, true);
}
}
答案 0 :(得分:1)
你在那附近,你不能在函数中定义一个非常类似的函数,但是你可以做到以下几点:
public function addImages(BackGround:String,Image1:String,Image2:String,Image3:String):void
{
var symbol_class:Class = getDefinitionByName(BackGround);
var image1_class:Class = getDefinitionByName(Image1);
var image2_class:Class = getDefinitionByName(Image2);
var image3_class:Class = getDefinitionByName(Image3);
var main_bg = new symbol_class();
var image_1 = new image1_class();
var image_2 = new image2_class();
var image_3 = new image3_class();
main_box.addChild(main_bg);
var BGTween:Tween = new Tween(my_thumb, "alpha", Strong.easeIn, 0,1,0.5, true);
BGTween.addEventListener(TweenEvent.MOTION_FINISH, function(e:TweenEvent) {
//WHEN BACKGROUND TWEEN IS COMPLETE NOW ADD THE OTHER IMAGES AND FADE THEM IN.
(e.target as EventDispatcher).removeEventListener(e.type, arguments.callee);
main_box.addChild(image_1);
var image_1_tween:Tween = new Tween(image_1, "alpha", Strong.easeIn, 0,1,0.5, true);
main_box.addChild(image_2);
var image_2_tween:Tween = new Tween(image_2, "alpha", Strong.easeIn, 0,1,0.5, true);
main_box.addChild(image_3);
var image_3_tween:Tween = new Tween(image_3, "alpha", Strong.easeIn, 0,1,0.5, true);
});
}
这称为闭包,因为它是匿名函数,它引用其直接范围之外的值。您可以在Wikipedia上详细了解它们。还要注意 removeEventListener 是如何更改的,这是删除匿名函数的方法,因为它不存在名称引用。
答案 1 :(得分:0)
使用TweenLite? http://www.greensock.com/tweenlite
用法:
TweenLite.to(bgObject, timeToFade,{alpha:0, onComplete:addThreeImages});
public function addThreeImages():void
{
//here you can add your images
}