views:

326

answers:

2

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.

A: 

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:

  1. You should declare the parameter types: function setAnimation(anObject:Object,id:uint):void. It's at least good practice.
  2. var theObject = this[anObject]; is completely unnecessary if your variable anObject is an object. I think var theObject = this[anObject]; doesn't work, theObject ends 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.
  3. Depending on the object you work with, 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 ...
evilpenguin
as an answer to 2: venster0 is a movieclip with that instance name.and to 3: it worked in as2. All I'm doing is creating a variable in a existing movieclip.
xaddict
2. then your code should work as is, if you define the parameter anObject:MovieClip or Object in the function header3. you can't do that in AS3. your MovieClip class must have that property. If not, your venster variable should subclass another class
evilpenguin
A: 

I think your problem here is following string:

var theObject = this[anObject];

Just replace it with

var theObject = anObject;

I hope that's what you need.

Alternatively instead of

setAnimation(venster0,0);

you could pass an instance name (i.e. String):

setAnimation("venster0",0);

That will work because by this['propertyname'] you are actually accessing Object's property by name.

dragonfly
And to declare everything properly in AS3 is a good practice. I mean declaring variable and parameter types everywhere.
dragonfly