"Loose statements" such as
 
    fileNames.push("Adobe");
 
inside an <mx:Script> tag become loose statements inside the
autogenerated AS3 class:
 
class ...
{
   ...
   fileNames.push("Adobe");
   ...
}
 
So the question is... in AS3, when are loose statements inside a class
executed?
 
The answer is that they are executed at "class initialization" time, not
at "instance initialization" time. (Put even more geekily, they go into
the cinit(), not the init() function that the compiler produces.)
 
Class initialization time is before ANY instances have been created, so
fileNames -- being an instance var -- is null at that time.
 
Gordon Smith
Adobe Flex SDK Team

________________________________

From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of Mark Shen
Sent: Wednesday, February 06, 2008 1:22 PM
To: [email protected]
Subject: Re: [flexcoders] Array function error?



Sherif ,
 
you are right,why it only works in function.
 
Thanks
 
Mark


----- Original Message ----
From: Sherif Abdou <[EMAIL PROTECTED]>
To: [email protected]
Sent: Wednesday, February 6, 2008 4:10:44 PM
Subject: Re: [flexcoders] Array function error?



I am guessin that you are just free floating the arrFilenames.
push("abc" ); It needs to be in a function  or am i missing something?
<?xml version="1.0" encoding="utf- 8"?>

<mx:WindowedApplicat ion xmlns:mx="http://www.adobe. com/2006/ mxml"
layout="vertical" xmlns:flexlib= "flexlib.*" 

xmlns:controls= "flexlib.controls. *" xmlns:tabBarClasses
="flexlib.controls. tabBarClasses. *" creationComplete= "initApp( )">

<mx:Style source="styles.css"/>

<mx:Script>

<![CDATA[

import mx.containers. Panel;

import mx.collections. ArrayCollection;

[Bindable]

private var myArrayCollection: ArrayCollection = new ArrayCollection(
[{label:'Adobe'},{label:'Air'},{label:'Flex'}]);

public var fileNames1:Array = new Array();

/**

* I get Access Of Undefined here

*/

fileNames1.push("Adobe");

private function initApp():void{

//works here

fileNames1.push("Adobe");

}

]]>

</mx:Script>

<controls:AdvancedTa bBar dataProvider= "{myArrayCollection}"
labelField="label"/>

</mx:WindowedApplica tion>



----- Original Message ----
From: Mark Shen <markflex2007@ yahoo.com <http://yahoo.com/> >
To: [EMAIL PROTECTED] ups.com <http://ups.com/> 
Sent: Wednesday, February 6, 2008 3:03:55 PM
Subject: Re: [flexcoders] Array function error?



I update the code
   
  public var arrFilenames: Array = new Array();
   arrFilenames. push("abc" );
 
but I get same error message.
 
"Access of undefined property arrFilenames. "
 
Thanks


----- Original Message ----
From: Sherif Abdou <[EMAIL PROTECTED] com>
To: [EMAIL PROTECTED] ups.com <http://ups.com/> 
Sent: Wednesday, February 6, 2008 3:51:11 PM
Subject: Re: [flexcoders] Array function error?



why do u have "" in the array?
public var fileNames1:Array = [];
or just public var fileNames1:Array = new Array();


----- Original Message ----
From: markflex2007 <markflex2007@ yahoo.com <http://yahoo.com/> >
To: [EMAIL PROTECTED] ups.com <http://ups.com/> 
Sent: Wednesday, February 6, 2008 2:47:47 PM
Subject: [flexcoders] Array function error?



Hi,

I did a simple code

public var filenames1:Array = new Array(""); 
filenames1.push( "abc");

but I get a error 

"Access of undefined property filenames1."

I do not know what is wrong. Please give me a idea to fix it.

Thanks

Mark





________________________________

Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try
it now.
<http://us.rd.yahoo.com/evt=51733/*http://mobile.yahoo.com/;_ylt=Ahu06i6
2sR8HDtDypao8Wcj9tAcJ>  


________________________________

Never miss a thing. Make Yahoo your homepage.
<http://us.rd.yahoo.com/evt=51438/*http://www.yahoo.com/r/hs>  


________________________________

Looking for last minute shopping deals? Find them fast with Yahoo!
Search.
<http://us.rd.yahoo.com/evt=51734/*http://tools.search.yahoo.com/newsear
ch/category.php?category=shopping>  


________________________________

Looking for last minute shopping deals? Find them fast with Yahoo!
Search.
<http://us.rd.yahoo.com/evt=51734/*http://tools.search.yahoo.com/newsear
ch/category.php?category=shopping>  

 

Reply via email to