我有以下代码,它基本上是屏幕上的动画对象,当翻转时会暂停动画,并显示一些信息。一切正常,但当它暂停时,我会像当前的对象一样“在顶部”,以便其他项目在后面运行。
我看过setChildIndex,但没有太多运气。
package {
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.geom.Point;
import flash.events.KeyboardEvent;
import flash.events.*;
import caurina.transitions.Tweener;
import fl.motion.Color;
public class carpurchase extends Sprite {
public function carpurchase() {
var carX = 570;
//Set cars
var car1:fullCar = new fullCar();
car1.info.alpha = 0;
//var c:Color = new Color();
//c.setTint(0xff0000, 0.8);
//car2.car.transform.colorTransform=c;
car1.x = carX;
car1.y = 280;
car1.info.title.text = "test";
car1.info.desc.text = "test";
addChild(car1);
car1.addEventListener(MouseEvent.ROLL_OVER, carPause);
car1.addEventListener(MouseEvent.ROLL_OUT, carContinue);
function car1Reset():void {
Tweener.addTween(car1, {x:carX, time:0, onComplete:car1Tween});
}
function car1Tween():void {
Tweener.addTween(car1, {x:-120, time:2, delay:3, transition:"linear", onComplete:car1Reset});
}
car1Tween();
var car2:fullCar = new fullCar();
car2.info.alpha = 0;
var c:Color = new Color();
c.setTint(0xff0000, 0.8);
car2.car.transform.colorTransform=c;
car1.x = carX;
car2.y = 175;
car2.info.title.text = "test";
car2.info.desc.text = "test";
addChild(car2);
car2.addEventListener(MouseEvent.ROLL_OVER, carPause);
car2.addEventListener(MouseEvent.ROLL_OUT, carContinue);
function car2Reset():void {
Tweener.addTween(car2, {x:carX, time:0, onComplete:car2Tween});
}
function car2Tween():void {
Tweener.addTween(car2, {x:-120, time:3, delay:0, transition:"linear", onComplete:car2Reset});
}
car2Tween();
function carPause(e:MouseEvent):void {
Tweener.pauseTweens(e.target);
Tweener.addTween(e.target.info, {y:-150, alpha:1, time:.5, transition:"easeout"});
}
function carContinue(e:MouseEvent):void {
Tweener.addTween(e.target.info, {y:10, alpha:0, time:.5, transition:"easeout"});
Tweener.resumeTweens(e.target);
}
}
}
欢迎任何帮助
答案 0 :(得分:8)
只需在该特定实例上使用addChild()。它将被放置在“顶部”
从帮助文件:
将一个子DisplayObject实例添加到此DisplayObjectContainer实例。该子项将添加到此DisplayObjectContainer实例中所有其他子项的前(顶部)。
是的,即使对象已经位于displaylist上,它也能正常工作。
答案 1 :(得分:4)
您是否尝试过setChildIndex?
答案 2 :(得分:3)
function carPause(e:MouseEvent):void {
setChildIndex(e.target, numChildren-1);
Tweener.pauseTweens(e.target);
Tweener.addTween(e.target.info, {y:-150, alpha:1, time:.5, transition:"easeout"});
}
答案 3 :(得分:2)
我搜索了同样的问题并找到了这个旧帖子。 我以一种很好的方式解决了这个问题,只想分享给人们以便将来找到这篇文章。
问题是,您尝试从loader-object本身设置childindex,但这是设置它的地方。在这种情况下,您需要父路径才能访问所有汽车。
好吧,长话短说: 尝试以下更改: 在属性通道中创建一个新的Sprite(在classname之后)
// [...]
public class carpurchase extends Sprite {
private var _sprite:Sprite = new Sprite();
}
// [...]
// Add the cars to the sprite
_sprite.addChild(car1); // replace this lines
//[...]
_sprite.addChild(car2); // replace this lines
// Of course adding the sprite to your stage
addChild(_sprite);
之后,通过查找名称并将其设置在顶部
来访问当前目标_mc.setChildIndex(_mc.getChildByName(e.target.name), _mc.numChildren-1); // Set on top
愿它,它有一天会有人帮助
答案 4 :(得分:1)
你试过addChildAt
吗?