Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

ks2000

macrumors newbie
Original poster
Oct 6, 2010
2
0
I made an interactive atlas of health facilities. Each facility is displayed with a symbol on the map. when the user rolls over the symbol it magnifies it by 2. when the user clicks on the symbol is remains magnified and information about that facility pops up. There are two functions used for the magnification (zoomIn and zoomOut) as follows.

PHP:
function zoomIn(evt) {
//trace(evt.target.instanceName);
//this.nurseArray[53].scaleX=3;
this[whichDot+"Array"][evt.target.instanceName.slice(5,evt.target.instanc eName.length)].scaleX=2;
this[whichDot+"Array"][evt.target.instanceName.slice(5,evt.target.instanc eName.length)].scaleY=2;
}

function zoomOut(evt) {
this[whichDot+"Array"][evt.target.instanceName.slice(5,evt.target.instanc eName.length)].scaleX=1;
this[whichDot+"Array"][evt.target.instanceName.slice(5,evt.target.instanc eName.length)].scaleY=1;
}


they work great except for when the user clicks a new tab in the Atlas (which is actually a movie clip containing the information of the tab) until which the zoom functions stop working and I get an error message about a term being undefined (zoomIn and zoomOut)

the zoom functions are defined on the main Timeline and work great, i just don't understand why they stop working in the movie clip?


you can see the application at http://health.geo.msu.edu/atlas.html the problem happens when you click on the "view by service" tab and check the box for nursing homes for psych beds and then click a symbol on the map..the symbol stays magnified and stuck in the "up" state, which should not happen. The symbols behave great on the "view by facility" tab.

i can provide more code to this as well.

if the functions exist, why would they only work part of time?

any insight into this problem would be greatly appreciated.

thanks,
K
 
i have to admit, when i first saw that you were posting about some non xhtml type thing for the web i thought "oh no this is going to be bad" but it is actually really cool. i would love to see the code behind it! though i've never used action script before, i wonder if you are programming with objects and if so, perhaps if a function is only working part time, then somewhere there is an issue with inheritance.
 
Impossible to say without the source code, but a really common problem.

One problem is that you are using AS3, but are still coding with an AS2 mindset. I know that may not be the most helpful advice, but it is one reason you are getting these types of errors.

Developing an app like this would be much easier if you got rid of things like sprite naming, and moved to a more object oriented approach (i.e. objects stored in arrays)

This would allow you to shift the responsibility of the event listeners into the objects themselves... you will have less opportunity of events trying to talk to stuff that is either not there or out of scope.
 
"slice" is destructive, methinks

lucidmedia is correct in that you need to become a different kind of programmer to successfully use AS3.

But, to your problem at hand, I believe it is related to your use of slice(), which is literally changing the "internal" name of the sprite, thus making it inaccessible as originally named. slice() is destructive, so use substr() or substring() instead to get the result you're looking for.

Or, you could use an object lookup table, such as

...
var nurseByDotHash:Object = {};
var dot: Dot = new Dot();
var nurse:Nurse = new Nurse();
nurseByDotHash[ dot ] = nurse; // obviously you could loop through this with an array of dots and nurses
...
function zoom( e:Event ) {
var nurse:Nurse = nurseByDotHash[ e.target ]; // depending on your env, you may need to do an "... as Nurse" here
...
}
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.