ActionScript 3.0, like many other programming languages, contains a number of basic data types commonly known as primitives. ActionScript 3.0 contains five primitive data types, which is far less than other languages like .NET or Java.
|
Data Type |
Function |
|
String |
A character or series of characters |
|
Boolean |
A value that is either true or false |
|
int |
Positive or negative whole numbers |
|
uint |
Positive whole numbers |
|
Number |
Positive and negative whole and real numbers |
Strings
Strings are a very important data type in programming languages that support them. For instance, string value can represent a sentence, a phrase, a word, a letter, or a directory location in an application, all of which are vital to many applications developed.
In the above example, when the value of String str is traced, the output will read This is a string.
Booleans
Booleans are a great way to evaluate whether a statement in code is true or not. A developer can program an application to do something whether or not a statement is true. For example:
The above code will set the Boolean value to false because the value of five is not greater than 6. After that, the second if statement checks to see whether or not the Boolean’s value is set to true or false. Seeing that the Boolean is false, it will return the trace statement in the else statement.
Integers, Unsigned Integers, and Numbers
Flash comes equipped with a small set of numeric data types that allow the flexibility for almost any developer. If a variable needs to store positive whole numbers, then one would use an unsigned integer to store the values. For whole numbers that are positive and negative, using an integer or Number would be ideal. The difference between integers and Numbers is that Numbers can also store real number values whereas integers only store whole numbers. Also, Number data types can store a headache inducing amount of data compared to integers and unsigned integers. Here’s a breakdown of numeric data type values in Flash
|
Data Type |
Minimum Value |
Maximum Value |
|
integer |
-2,147,483,648 |
2,147,483,647 |
|
unsigned integer |
0 |
4,294,967,295 |
|
Number |
4.9406564584124654e-324 |
1.79769313486231e+308 |
As you can see, Numbers are great for not only storing real numbers, but also for REALLY HUGE values. Remember, when programming, choose the numeric data type that’s the most ideal for the situation. For example, if you plan on storing numeric whole number values (positive or negative) that aren’t going to contain decimals, then you’re probably best off using integers. Any time decimals or real numbers in general are involved, use Numbers. When you are developing any type of application or animation, you have to keep system resources in mind to the best of your ability. By doing so, this ensures optimal performance on most computers.
As always, source code is available here.
When creating Adobe AIR applications, one of the more important (and easily overlooked) things that people like is System Tray Icons (Windows) or Dock Icons (Mac) for simple user commands such as changing preferences in the application or exiting entirely.
One of the many advantages of using Adobe AIR is the cross platform support, but how does an application know if it’s running on a Windows or Mac platform in order to accommodate a System Tray or Dock icon for each respective environment? The development team behind Adobe AIR have conquered this problem for developers. Within the NativeApplication Class there’s two boolean properties to resolve this problem. The boolean property supportsDockIcon is used to detect whether or not the native operating system supports Dock Icons (Mac) while the other, supportsSystemTrayIcon, is used for Windows based systems.
What can be done, is that an if-else if statement can be written to compensate for both environments. In most cases, you’d want the logic in both parts of the statement to be similar, with the exception of the size of the icon. This way, continuity and consistency is maintained between both platforms.
As you can see, the idea is pretty simple. If the boolean returns true, then the respective statement will execute. If you would like this code expanded on, please let me know. I’d be more than happy to either update the post or write a follow up post on this topic.
Happy coding!
One of the most common (and least favorite) errors I see classmates encounter when they initially start out using Adobe Flex technologies is error #2148. Here is the latest run-time error read out I receive:
SecurityError: Error #2148: SWF file file:///C:/Documents and Settings/Brett/Adobe Flash Builder Beta 2/Hello World Flex4/bin-debug/main.swf cannot access local resource file:///C:/Documents and Settings/Brett/Adobe Flash Builder Beta 2/Hello World Flex4/bin-debug/textLayout_4.0.0.10485.swf. Only local-with-filesystem and trusted local SWF files may access local resources.
From the looks of it, that’s a lot to take in. To simplify, what’s happening is that when the application is compiled or tested, it is being accessed by the bin folder, which is a special directory in this instance. One of the first things I do is I access the Global Security Settings Panel to make sure that I have added my work folders to the Always Trust list.
You’ll notice that both my Flex 3 and Flash Builder workspaces have been added to the list. You can add yours by selecting the appropriate option under the Edit locations… dropdown menu.
If you are looking for an on the fly, or project specific alternative to solving this issue is to add the argument -use-network=false to the compiler properties. This can be done by going under Project > Properties > Flex Compiler
I usually don’t recommend this latter option, but if for some reason security settings are really tight on your development machine and you cannot get the previous method to work, this will result in a quick to your problem.
Comments and questions are always welcome.
Happy coding!
Adobe Flex is a powerful and user friendly platform for developing and deploying rich internet applications (RIAs) for Adobe’s overarching Flash platform. One of the strengths of Flex is its ability to integrate with many web services such as ColdFusion, J2EE, and LiveCycle Data Services. For more information, please visit Adobe’s Flex 3 site. If you have any questions about Flex, please feel free to contact me as I would like to focus mainly on the code for the Hello World application in this post.
As you can see, there are actually two examples of a basic Hello World application in the above Flex project. That’s because I created the example using two different approaches of how Flex handles events within code. Below is a screenshot for the source code. You can download the source here.
EDIT: For some reason, the plugin I use adds an odd string in the helloFunction() Alert text. Ignore the string of text http://brettwidmann.com.nyud.net/2010/03/ as this could be a conflict with my CDN.
The most important concepts to understand in this example is the relationship between Flex’s MXML markup and ActionScript 3.0. As you can see, the first example fires an Alert window event using the click attribute, which also contains the formatting for the window. The second example demonstrates how one would code the same thing using AS3 event handlers. You’ll notice the second approach is more verbose than the first, but keeps MXML and AS3 separate from each other.
Finally, notice that in the Application tag, I have the creationComplete attribute firing a function called “mainFunction”. The purpose of this function is to create the event listener on the second button, so that when the button is clicked, the listener tells the button to fire the function called “helloFunction”.
If you have any questions or comments, please feel free to leave them on here.
EDIT: For a Flash Builder version of this post, click here.
The following tutorial demonstrates how events can be handled in Adobe Flex Builder 3 using an event listener or listening through the MXML code. When finished with the code, you should see an Alert window pop up, and two events being fired simultaneously when a button is clicked. You’ll also notice an event being fired to clear the text when a button is clicked.
Unfortunately, I cannot give out the source code for this project, as it is intended to be a tutorial for students at UWSP.
Happy coding!
To view a higher resolution video, click here