-
[RESOLVED] Variables and functions
Hey guys and gals,
This is a newbie question, but I have to ask it. Let's say you declare a variable and want to re-use the variable and update its contents inside a function, why doesn't this work?
Example only:
Code:
var myNewArray:Object = new Object();
myNewArray.list = new Array();
function something() {
// looping iteration of 'i'
myNewArray.list[i] = "something";
}
. . .
function useit() {
// yet another looping iteration of 'i'
trace(myNewArray.list[i]);
}
Why is it that when the useit function is called, the traces all produce "undefined"?
Thanks in advance.
-
rabid_Delineator
In what context are you using this code ? It could be a scope problem. Where is ' i ' being defined ?
-
Well, the "i" was there as a representation only. I should have posted clearer code, sorry about that.
Here's a sample:
Code:
var playlistData:Object = new Object();
playlistData.list = new Array();
// il is defined elsewhere in the code from imported XML, didn't think it wise to post the entirety of the code for this example. il contains il.title and il.description
function getPlaylist() {
for (var i=0; i<il.length(); i++) {
playlistData.list[i] = il.title[i];
trace(playlistData.list[i]+"---");
}
}
function useit() {
for (var i=0; i<playlistData.list.length(); i++) {
trace(playlistData.list[i]+"+++");
}
}
When the function getPlaylist() is called, the trace shows the playlist files, one after another, like:
file1.flv---
file2.flv---
file3.flv---
However, later when the function useit() is called, the traces say:
undefined+++
undefined+++
undefined+++
I have seen many references to getChild(). I think that this has something to do with it, but I've not found a relevant example to judge from and, being new to flash as a whole, the Adobe.com snippets is a bit over my head.
Hope this clarifies the problem, and thanks.
Last edited by Wraithmanilian; 01-21-2010 at 02:45 PM.
Reason: To avoid confusion, clarified one function.
-
Unless you change playlistData, the stuff you put in there should still be there later. Do you perhaps re-set playlistData, perhaps by returning to the frame in which you declare it as a new array?
-
Resolved
Geez, do I REALLY feel like a n00b now...
I have now discovered that variables are case-sensitive, and my awkward variable naming abilities caused confusion in my code.
Fellow n00bs, let my blunderings serve as a lesson for the rest of you.
AttackRabbit and 5TonsOfFlax, thanks for the patience you have to have for us newcomers to flash.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|