A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: x and y coordinates and angle

  1. #1
    Junior Member
    Join Date
    Oct 2010
    Posts
    24

    x and y coordinates and angle

    Hello,

    I know this question might sound stupid to most of you guys but it is very necessary for me to know the answer.

    How can you get x and y coordinates of an instance? My instance is called "rock". This is what I have tried:

    PHP Code:
    onClipEvent(enterFrame){
        
    trace(rock.x);
        
    trace(rock.y);
        } 
    but it does not work.

    Next, how can I make this instance go up by a certain angle?

    Thank you very much.

  2. #2
    ___________________
    Join Date
    May 2004
    Posts
    3,174
    in AS2, it's _x and _y

    PHP Code:
    onClipEvent(enterFrame){ 
        
    trace(rock._x); 
        
    trace(rock._y); 
        } 
    in AS3, it's .x and .y (like you have). however, there is no onClipEvent in AS3, so you must be in AS2.

    btw, this is the AS3 board.

  3. #3
    Junior Member
    Join Date
    Oct 2010
    Posts
    24
    Um............thank you for your reply. I am sorry about the board error. But in my output window only the word "undefined" is coming up. And I am using AS2 in Flash CS5. Any idea what I am doing wrong? And can you solve my angle problem too? Thank you.

    And I also know that I have had posted this question in the general question forum but now that I have posted it here, please help me.
    Last edited by Flashgamr; 12-08-2010 at 09:18 PM.

  4. #4
    ___________________
    Join Date
    May 2004
    Posts
    3,174
    i answered your question in the first part of my reply.

    for AS2, properties have an underscore before the name. your code says "rock.x" - it should be "rock._x" - notice the underscore. i'll repaste the corrected code:

    PHP Code:
    onClipEvent(enterFrame){ 
        
    trace(rock._x); 
        
    trace(rock._y); 
        } 
    for angles, the most simple formula is this:

    PHP Code:
    var TO_RAD Math.PI/180;
    object._x Math.sin(angle TO_RAD) * distance;
    object._y Math.cos(angle TO_RAD) * distance
    so if you wanted rock to be positioned at 100 pixels 45 degrees from 0, 0, you'd use:

    PHP Code:
    var TO_RAD Math.PI/180;
    rock._x Math.sin(45 TO_RAD) * 100;
    rock._y Math.cos(45 TO_RAD) * 100
    note that this very simple method will start at the 6 o'clock position and go CCW.

    neznein from this board has a nice (and much more informative) post about it here: http://www.calypso88.com/?p=512
    Last edited by moagrius; 12-08-2010 at 10:53 PM. Reason: clarification

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center