mouse X/Y coordinates: Javascript to Actionscript

  • sprouletopia
  • Born
  • Born
  • sprouletopia
  • Posts: 3

Post 3+ Months Ago

Hello Everyone,

I am taking a value from javascript and want to use it in actionscript. I know how to pass the value (mouse X/Y coordinates) in to a dynamic text box but am stumped when it comes to reading that value when it changes and then using the new value in actionscript.

I would like to move an object’s (“ a car”) when the “X” value changes.

So I have Source files.
1. One is of a car that will move back and forth with the mouse, but only if the cursor is over the SWF.Example

2. The second is html with JavaScript that will read in x/y and display it. Example

3. The third is an example my attempt of getting the X in to a dynamic text box. Now I can do that but how do I reference the value of that text box and use it again in the Actionscript. Example

Link for source files

Can someone please take a look and help me with this?

thank you,
Jason
  • IceCold
  • Guru
  • Guru
  • User avatar
  • Posts: 1254
  • Loc: Ro

Post 3+ Months Ago

1) when use URL=some link, dont use "some link"
use simply: [URL=http://some ...
2) why you need the x, y coordinates to be passed from javascript into flash?
if you tell me the end point of your work, then there might be other ways to do it, so stop asking for what you think you need and better ask for what you want to achieve.
  • sprouletopia
  • Born
  • Born
  • sprouletopia
  • Posts: 3

Post 3+ Months Ago

Well what i need to happen is :

the car has to follow the cursor whether the cursor is on the movie or on the browser window. it also needs to use as little javascript as possible.

thank you,

Jason
  • IceCold
  • Guru
  • Guru
  • User avatar
  • Posts: 1254
  • Loc: Ro

Post 3+ Months Ago

well then, i see that you know how to move the car to follow the cursor when it`s in the movie.
next step, when it`s in the browser, i see that you have:
document.onmousemove = getXY;
so .. in getXY function, after you get the x and y of the mouse, send them to flash. This way, when mouse is moved, the new coordinates will be sent. I dont know how fast the new values will be updated, but i dont think will take too much time.
just test and see
  • sprouletopia
  • Born
  • Born
  • sprouletopia
  • Posts: 3

Post 3+ Months Ago

well how i get the x in now for the text box is:
flashMovie.SetVariable("test", nx);

i have got the car to move through javascript with:
flashMovie.SetVariable("mycar._x", nx);

but if i do it that way then all if statments and control for the cars X have to be done in javascript (I think). I can do it that way. the meat of the code has to be after it hits actionscript.
  • IceCold
  • Guru
  • Guru
  • User avatar
  • Posts: 1254
  • Loc: Ro

Post 3+ Months Ago

no no no no no
in actionscript you would have something like:
Code: [ Select ]
onEnterFrame = function()
{
    tweenEaseIn(crtMouseXPosition);
}

onMouseMove = function()
{
  crtMouseXPosition = this._xmouse;
}
  1. onEnterFrame = function()
  2. {
  3.     tweenEaseIn(crtMouseXPosition);
  4. }
  5. onMouseMove = function()
  6. {
  7.   crtMouseXPosition = this._xmouse;
  8. }


then, in javascript, you just set the variable crtMouseXPosition.
and ... ye, that`s all.

Post Information

  • Total Posts in this topic: 6 posts
  • Users browsing this forum: No registered users and 5 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.