views:

297

answers:

4

Hi All,

i have the below code, which is basically animating object across the screen, when roll-over happens it pauses the anim, and displays some information. Everything works fine, but when its paused, i wold like that current object to be 'on top' so other items run behind.

I have looked at setChildIndex, but didn't have much luck.

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

Any help welcome

+1  A: 

have you tried addChildAt?

Adobe Live Docs - addChildAt()

Adam Kiss
Would this only work when adding the object to the stage? I would need them to change when paused, ie. that current object would have to be on top when roll-over occurs
jimbo
Nope, it also works when used on something that is already a child. Normally, if you do parent.addChildAt(child, n), you add child to position n, and increase by one the position of all the other children which were at n or above. In effect, you slot the child in like a card into a deck. If you do this when child is already a child of parent, it works exactly the same way, except it doesn't do the adding part, it just moves it to position n.
danyal
I have tried adding:function carPause(e:MouseEvent):void { addChildAt(e.target, 6) Tweener.pauseTweens(e.target); Tweener.addTween(e.target.info, {y:-10, alpha:1, time:1, transition:"easeout"}); }But gives error, any ideas?
jimbo
+2  A: 
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"});
} 
jonathanasdf
Thanks for the response, sorry it has taken me so long to come back to you, been on another job. I have tried adding the line but get an error:1118: Implicit coercion of a value with static type Object to a possibly unrelated type flash.display:DisplayObject.setChildIndex(e.target, this.numChildren-1);Any help again welcome
jimbo
+1  A: 

Have you tried setChildIndex?

Jorge
+1  A: 

Just use addChild() on that specific instance. It will be placed to the 'top'

From the help files:

Adds a child DisplayObject instance to this DisplayObjectContainer instance. The child is added to the front (top) of all other children in this DisplayObjectContainer instance.

And yes, that works even if the object already is on the displaylist.

Creynders