PDA

View Full Version : AS3 in Flex


scorpion9
11-23-2010, 04:25 PM
Hi


im quite familiar with as3 in flash CS. Recently i got a task to edit/write a source for flex app.

i read from Adobes site an interesting line that said, flex uses mxml and/or as3.
does that OR mean i could write flex in pure AS3?

also, are the flash API elements available in flex as well. I mean MovieClips, URLRequests etc etc, or does flex have its own API.




thanks for ur time

TomMalufe
11-23-2010, 04:35 PM
Flex includes all the same AS3 libraries you know from Flash IDE, but it contains very different components.

You can write a Flex app almost entirely in AS3, but you are going to need your main MXML file that includes that AS file.

I would watch the intro to Flex videos on gotoandlearn.com if I were you. They don't take too long and it will give you a pretty good idea of what Flex is.

In simple terms... Flex is Flash within a heavy framework. It's the same thing plus a bunch more.

drkstr
11-23-2010, 04:59 PM
MXML is Actionscript in a way. It's basically just short cut notation for defining display layouts, bindings, and other such things that are easier to define in a markup language. All of that MXML get's converted into Actionscript before it's compiled, so yes it is possible to write your entire project in AS. But why would you want to? MXML is actually quite nice once you get used to what it's good at, and what it's not.

scorpion9
11-23-2010, 07:23 PM
atm, i havent programmed anything in flex (first encountered it 5 hours ago). Ive used to the code flow of as3, all the nice oop etc + timeline.


so here are few general questions about flex

what is the main stage/timeline in flex.
is there a display list as it is in flash....e.g are the objects created/layered in the order of code appearance. eg. stuff defined between tags at the beginning of the file are placed at the bottom of the display list, and as the code moves along rest of the stuff is added on top.

does objects/tags nesting determine their placement in display list+parent child relationship.

do the width and height in a markup like this
<mx:Object width="400" height="400" >

refer to DisplayObject.width/height in flash.

and lastly, how do events propagate in flex. ive seen in tutorials that flex uses listeners like javascript eg onclick=function().
is there a way to listen events by addEventListener()


anyway this whole flex structure and oop seems very odd atm. cant see much benefit of using it. the only thing atm i could think if is the use of % in defining objects width and placement on the screen.

drkstr
11-23-2010, 09:58 PM
what is the main stage/timeline in flex.
is there a display list as it is in flash....e.g are the objects created/layered in the order of code appearance. eg. stuff defined between tags at the beginning of the file are placed at the bottom of the display list, and as the code moves along rest of the stuff is added on top.
Yes.

does objects/tags nesting determine their placement in display list+parent child relationship.
Yes.

do the width and height in a markup like this
<mx:Object width="400" height="400" >

refer to DisplayObject.width/height in flash.
Well yes and no. All you are doing in your example is instantiating an Object and giving it a width and height.

The following do the exact same thing in MXML / AS:

<mx:Object id="myObject" width="400" height="400" />
public class MyClass()
{
function MyClass()
{
this.myObject = {width:400, height:400};
}

public var myObject:Object;
}

When you add a tag to MXML you are telling it to instantiate whatever Actionscript class that tag represents. You can then use the attributes to set initial class properties, add event handlers, etc. If the class happens to be a DisplayObject, it will add it to the display list of it's parent tag. So yes, if your tag is a DisplayObject, than you are assigning the width/height of the DisplayObject.

and lastly, how do events propagate in flex. ive seen in tutorials that flex uses listeners like javascript eg onclick=function().
is there a way to listen events by addEventListener()

Again, same things:
<fx:Script>
<![CDATA[
private function changeHandler(event:Event):void { }

]]>
</fx:Script>
<s:TextInput id="textInput" change="changeHandler(event)" />
this.textInput.addEventListener(Event.Chage, changeHandler);

...it's a matter of personal preference.

anyway this whole flex structure and oop seems very odd atm. cant see much benefit of using it. the only thing atm i could think if is the use of % in defining objects width and placement on the screen.

It helps if you think of every MXML file as an Actionscript class. Any code you add in the script tag is just like you were to add it to a Class. Any MXML tags within that file is just a shortcut notation to instantiate other classes, assign initial properties, add event handlers, assign styles, etc.

All of the same OOP rules apply. Just like in AS, it's up to the programmer to follow OOP conventions or not.

scorpion9
11-24-2010, 02:08 PM
thanks for the replies.
that cleared out some stuff.


now all i need is a programming environment.

whats the best free program for that?

i have eclipse installed for java and other stuff. ive read that adobe has a plugin for that. but it isnt free as far as i know.

is there something thats free.

drkstr
11-24-2010, 11:50 PM
The eclipse plugin is free, I thought. There is FlashDevelop too.

scorpion9
11-25-2010, 03:38 PM
thanks for the replies.

i decided to go with the 60 day trial- plugin.