0

I want to set coordinates of some movieclips. But it's shows the movieclips based on their their own origins. So I think I have to use "parent". Here's my code:

...
    d2: {
        piece: wp1_txt,
        pieceLoc: {
            parent.x: "147",
            parent.y: "297"
        }
    },

...
addChild(squareArr.d2.piece);
squareArr.d2.piece.x = squareArr.d2.pieceLoc.parent.x;
squareArr.d2.piece.y = squareArr.d2.pieceLoc.parent.y;

TweenLite.to(currentPiece, 0.3, {x:squareArr[newSquare].pieceLoc.parent.x, y:squareArr[newSquare].pieceLoc.parent.y, ease:Linear.easeNone, onComplete:isMovingFunction});

Above code (without parent) is moving the textfield out of the stage. When I set x and y to 0, the textfield remaining it's own position instead of appearing on top left.

4
  • What is your exact problem? addChild() w.r.t parent. How is your MovieClips structure? Commented Mar 10, 2014 at 9:17
  • Hello, thanks for your reply. It's a text field, not a movieclip, I couldn't understand what you mean by saying structre. My problem is the textfield's x and y coordinates. Above code is moving the textfield out of the stage. When I set x and y to 0, the textfield remaining it's own position instead of appearing on top left. Commented Mar 10, 2014 at 9:31
  • Where are you adding this TextField. on the stage or inside any MovieClip? Commented Mar 10, 2014 at 9:41
  • sudrap.org/paste/text/309796 Commented Mar 10, 2014 at 9:48

2 Answers 2

1

Try localToGlobal function http://help.adobe.com/en_US/AS2LCR/Flash_10.0/help.html?content=00001320.html Coords of child is relative to parent. If you want to use global coords localToGlobal/globalToLocal is a good option.

Sign up to request clarification or add additional context in comments.

1 Comment

You do realize that, that is a a link to an AS2 page right?
0

What do you mean by "use parent"? When you add some display object to the container, position of the parent will be accounted, without any additional calculations from you. If you want store coordinates of some display object:

d2: {
    piece: wp1_txt,
    pieceLoc: {
        x: someDisplayObject.x,
        y: someDisplayObject.y,
        //If you need store coordinates of some parent object
        parentX: someDisplayObject.parent.x
        parentY: someDisplayObject.parent.y
    }
}

//...
var addedObject:DisplayObject = addChild(squareArr.d2.piece);
addedObject.x = squareArr.d2.pieceLoc.x;
addedObject.y = squareArr.d2.pieceLoc.y;

When I set x and y to 0, the textfield remaining it's own position instead of appearing on top left.

It's because parent of the TextField has his own coordinates, if you can, move parent to the 0,0 coordinates. Also, in your code, you pass coordinates as Strings to the TweenLite, Tweenlite will render them as addition to the current position.

Move TextField out of the stage, slide to the right:

TweenLite.to(currentPiece, 0.3, {x:stage.stageWidth, ease:Linear.easeNone, onComplete:isMovingFunction});

1 Comment

I see, I added several assumptions based on your edit.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.