Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Flex 3.0 - How to declare an array.

Posted on 2009-12-17
5
Medium Priority
?
1,738 Views
Last Modified: 2013-11-11
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
Comment
Question by:AdrianSmithUK
  • 3
  • 2
5 Comments
 
LVL 12

Assisted Solution

by:sajayj2009
sajayj2009 earned 500 total points
ID: 26071309
0
 
LVL 12

Expert Comment

by:sajayj2009
ID: 26071316
0
 
LVL 12

Expert Comment

by:sajayj2009
ID: 26071322
Hope the above examples help you to find why?
0
 

Accepted Solution

by:
AdrianSmithUK earned 0 total points
ID: 26082121
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
 

Author Comment

by:AdrianSmithUK
ID: 26082131
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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sometimes you know that one object has a specific child in it, but you can't find the child. This happened to me when I was trying to code some actionScript to make a toolbar work with its embedded buttons.  My partner had created the toolbar usi…
While working over numerous projects I often had the requirement for doing a screen capture in AS3.0. Unfortunately I found no "ready made" solutions in google search that suited my requirements. But I did come across some great resources which help…
In this tutorial viewers will learn how to create a basic shape tween animation in Flash including shape hints for smooth animation Open a new document in Flash: Draw a shape: Select another frame (how long you want the tween to be): Right click and…
This Micro Tutorial will teach to how to utilize bit rate in Adobe Flash Media Live Encoder.
Suggested Courses
Course of the Month10 days, left to enroll

569 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question