• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1742
  • Last Modified:

Flex 3.0 - How to declare an array.

Hi

A silly problem but I'm stumped.

The flex 3.0 code below throws errors at the side of each assignment.

Can anybody explain why?

Kind Regards,



<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical">

<mx:Script>
	
	<![CDATA[
	
	[Bindable]
	public var arr:Array = new Array();
	
	arr[0] = 'a';
	arr[1] = 'b';
	arr[2] = 'c';
		
	]]>
</mx:Script>
	
</mx:Application>

Open in new window

0
AdrianSmithUK
Asked:
AdrianSmithUK
  • 3
  • 2
2 Solutions
 
sajayj2009Commented:
0
 
sajayj2009Commented:
Hope the above examples help you to find why?
0
 
AdrianSmithUKAuthor Commented:
After a lot of searching I have found the answer.

The thing that threw me was that in flash CS4 the code in Example 1 worked. In flex it didn't.

The reason is that flex applications are a collection of classes. You cant write on the main timeline. I was confused. I mistakenly treated the default .mxml file as the main timeline.

The code in Example 1 doesn't work in a flash class either. It only works on the main timeline.

Example 2 shows the proper way to write the code in Flex.


//Example 1

var arr:Array = new Array();
        
arr[0] = 'a';
arr[1] = 'b';
arr[2] = 'c';
		
trace(arr[0] + arr[1] + arr[2]);

Open in new window

0
 
AdrianSmithUKAuthor Commented:
Example 2
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" creationComplete="initApp();">

<mx:Script>
        
        <![CDATA[
        
        [Bindable]
        public var arr:Array = new Array();
        
        private function initApp():void
        {
       
        	arr[0] = 'a';
        	arr[1] = 'b';
        	arr[2] = 'c';
        	
        	trace(arr[0] + arr[1] + arr[2]);
        	
        }
                
        ]]>
        
</mx:Script>
        
</mx:Application>

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now