Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > Flex > Flex 2, 3 & 4

Reply
 
Thread Tools Rate Thread Display Modes
Old 04-22-2009, 06:15 PM   #1
scripter73
Registered User
 
Join Date: Apr 2009
Posts: 10
Default Understanding the Processing Order of a MXML File

Hi,

I hope I'm posting this in the right location. I'm a newbie to Flex, MXML and ActionScript.

I'm walking a book now on the Flex Builder framework. As I go through examples, I run the examples which are comprised of MXML and ActionScript.

I'm sort of very methodical (ColdFusion background), and as I'm looking through one example in particular, I'd like to know what comes first, etc.

I understand that when I compile my MXML code, everything is converted to ActionScript, but I'm having a hard time walking through this code. (Hopefully, when I get to the debugging portion of my book, this will be easier.)

I've posted the latest example I'm working on here. If it wouldn't be too much trouble, could someone please step through it and tell me the "order" of the process? For example, are the imports done first, or is the Panel and PopUpButton processed first.


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

<mx:Script>
<![CDATA[

import mx.events.*;
import mx.controls.Menu;

public var menuItems:Object=
[
{label:'One'},
{label:'Two'},
{label:'Three'}
];

public var thisMenu:Menu = Menu.createMenu(null, menuItems, false);

public function handleItemClick(event:MenuEvent):void{
menuBtn.label = event.label; //all this does is move the
//mx.controls.Alert.show("Value picked was: " + event.label);
}
]]>
</mx:Script>

<mx:Panel width="100" height="100">

<mx:PopUpButton id="menuBtn" creationComplete="thisMenu.addEventListener('itemC lick', handleItemClick)" popUp="{thisMenu}" />

</mx:Panel>
</mx:Application>

--------------------

Thanks in advance!
scripter73
scripter73 is offline   Reply With Quote
Old 04-22-2009, 06:31 PM   #2
wvxvw
Holosuit User
 
wvxvw's Avatar
 
Join Date: Oct 2006
Location: Tel Aviv
Posts: 4,301
Send a message via ICQ to wvxvw
Default

For to understand what happens, add -keep additional compiler argument (this will save the generated files into directory where your document class / application class is.
The files of interest would be those which have a name of this pattern:
MyMXMLComponent.as-generated.
As to the order of execution:
// Assuming we've done all the SystemManager
// stuff and advanced to the frame #2, which your code actually is
1. Call mixins (thise are static functions called before Application is instantiated.
2. Call the top-level document constructor.
3. Call recursively initiated(document, id) on the top-level container, container's children, grand children etc.
4. Do layered instantiation and layouting of all the visual components which are children of top-level container.
5. Dispatch applicationComplete event and wait for further instructions
Imports aren't called, they are used by compiler as a "lazy" data base for information on how to compile the class. What this means is: when the class is compiled, the compiler, once it encounters unknown reference checks local skope, class skope, package skope, and then if the reference is not found will go to the imports and try to trace the imported source.
__________________
The .NET open source editor for Flash and web developers
*This would be my contribution to the project*
couchsurfing if you need it
wvxvw is offline   Reply With Quote
Old 04-22-2009, 07:27 PM   #3
scripter73
Registered User
 
Join Date: Apr 2009
Posts: 10
Default Additional Question regarding the Processing Order

Hi wvxvw,

Thanks for that overview. I think it's a little over my head right now until I read some more.

How about this? I was looking for something more along the lines of:
1. Panel gets created.
2. PopUpButton named "menuBtn" is created.
3. The event "creationComplete" calls an event listener function for variable thisMenu that is supposed to listen for when thisMenu (the new menu created) has an itemClicked on it.
3a. Once the event occurs, then the handleItemClick() runs, which accepts an event and changes the PopUpButton label to the item that was selected.
4. The PopUpButton is populated with the values assigned to it.

I'm just not sure what the correct order is.

Are the variables menuItems, and thisMenu created behind the scenes before any of the MXML is processed? Then that way once you get to the MXML, you already have these items available?

Sorry to dumb it down so much, but I'm trying to understand each example and build on that foundation.

Thanks!
scripter73 is offline   Reply With Quote
Old 04-22-2009, 08:08 PM   #4
wvxvw
Holosuit User
 
wvxvw's Avatar
 
Join Date: Oct 2006
Location: Tel Aviv
Posts: 4,301
Send a message via ICQ to wvxvw
Default

Ah, well, then basically you're correct.
Yes, the variables are created and initialized before anything else in MXML is executed. Though, I wouldn't use one variable to initialize another... in simple cases this may work, but in more complex cases you may get a forward-reference exception (i.e. attempt to access a variable that isn't constructed yet). So, I'd populate variables after the construction of other declared stuff finishes.
Also you need [Bindable] meta tag before
ActionScript Code:
public var thisMenu:Menu ...
Otherwise the compiler will complain that it is not able to bind it.
__________________
The .NET open source editor for Flash and web developers
*This would be my contribution to the project*
couchsurfing if you need it
wvxvw is offline   Reply With Quote
Old 04-23-2009, 01:35 PM   #5
scripter73
Registered User
 
Join Date: Apr 2009
Posts: 10
Default

Hi wvxvw,

Thanks for the information. Since I'm just learning, I think that I really need to get this concept down. I know everything is event driven, but since I'm SOOOO.... linear thinking, I have this feeling to know what's created first, what's already created behind the scenes, etc.

If you find any good tutorials on this, please send them my way.

Thanks for your help!
scripter73
scripter73 is offline   Reply With Quote
Old 04-23-2009, 02:51 PM   #6
wvxvw
Holosuit User
 
wvxvw's Avatar
 
Join Date: Oct 2006
Location: Tel Aviv
Posts: 4,301
Send a message via ICQ to wvxvw
Default

http://msimtiyaz.wordpress.com/flex/...on-life-cycle/
This should be something like you're probably looking for.

http://blogs.eyepartner.com/adrian/f...instantiation/
Just an additional reading
__________________
The .NET open source editor for Flash and web developers
*This would be my contribution to the project*
couchsurfing if you need it
wvxvw is offline   Reply With Quote
Old 04-24-2009, 07:48 PM   #7
scripter73
Registered User
 
Join Date: Apr 2009
Posts: 10
Default Thanks!

Wow! These links are great. Thanks for sending. I really appreciate it.
scripter73 is offline   Reply With Quote
Old 04-24-2009, 08:01 PM   #8
wvxvw
Holosuit User
 
wvxvw's Avatar
 
Join Date: Oct 2006
Location: Tel Aviv
Posts: 4,301
Send a message via ICQ to wvxvw
Default

Happy to help
__________________
The .NET open source editor for Flash and web developers
*This would be my contribution to the project*
couchsurfing if you need it
wvxvw is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to give flash player dynamic url of xml file..? saqib_jahangir81 ActionScript 3.0 1 02-28-2008 12:41 AM
FocusManager has Bugs? firestar Components 5 01-09-2008 06:54 PM
Passing MXML file as XML Parameter maulik33 ActionScript 3.0 0 01-09-2008 04:21 PM
how do I make a clip wait before loading? shoodogg1977 ActionScript 1.0 (and below) 4 09-01-2006 01:08 PM
help with save to php padone Server-Side Scripting 6 05-21-2005 11:29 PM


All times are GMT. The time now is 09:11 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.