Flex 4 SDK source code analysis!

Source: Internet
Author: User

If you want to reprint it, Please retain your copyright:
/*
* Description: pv3d class inheritance Architecture

* Auther: chongchong-innocent blue
* MSN: chongchong2008@msn.com
* Blog: chongchong2008
* Dates: 2009-06-02
* Copyright: chongchong2008 Yichang Hubei China
*/

 

Flex 4 SDK source code analysis!

 

Recently, the flex 4 SDK (flex_sdk_4.0.0.7219_mpl_src)Source code
This directory contains the following related parts:

1. MX core frameworks, which can be found in the following directory
Flex_sdk_4.0.0.7219_mpl_src --> frameworks --> projects --> framework --> SRC --> MX

2. RPC frameworks, which can be found in the following directory
Flex_sdk_4.0.0.7219_mpl_src --> frameworks --> projects --> RPC --> SRC --> MX

3. Air framework, which can be found in the following directory
Flex_sdk_4.0.0.7219_mpl_src --> frameworks --> projects --> airframework --> SRC --> MX

4. Skin-related, which can be found in the following directory
Flex_sdk_4.0.0.7219_mpl_src --> frameworks --> projects --> haloclassic --> SRC

I. Familiar with Flex SDK
The flex SDK is really huge and all-encompassing. It is really difficult to start from the very beginning and I don't know where to start reading.
The first step is to familiarize yourself with the basic interfaces defined by flex and read all interfaces. It is the basic interface file in flex_sdk_4.0.0.7219_mpl_src --> frameworks --> projects --> framework --> SRC --> MX --> core, familiar with Flex's uicomponent component and container, in particular, you should be familiar with the application class (how to establish a connection with the systemmanager class, how to form a queue, and how to delay the call ).

Familiar with uicommp ontent
Public Function calllater (method: function, argS: array/* of object */= NULL): void {
Methodqueue. Push (New methodqueueelement (method, argS ));
VaR SM: isystemmanager = systemmanager;
If (SM & (Sm. Stage | SM. useswfbridge ()))
{
If (! Listeningforrender)
{
SM. addeventlistener (flexevent. Render, calllaterdispatcher );
SM. addeventlistener (flexevent. enter_frame, calllaterdispatcher );
Listeningforrender = true;
}
If (Sm. stage)
SM. Stage. invalidate ();
}
}

Familiar with flexmodulefactory class operation, registration of single-piece classes in the system, and how to load modules.

Addframescript (docframe, docframehandler );

// Frame 1: module Factory
// Frame 2: document class
// Frame 3 +: extra classes
For (I = docframe + 1; I <totalframes; I ++ ){
Addframescript (I, extraframehandler );
}

Next, let's take a look at the management interface defined by Flex. In flex_sdk_4.0.0.7219_mpl_src --> frameworks --> projects --> framework --> SRC --> MX --> managers, familiarize yourself with this, in order to know how the application runs, the content here is somewhat complicated and must be carefully read. In particular, you need to carefully read the systemmanager, which is as important as the uicomponent in the basic interface.

There are also some concepts to be familiar with, You Need To Know What is document, swfroot, sandboxroot, toplevelsystemmanager.

 

Run the flex application:

========================================================== ====================
Flexapplicationbootstrap.
========================================
Package MX. Core {
Import flash. display. displayobject;
Import flash. Events. event;
Import MX. Events. flexevent;

[Excludeclass]
Public class flexapplicationbootstrap extends flexmodulefactory {
Include "../CORE/version. ";
Public Function flexapplicationbootstrap (){
Addeventlistener ("ready", readyhandler );
Super ();
}

Public Function readyhandler (Event: Event): void {
Removeeventlistener ("ready", readyhandler );
VaR O: Object = create ();
If (O is displayobject ){
Addchild (displayobject (o ));
O. dispatchevent (New flexevent (flexevent. application_complete ));
}

}
}
}

========================================================== ====================
Flexmodulefactory.
========================================================== ====================
Package MX. Core {
[Excludeclass]
/**
* @ Private
*/
Public class flexmodulefactory extends movieclip implements iflexmodulefactory, itextlinecreator {

Private Static const init_state: Int = 0;
Private Static const rsl_start_load_state: Int = 1;
Private Static const app_load_state: Int = 2;
Private Static const app_start_state: Int = 3;
Private Static const app_running_state: Int = 4;
Private Static const error_state: Int = 5;
Private Static const rsl_loading_state: Int = 6;

Public Function flexmodulefactory (){
Super ();
VaR RSLs: array = Info () ["RSLs"];
VaR cdrsls: array = Info () ["cdrsls"];

// Put cross-domain RSL information in the RSL list.
VaR rsllist: array = [];
VaR N: int;
VaR I: int;
If (cdrsls & cdrsls. length> 0 ){
VaR crossdomainrslitem: class = Class (getdefinitionbyname ("MX. Core: crossdomainrslitem "));
N = cdrsls. length;
For (I = 0; I <n; I ++ ){
VaR cdnode: Object = new crossdomainrslitem (
Cdrsls [I] ["RSLs"],
Cdrsls [I] ["policyfiles"],
Cdrsls [I] ["Digests"],
Cdrsls [I] ["types"],
Cdrsls [I] ["issigned"]);

Rsllist. Push (cdnode );
}
}
If (RSLs! = NULL & RSLs. length> 0 ){
N = RSLs. length;
For (I = 0; I <n; I ++)
{
VaR node: rslitem = new rslitem (RSLs [I]. url );
Rsllist. Push (node );
}
}

Rsllistloader = new rsllistloader (rsllist );

Mixinlist = Info () ["mixins"];

Stop ();

Loaderinfo. addeventlistener (event. Complete, modulecompletehandler );

VaR docframe: Int = totalframes = 1? 0: 1;

Addframescript (docframe, docframehandler );

// Frame 1: module Factory
// Frame 2: document class
// Frame 3 +: extra classes
For (I = docframe + 1; I <totalframes; I ++)
{
Addframescript (I, extraframehandler );
}

Timer = new timer (100 );
Timer. addeventlistener (timerevent. Timer, timerhandler );
Timer. Start ();

Update ();
}

public function create (... params): Object
{< br> var mainclassname: String = Info () ["mainclassname"];
If (mainclassname = NULL)
{< br> var URL: String = loaderinfo. loaderurl;
var Dot: Number = URL. lastindexof (". ");
var slash: Number = URL. lastindexof ("/");
mainclassname = URL. substring (slash + 1, dot);
}< br>
var mainclass: class = Class (getdefinitionbyname (mainclassname);

Return mainclass? New mainclass (): NULL;
}

Public Function Info (): Object
{
Return {};
}

Private function docframehandler (Event: event = NULL): void
{
// Register Singleton classes.
// Note: getdefinitionbyname () will return null
// If the class can't be found.

Singleton. registerclass ("MX. Managers: ibrowsermanager ",
Class (getdefinitionbyname ("MX. Managers: browsermanagerimpl ")));

Singleton. registerclass ("MX. Managers: icursormanager ",
Class (getdefinitionbyname ("MX. Managers: cursormanagerimpl ")));

Singleton. registerclass ("MX. Managers: idragmanager ",
Class (getdefinitionbyname ("MX. Managers: dragmanagerimpl ")));

Singleton. registerclass ("MX. Managers: ihistorymanager ",
Class (getdefinitionbyname ("MX. Managers: historymanagerimpl ")));

Singleton. registerclass ("MX. Managers: ilayoutmanager ",
Class (getdefinitionbyname ("MX. Managers: layoutmanager ")));

Singleton. registerclass ("MX. Managers: ipopupmanager ",
Class (getdefinitionbyname ("MX. Managers: popupmanagerimpl ")));

Singleton. registerclass ("MX. Resources: iresourcemanager ",
Class (getdefinitionbyname ("MX. Resources: resourcemanagerimpl ")));

Singleton. registerclass ("MX. styles: istylemanager ",
Class (getdefinitionbyname ("MX. styles: stylemanagerimpl ")));

Singleton. registerclass ("MX. styles: istylemanager2 ",
Class (getdefinitionbyname ("MX. styles: stylemanagerimpl ")));

Singleton. registerclass ("MX. Managers: itooltipmanager2 ",
Class (getdefinitionbyname ("MX. Managers: tooltipmanagerimpl ")));

appready = true;
// The resources must be installed before Update () creates components
// (such as datechooswer) that might need them immediately.
installcompiledresourcebundles ();
Update ();
If (currentframe deferrednextframe ();
}

private function deferrednextframe (): void
{< br> If (currentframe + 1 <= framesloaded)
{< br> nextframe ();
}< br> else
{< br> // next frame isn' t baked yet, we'll check back...
nextframetimer = new timer (100);
nextframetimer. addeventlistener (timerevent. timer,
nextframetimerhandler);
nextframetimer. start ();
}< BR >}

Private function extraframehandler (Event: event = NULL): void
{
VaR framelist: Object = Info () ["frames"];

If (framelist & framelist [currentlabel])
{
VaR C: class;
Try
{
C = Class (getdefinitionbyname (framelist [currentlabel]);
C ["frame"] (this );
}
Catch (E: Error)
{
}
}

If (currentframe <totalframes)
Deferrednextframe ();
}

Private function timerhandler (Event: timerevent): void
{
If (totalframes> 2 & framesloaded> = 2 |
Framesloaded = totalframes)
{
Apploaded = true;
}

Update ();
}

Private function nextframetimerhandler (Event: timerevent): void
{
If (currentframe + 1 <= framesloaded)
{
Nextframe ();
Nextframetimer. removeeventlistener (timerevent. Timer,
Nextframetimerhandler );
// Stop the timer
Nextframetimer. Reset ();
}
}
}

}

 

II. Flex Inheritance System

Important classes and interfaces can be found in flex_sdk_4.0.0.7219_mpl_src --> frameworks --> projects --> framework --> SRC --> MX --> Core

1. Interface inheritance system, from the underlying interface to the high-level interface:

Iflexdisplayobject --> ibitmapdrawable, ieventdispatcher
Iuicomponent --> iflexdisplayobject
Icontainer --> iuicomponent
Ideferredinstantiationuicomponent --> iuicomponent
IButton --> iuicomponent

Iborder
Irectangularborder --> iborder

Ilayoutelement --> ieventdispatcher

IID
Irawchildrencontainer
Ichildlist

Iconstraintclient
Idatarenderer
Iembeddedfontregistry
Ifontcontextcomponent
Ifacloud
Iflexmodule
Iflexmodulefactory
Iinvalidating
Iprogrammaticskin

Packaging flash itself
Idisplayobjectinterface
Iinteractiveobjectinterface
Idisplayobjectcontainerinterface

Internal namespace
Mx_internal

2. Class inheritance system

Flexsprite --> Sprite
Uicomponent --> flexsprite implements iautomationobject, ichildlist, iconstraintclient,
Ideferredinstantiationuicomponent, iflexdisplayobject, iflexmodule, IID,
Iinvalidating, ilayoutmanagerclient, ipropertychangenotifier,
Irepeaterclient, istateclient, iadvancedstyleclient, itooltipmanagerclient,
Iuicomponent, ivalidatorlistener, ivisualelement, ilayoutelement

Container --> uicomponent implements icontainer, idatarenderer,
Ifocusmanagercontainer, ilistitemrenderer,
Irawchildrencontainer, ichildlist, ivisualelementcontainer

Layoutcontainer --> container implements iconstraintlayout
Layoutmanager --> eventdispatcher implements ilayoutmanager

 

Classfactory implements ifacloud

Global class:
Flexglobals
Uicomponentglobals
Containerglobals
Systemmanagerglobals
Singleton (Flex single-piece class, static type, will be referenced in many places)

ApplicationProgramRelated:
Application --> layoutcontainer
Flexapplicationbootstrap --> flexmodulefactory

System Management:
Isystemmanager --> ieventdispatcher, ichildlist, iflexmodulefactory
Systemmanager --> movieclip implements ichildlist, iflexdisplayobject, iflexmodulefactory,
Iswfbridgeprovider, isystemmanager, itextlinecreator
Systemmanagerproxy --> systemmanager
Systemrawchildrenlist implements ichildlist

Drag management:
Idragmanager
Dragmanagerimpl implements idragmanager
Dragmanager
Dragproxy --> uicomponent
Dragsource
Dragevent --> mouseevent

Other tools include tooltipmanager, cursormanager, focusmanager, popupmanager, layoutmanager, browsermanager, and historymanager.

 

 

3. Event hooks, function call queues, and single-piece

The flex SDK uses a large number of single pieces, event hooks, and queue calls.

Singleton. registerclass (
"MX. Resources: iresourcemanager ",
Class (getdefinitionbyname ("MX. Resources: resourcemanagerimpl "))
);

..... Unfinished

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.