views:

47

answers:

1

Hello,

I have a var to get thumbnails width, and it's set at the beggining of my class code.

var thumbW:Number;

Then I update that var inside a function that updades with stage resize.

function x(){
    var thumbW:thumbnails.width;
    //tracing thumbW here returns the updated value. Perfect!
}

Then I try to get the thumbW value inside a function that scrolls the thumbnails

function y(){
    trace(thumbW);
}

But, in y function, it only returns NaN, aka Not a Number, telling me that the value for that variable is not set nor updated.

I'm wondering why this is happening? Why I can't update this var? How can it be done?

A: 

There is something wrong in your function x.

If you want to access the global variable thumbW, you should direct use it like thumbW = 123. Using var will declare another local variable inside the function.

And, why you put the flag thumbnails.width? There should be compiler error! Typo?

The whole code for function x should be:

function x():void {
    thumbW = thumbnails.width;
}

BTW, you should learn more about variable scope. There is an article from adobe help.

Andy Li
Thak you, Andy Li! It was a primitive mistake, but sometimes we need a cleared mind to escape from this kind of trap. Thak you, again!!
Fabio Montone
also, don't have a function named x() that's going to conflict with tons of stuff!
grapefrukt