views:

14

answers:

1

I'm adding several instances of an MC (bread_mc) into a container MC (wall_mc). wall_mc has been added to a shop class and that is where i'm called the rest of my functions from. Also the wall_mc is scrolled left and right with mouseX & mouseY values. I've set up a function to add the bread_mc to the wall at different x/y positions.

Function call:

fillShelves(bread_mc,Bread,600,200);

Function:

 function fillShelves(productMc:MovieClip,className:Class,productX:Number, productY:Number) {

        newProduct = new className();
        newProduct.x=productX;
        newProduct.y=productY;
        shelf_mc.addChildAt(newProduct,1);

        newProduct.addEventListener(MouseEvent.MOUSE_DOWN, dragProduct, false, 0, true);

    }

I've added a drag/drop where the bread_mc will snap back to it's shelf x/y position. However i'd like that when user MOUSE_DOWN on bread_mc it is added to the highest depth so, while dragged, it stays infront of other mc's (a person with a shopping cart for example).

My problem is, whenever I call the function dragProduct();

function dragProduct(e:MouseEvent):void {

    currMC = (e.target as MovieClip);
    this.addChild(currMC); 
    stage.addEventListener(MouseEvent.MOUSE_UP, dropProduct);

    }

The damn bread_mc I click on moves to the right by the same amount that I've scrolled the wall_mc. I have tried forcing the currMC to stick with the mouseX/Y but that would need an ENTER_FRAME function and that seems so convoluted.

I researched and found localToGlobal. Methods simliar to this:

point = new Point(currMC.x, currMC.y);
    currMC.localToGlobal(point);
    trace(point.x);

I really don't even know if i'm using it right, But I think my problem lies in the fact that I need the currMC path to travel up the display list tree and get the global stage X/Y position. I'm not too sure how to implement a dynamic path with the localToGlobal method.

Any help would be appreciated. Even if it's go here>read this. Thanks

A: 

Your dragged bread_mc moveclip moves because it is being move to a different container that has a different origin. In your fillShelves function you are adding bread_mc as a child of shelf_mc. But in the dragProduct function you are adding it to this. Just try adding bread_mc to shelf_mc rather than this. And forget about all the localToGlobal stuff.

When you call addChild, it will bring the target to the front of all its siblings.

TandemAdam
Hi, thanks for the quick reply. The reason I want to do this is because I have a shopper_mc added to the stage (on top of the shelf_mc, not in) And they walk beside the shelf as the shelf scrolls. So, as you can imagine, the dragged product (bread_mc) will never sit above the shopper_mc and I was just hoping to correct this by adding the bread_mc to the stage while it is dragged and then returning it back to it's nested position in the shelf_mc if it is stopDrag()ed. That is why I was hoping to use localToGlobal.
Snowden