DECO2102

Interactive Multimedia Design

Here's the code that I typed in yesterday for updating the targetX and targetY position of our MovieClip when targetZ is changed to zoom in:

if (k == Key.PGUP) {
offSetX = (Stage.width/2 - targetX) / targetZ;
offSetY = (Stage.height/2 - targetY) / targetZ;
targetZ += 5;
targetX = Stage.width/2 - offsetX * targetZ;
targetY = Stage.height/2 - offsetY * targetZ;
}


Here's the code from my pre-lab test version that works:

if (k == Key.PGUP) {
offsetX = (Stage.width/2 - targetX) / targetZ;
offsetY = (Stage.height/2 - targetY) / targetZ;
targetZ += 5;
targetX = Stage.width/2 - offsetX * targetZ;
targetY = Stage.height/2 - offsetY * targetZ;
}


Can you spot the difference?

No?

Look closely at the spelling of "offsetX" and "offsetY" in the first piece of code...

I made the mistake of captialising the "s" in the first two lines and not in the last two lines! Unfortunately, in Actionscript this means that I'm referring to different variables (it doesn't matter how similar they look!) and even worse Actionscript 2.0 will happily allow us to make this type of silly mistake. One of the reasons that programmers like Actionscript 3.0 is that it will complain (loudly) if you try to do something like this.

Share 

Add a Comment

You need to be a member of DECO2102 to add comments!

Join this social network

About

Rob Saunders Rob Saunders created this social network on Ning.

Badge

Loading…

© 2009   Created by Rob Saunders on Ning.   Create Your Own Social Network

Badges  |  Report an Issue  |  Privacy  |  Terms of Service