Below is a comparison of the final code used by JavaScript, jQuery, and ActionScript to animate the box across the screen and back again repeatedly.
While the code syntax is different, notice all of the OOP code has the following things in common:
NOTE: Notice the the JavaScript and jQuery are almost the same except for a few minor differences:
NOTE: It is no surprise that jQuery uses similar code as JavaScript because jQuery IS one of many JavaScript Class Libraries. A few include:
For a complete list of JavaScript libraries and other JavaScript resources, go to List of JavaScript libraries on the Wikipedia web site.
<script>
window.onload = function()
{
var currentXPos = 0;
var intervalHandler = setInterval(animateBox,50);
var myBoxObject = document.getElementById("myBox").style
var windowSize = window.innerWidth;
function animateBox()
{
currentXPos += 10;
if(currentXPos > windowSize)
{
currentXPos = 0;
}
else
{
myBoxObject.left = currentXPos + "px";
};
}; //End of animateBox function
}; //End of onLoad function
</script>
<script>
$(document).ready(function(e)
{
var currentXPos = 0;
var intervalHandler = setInterval(animateBox,50);
var windowSize = window.innerWidth;
function animateBox()
{
currentXPos += 10;
if(currentXPos > windowSize)
{
currentXPos = 0;
}
else
{
$("#myBox").css("left", currentXPos);
};
}; //End of animateBox function
}); //End of $(document).ready
</script>
myBox.addEventListener(Event.ENTER_FRAME, moveBox) function moveBox(eventObject:Event):void { /*If myBox x position is larger than the stage
width, set its x position back to zero.*/ if (myBox.x > stage.stageWidth) { //myBox x position to zero. myBox.x = 0; } else { //Else, continue to move box by 10px repeatedly myBox.x += 10; } }