I’m having quite some trouble to try and get an app I wrote in AS2 to AS3. The reason I need to go to AS3 is something icky, so I won’t go into detail about it.
I’ve got 90% of the application running with the new code. Now I’ve come to the point where I have to convert this code from AS2,
function setAnimation(theObject,id) { theObject.vensterid=id; theObject.onEnterFrame = function() { var myHoriTween:Tween = new Tween (this,'_x',Strong.easeOut,this._x,(130+((theObject.vensterid-frameno)*260)),1,true); } } setAnimation(venster0,0);
, to AS3. My attempt of doing this ended up like
function setAnimation(anObject,id) { var theObject = this[anObject]; theObject.vensterid=id; function slideHorizontal(event:Event) { var myTween:Tween = new Tween (theObject,'x',Strong.easeOut,this.x,(130+((theObject.vensterid-frameno)*260)),1,true); } theObject.addEventListener(Event.ENTER_FRAME,slideHorizontal); } setAnimation(venster0,0);
and gives me the following non-error (it doesn’t show as a compiler error, but as output):
TypeError: Error #1010: A term is undefined and has no properties. at sliding_windows_as3_fla::SlideMenu_1/setAnimation() at sliding_windows_as3_fla::SlideMenu_1/frame1()
I think this is very strange since it doesn’t say anything about which term (and there are quite a lot) and googling didn’t find me an explanation either.
I didn’t get the chance to test your code, because it’s difficult to set up a context for it, but my thoughts would be:
function setAnimation(anObject:Object,id:uint):void. It’s at least good practice.var theObject = this[anObject];is completely unnecessary if your variableanObjectis an object. I thinkvar theObject = this[anObject];doesn’t work,theObjectends up being null and that’s why you get your error. If you have declared a variable called venster0, that is the instance of a class that extends Object, then you can pass the reference to it without any other trouble.theObject.vensterid=id;might not work. The class that theObject instances must have the ‘vensterid’ property, or you will get `1119: Access of possibly undefined property vensterid through a reference with static type …