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