I'm new to Actionscript 3.0 (and Flash), and am currently having a problem with a MouseEvent function in my first movie.
I'm trying to make the object 'mainVersionInfo' change colour when moused over. Instead of using colorTransform, I'm using labels as shown in the snippets of code below.
function menu():void{ mainVersionInfo.addEventListener(MouseEvent.MOUSE_OVER,glowInfo); } function glowInfo(Event:MouseEvent):void{ mainVersionInfo.gotoAndStop("mouseOff" }
Upon testing the movie, I receive the following compiler error:
1120: Access of undefined property mainVersionInfo.
I'm able to fix this error by moving the 'glowinfo' function inside the 'menu', but I don't think this is the best solution. Can anybody explain to me why this error is occuring, and what the 'roper' way to fix it would be?
hmmm - well it should be ok if you do have an instance name of mainVersionInfo on the stage. however, there is one issue in the handler declaration, you should try not to use 'reserved names' as your property names, ie. Event:MouseEvent - try it with simply, e:MouseEvent - as 'Event' is a system package
but additionally, what your description leads me to believe is that you have the instance 'mainVersionInfo' declared as a property (var) within the menu() method? this would mean that the instance is 'local' to the scope of the method and doesn't exist outside that scope - which would cause the 1120
additionally another way to target the instance within a handler, is to use: e.currentTarget - provided that 'e' is the property name of the event argument
ok - simply move the declaration outside the method so that it looks more like this:
var mainVersionInfo:MovieClip;
function menu():void{ mainVersionInfo = new MainVersionInfo(); mainVersionInfo.addEventListener(MouseEvent.MOUSE_OVER, glowInfo); addChild( mainVersionInfo ); }
function glowInfo(Event:MouseEvent):void{ e.currentTarget.gotoAndStop("mouseOff" }
BUT there are several factors here that i am guessing at since i don't know the entire structure of your code and timeline - i would assume that you are propagating the instance within the menu() method when called and then bringing it to the stage within the method - IF this is the case then it explains the 1120
however, if you have an instance that is 'laced' on the stage that has an instance name of 'mainVersionInfo' - then it is a different issue - which probably means that the instance is not 'instantiated' at the time of the menu() method call
but you have said that it does function when placed inside the method, so i would assume that the property is being constructed within that scope - but again, a lot of speculation here not knowing the entire structure of your app - and i suspect, more code in the menu() method not shown above
but, i'm a bit confused - you've said that it works when placing the glowInfo() method inside the menu() method (this is called nesting) - which is not the solution i have above.