Web Animation Question

Out of context: Reply #2

  • Started
  • Last post
  • 13 Responses
  • monNom0

    Yes, Javascript is really similar to AS2 in that it uses a dot syntax to access properties of objects. So the equivalent of "_root" might be "window", or "document", and they have a bunch of methods you can use to do stuff with.

    If you're wondering about methods on a specific object, you can use the console in Chrome by hitting the F12 key when on a webpage. This gives you an interactive command line that you can used to manipulate the webpage, test scripts, and find out all sorts of things about what's going on behind the scenes of your browser. It's like being able to change your actionscript in a running flash movie and seeing what happens - way cooler than constantly recompiling.

    In the console, if you type "window." it will list all the available properties and methods available for the window object. If you type 'document." you will get all the properties and methods for the document object, which is a child of window but you can access it directly because you are operating within the window's scope.

    To access properties of some things (like mouse position), you need to attach an event listener that fires when the mouse or whatever changes.

    you would do that as follows:

    var mouseX; //create a variable to hold last mouse position

    window.onmousemove = function(e){ //attach listener to 'mousemove' event
    mouseX = e.offsetX; //set mouseX variable with mouse position;
    }

    //mouseX will now have the position of the mouse when it last moved.

    There's tons to learn. I'd suggest doing some beginner tutorials or getting a book to learn the ropes. If you understood moving things around in AS by adjusting X/Y values, javascript is very similar.

    • The F12 didn't work for me. It's the same as right click and inspect element?pinkfloyd
    • Yes. The command line is in console.dorf

View thread