PDA

View Full Version : [AS3] tileList and "value is not a function"


moglie
07-16-2008, 04:59 AM
I have a listener set up on each item of a tileList myTileList.addEventListener(ListEvent.ITEM_ROLL_OV ER, over);

and I'm trying to call functions (ie. function0, function1) from the over function
var somevar:Number = evt.index
this["function" + somevar]();
but i get a "value is not a function" error. Used to do stuff like this in AS2 with eval.

senocular
07-16-2008, 12:38 PM
what happens when you trace this["function" + somevar]?

moglie
07-17-2008, 10:48 AM
ok this code trace(["function" + somevar]); will trace function0, function1 etc.

but if i use trace(this["function" + somevar]) it comes back undefined

senocular
07-17-2008, 03:20 PM
Then you haven't defined the actual function0 function1 ... functions you want to call, or they're defined somewhere other than in 'this'

moglie
07-18-2008, 12:53 AM
where would "this" be pointing to? if i just call a specific function like function0(), it can trigger the function.

function over(evt:ListEvent):void {
//var somevar = evt.index;
//this["function" + somevar]();
function0();

}

senocular
07-18-2008, 01:12 AM
That should work. If you can call a function there (and you're not doing anything funky like nesting functions) it should work.

moglie
07-18-2008, 01:21 AM
Nothing funky. I guess it has something to do with the tilelist component? I've tried everything I could think of.

the entire error is this

TypeError: Error #1006: value is not a function.
at MethodInfo-357()
at flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunctio n()
at flash.events::EventDispatcher/dispatchEvent()
at fl.controls::SelectableList/fl.controls:SelectableList::handleCellRendererMous eEvent()