How to Remove Document Management Hurdles with X-Docs?
Flex Book Club Chapter 5
1. Flex Book Club: Chapter 5 Learning The Basics of Scripting Part 1
2.
3.
4.
5.
6.
7.
8.
9.
10.
11. Question: MXML Yeah, yeah yeah…we get it. “They are the same thing.” But I have a question…If MXML is so much more succinct, so much easier to write, and in general really hella friggin AWESOME. Why would anyone ever write a line of ActionScript?
12. Answer: ActionScript MXML is Great for things like laying out what your app is going to look like. However, when it comes time to take action and DO SOMETHING, MXML looks a lot like the Government in the middle of a credit crisis, Big Talk, No ACTION. That is why they call is Action Script afterall…
13. Getting into ActionScript with Variables ActionScript We’ve already seen examples of variables all over the place used to store information… public var userName = “Tom” This is the keyword we use to declare variables This is the variable’s name This is it’s value
14. Variable Data Types ActionScript You might have noticed in the past we did something like… public var userName:String = “Tom” This is the data type of the variable we are declaring is a String That’s just a way of saying what kind of data the variable holds See page 54 in “Learning Flex 3” for a reference to all of the fundamental data types.
15. Functions ActionScript Functions, are pieces of code we create to re-use code, so we don’t have to write it over again. <mx:Script> <![CDATA[ function createUser(){ } ]] </mx:Script> If we put code between the brackets that creates a new user, we can re-use that code by calling the method.
16. Function Parameters ActionScript We can also supply our functions with data to make them more re-usable <mx:Script> <![CDATA[ function createUser(name){ } ]] </mx:Script> In this case we supply the function with a name to assign to a new user.
17. Function Parameters ActionScript Furthermore, we can give our function parameters some default values, and give those parameters data types. function createUser(name:String = “Sam”){ } In this case we say that the parameter has to be a String. Also if there is no parameter supplied, name will be given the value of “Sam”
18.
19. Objects group together variables and functions. I’m a frog object ActionScript We can make anything an object. Cars, People, Buttons, even frogs! var frog:Object = new Object(); frog.color = “green” ; frog.name = “Kermit De Frog” ; We’ll get to grouping in functions later.
20. A Class is a Blueprint for an object. I’m a frog class ActionScript Think of classes as a way to make objects (or structured data) re-usable Public class Frog { var name:String; var color:uint; … }
21. We can even put objects within classes. ActionScript Classes can help us, especially with code completion in the Flex IDE! Public class Pond { var frog:Frog; var rock:Rock; var name:String; }