Hi all
Fairly new to AS3. My problem is I wish to find the x and y position of certain child objects. however when i try to display these values I am only shown their position when the child is initially added to the stage.
Once the child moves due to the parent object moving, visually the child is moving, however when tracing or displaying the childs x position it remains static.
Here is an abstracted version of my problem, it is all code based so it should run fine. The problem area is highlighted using comments and you will notice that the child positions in the trace logs do not change.
Any Ideas?
package
{
import flash.display.MovieClip;
import flash.display.Stage;
import flash.events.*;
import flash.text.TextField;
import flash.ui.Mouse;
import flash.display.Sprite;
public class Problem extends MovieClip {
private var grandFather:Sprite = new Sprite();
private var parentt:Sprite = new Sprite();
private var grandChild:Sprite = new Sprite();
private var miceDown:Boolean = false;
public function Problem():void {
this.addEventListener(Event.ENTER_FRAME, eFramemainContainer);
this.addEventListener(MouseEvent.MOUSE_DOWN, moveFamily);
this.addEventListener(MouseEvent.MOUSE_UP, stopFamily);
createFamily();
addFamily();}
private function tracePos():void{
//update the text
trace("-----------------------------");
trace("GrandFather: X: " + grandFather.x + "Y: " + grandFather.y);
//Problem occurs here !!!!!!!!!!!!!!
trace("Parent:X: " + parentt.x + "Y: " + parentt.y);
trace("GrandChild: X: " + grandChild.x +"Y: " + grandChild.y);
//Problem occurs here !!!!!!!!!!!!!!
}
private function eFramemainContainer(e:Event):void{
//move the family
if (miceDown == true) {
grandFather.x = mouseX;
grandFather.y = mouseY;}
else if (miceDown == false) {
grandFather.x = grandFather.x;
grandFather.y = grandFather.y;}
}
private function moveFamily(event:MouseEvent):void{
miceDown = true;}
private function stopFamily(event:MouseEvent):void{
tracePos();
miceDown = false}
private function createFamily():void {
grandFather.graphics.lineStyle(3, 0x00ff00);
grandFather.graphics.beginFill(0x0000ff);
grandFather.graphics.drawRect(0,0,100,100);
grandFather.graphics.endFill();
grandFather.x = 200;
grandFather.y = 200;
grandFather.name = "grandFather";
parentt.graphics.lineStyle(3, 0x00ff00);
parentt.graphics.beginFill(0x00FFff);
parentt.graphics.drawRect(0,0,75,75);
parentt.graphics.endFill();
parentt.x = 200;
parentt.y = 0;
parentt.name = "parentt";
grandChild.graphics.lineStyle(3, 0x00ff00);
grandChild.graphics.beginFill(0xFFFFff);
grandChild.graphics.drawRect(0,0,25,25);
grandChild.graphics.endFill();
grandChild.x = 150;
grandChild.y = 0;
grandChild.name "grandChild";
}
private function addFamily():void{
this.addChild(grandFather);
grandFather.addChild(parentt);
parentt.addChild(grandChild);
}
}
}