I am new in as3 and flex and there is probably a dump question. The following code raises an error Access of undefined property myItem. But why? All variables are accessable and defined. Do i register this variable somewhere else? I can not just define a new variable?
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
<fx:Script>
<![CDATA[
var myList:Array = new Array();
var myItem:int = 12;
myList.push(myItem);
trace(myList);
]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
it has to be in a function in order for you to reference your declared variables. You can put
and
in a function and call that function on creationComplete or preInitialize if you want to run it right away. Or if you absolutely want to initialize myList with the value 12, just declare it like
and get rid of myItem altogether.