Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6989301
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:11:38+00:00 2026-05-27T19:11:38+00:00

When executing the code: var cont:Sprite = new Sprite(); var a:Vector.<int > = Vector.<int

  • 0

When executing the code:

    var cont:Sprite = new Sprite();
var a:Vector.<int >  = Vector.<int > ([1,2]);
var b:Vector.<Number >  = Vector.<Number > ([0,0,40,40]);
cont.graphics.lineStyle(5, 0x442299);
cont.graphics.drawPath(a, b);
addChild( cont );
cont.x = 100;
cont.y = 100;
trace("X coordinate of purple line: ", cont.x);

I get the output “X coordinate of purple line: 100”

However, when I test this code and draw a line from (100, 100) to (140, 140) with the mouse:

var line:Sprite = new Sprite();

stage.addEventListener(MouseEvent.MOUSE_DOWN,mouseDownHandler);
stage.addEventListener(MouseEvent.MOUSE_UP,mouseUpHandler);

var startX:int = -1;
var startY:int = -1;

function mouseDownHandler(event:MouseEvent):void
{
    startX = mouseX;
    startY = mouseY;
}

function mouseUpHandler(event:MouseEvent):void
{
    swype(Vector.<int> ([1,2]), Vector.<Number> ([startX,startY,mouseX,mouseY]));
}

function swype(commands:Vector.<int>, coords:Vector.<Number>):void
{
    var container:Sprite = new Sprite();
    container.graphics.lineStyle(5, 0x0066CC);
    container.graphics.drawPath(commands, coords);
    addChild( container );
    container.x = 100;
    container.y = 100;
    trace("X coordinate of blue line: ", container.x);
}

I get the output: “X coordinate of blue line: 0”

Why is it that when I am getting the coordinates from the mouse’s position on the screen and adding them to the vector, the Sprite container’s x and y coordinates default to 0,0?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T19:11:39+00:00Added an answer on May 27, 2026 at 7:11 pm

    Not sure what you are wanting to do but you may need to use the localToGlobal methods if you keep moving that _container around 😉

    This has to do with the context of where you get the property of the mouseX and mouseY.
    You have to think more about the display stack and how that relates to what the properties of mouseX and Y will give you.

    Have a try of this and shoot me any questions if you cannot understand why it works.

    package
    {
    
    import flash.display.Sprite;
    import flash.display.StageQuality;
    import flash.display.StageScaleMode;
    import flash.events.MouseEvent;
    
    public class Testing extends Sprite
    {
        private var startX:Number;
        private var startY:Number;
        private var _container:Sprite = new Sprite ();
    
        public function Testing ()
        {
            stage.quality = StageQuality.BEST;
            stage.align = "TL";
            stage.scaleMode = StageScaleMode.NO_SCALE;
    
    //        if you comment this it will stuff up the first swype
            _container.x = _container.y = 100;
    
            var cont:Sprite = new Sprite ();
            var a:Vector.<int> = Vector.<int> ( [1, 2] );
            var b:Vector.<Number> = Vector.<Number> ( [0, 0, 40, 40] );
            cont.graphics.lineStyle ( 5 , 0x442299 );
            cont.graphics.drawPath ( a , b );
            addChild ( cont );
            cont.x = 100;
            cont.y = 100;
    
            trace ( "X coordinate of purple line: " , cont.x );
            var line:Sprite = new Sprite ();
    
            addChild ( _container );
            stage.addEventListener ( MouseEvent.MOUSE_DOWN , mouseDownHandler );
    
            stage.addEventListener ( MouseEvent.MOUSE_UP , mouseUpHandler );
            var startX:int = - 1;
    
            var startY:int = - 1;
        }
    
        function mouseDownHandler ( event:MouseEvent ):void
        {
            startX = _container.mouseX;
            startY = _container.mouseY;
        }
    
        function mouseUpHandler ( event:MouseEvent ):void
        {
            swype ( Vector.<int> ( [1, 2] ) , Vector.<Number> ( [startX, startY, _container.mouseX, _container.mouseY] ) );
        }
    
    
        function swype ( commands:Vector.<int> , coords:Vector.<Number> ):void
        {
    
            _container.graphics.lineStyle ( 5 , 0x0066CC );
            _container.graphics.drawPath ( commands , coords );
            //this moves it after the property was collected for the initial swype which you don't want
            _container.x = 100;
            _container.y = 100;
    
            trace ( "X coordinate of blue line: " , _container.x );
        }
    
    }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After executing this code: var runtime = IronRuby.Ruby.CreateRuntime(); var engine = IronRuby.Ruby.CreateEngine(); var scrope
My code looks something like: $(document).ready(function(){ var cont = 0; function func1(cont) { //Some
I have the following code var section = new CustomConfigurationSection(); section.SectionInformation.Type = System.Configuration.NameValueFileSectionHandler; section.SectionInformation.SetRawXml(sectionXml);
Below is a typical OptionSet construction code: var p = new OptionSet { {
Possible Duplicate: How do I get the HMODULE for the currently executing code? I'm
I want to perform a printf() to display when the currently executing code was
Executing this code: mainLyr = [[CALayer layer] retain]; [mainLyr setFrame:CGRectMake(0.0,0.0,23.0,23.0)]; in debugger, I found
I'm wondering what happens after the constructor is done executing my code, because the
Executing the below code gives me the following exception on the last line: InvalidOperationException:
How do I prevent code from executing in the SelectedValueChange event of a combobox

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.