[Flex] Introduction to mate flex Framework process using an adapter

Source: Internet
Author: User

Process introduction of mate flex framework: one-way communication
Introduction to the process of mate flex framework-two-way communication
Introduction to mate flex Framework process-Introduction to listener tagmate flex Framework process-using an adapter


This article introduces a typical process of mate flex framework: two-way communication model: using an adapter (two-way communication via model: using an adapter)

The following is its flowchart: Okay. Let's analyze the meaning of this new process: 1. In the view, we use the <dispatcher> mate tag, triggered an event. 2. Event bus will notify the event map of the triggered event ).

In event map, some event processing logic will be prepared in advance (that is, some eventhandler will be defined)3. In these defined eventhandler, there will be a group of actions to respond to this event. As shown in, <eventhandler> defines a <serviceinvoker> 4. Set some values using the model manage method. 5. In the bindings mode, when the attributes of model manager change, these changes are captured using apdapter. 6. bindings binds the attributes of model manager to the view. That is, when the attribute of model manager changes, it is synchronously updated to the view.Kenshin uses an existing example to illustrate this process. This example is address in: http://mate.asfusion.com/assets/content/examples/weatherWidget/srcview/ Please see the following snippet code: <Eventhandlers type = "{weatherevent. Get}">
<Extensions: weatherloader> <! -- Make the call to the service -->
<Properties location = "{event. Location}" unit = "{event. unit}"/>
<Extensions: resulthandlers>
<! -- Receive the results contained in the currentevent. Data property (weatherresultevent contains a data property) -->
<Methodinvoker generator = "{weathermanager}" method = "setweather" arguments = "{currentevent. Data}"/>
</Extensions: resulthandlers>
</Eventhandlers>
OK. The code above demonstrates that a weatherevent type is created in <eventmap>. get <eventhandlers> and use <methodinvoker> to call a program called weathermanager. setweather () also passes in a parameter: currentevent. data. Public class weathermanager extends eventdispatcher
{
Private VaR _ weather: weather;
Public Function setweather (W: weather): void
{
_ Weather = W;
Dispatchevent (new event ("weatherchange "));
}

[Bindable (event = "weatherchange")]
Public Function get currentweather (): currentconditions
{
Return (_ weather! = NULL )? _ Weather. Current: NULL;
}
OK. Let's take a look at weathermanager. First, weathermanager. setweather () is called because the previous Code uses the <methodinvoker> method (). Function: setweather: assigns the passed content to _ weather and triggers a dispatchevent (new event ("weatherchange: weatherchange is bound to currentweather. Therefore, when this event is triggered, the public function get currentweather (): currentconditions is automatically executed. <! -- Detailmodel ___________________________________________________________________ -->

<Injectors target = "{detailmodel}">
<Propertyinjector targetkey = "Weather" Source = "{weathermanager}" sourcekey = "currentweather"/>
</Injectors>
Because in detailmodel. the <injectors> label is used in mxml, and some attribute labels <propertyinjector> are added in <injectors> to assign currentweather in weathermanager to weather in the detailmodel. The above method is caused by the previous Code, namely triggering currentweather. After triggering currentweather, the code just executed due to the role of <injectors>. Public class detailmodel extends injectortarget
{
/*-..................................... .... Weather .......................................... */
Private VaR _ weather: currentconditions;
Public Function get weather (): currentconditions
{
Return _ weather;
}

[Bindable]
Public Function set weather (W: currentconditions): void {
_ Weather = W;
Humidity = _ weather. Atmosphere. humidity;
Description = _ weather. description;
Formatunits ();
}
 
/*-..................................... .... Formatunits .......................................... */
Private function formatunits (): void
{
If (weather & units ){
Pressure = weather. Atmosphere. Pressure + "" + units. Pressure + "and" + weather. Atmosphere. Rising;
Wind = (weather. Wind. speed> 0 )? (Weather. Wind. Speed + "" + units. Speed): & apos; calm & apos ;;
Visibility = Number (weather. Atmosphere. Visibility)/100 + "+ units. distance;
}
}
Let's take a look at what weather in the detailmodel defines. Code: public function set weather (W: currentconditions. Through set weather, we obtain the attributes humidity, description, pressure, wind, and visibility.

<! -- Model _______________________________________________________________ -->

<Model: detailmodel id = "model"/>

<! -- GUI _______________________________________________________________ -->

<Mx: Text text = "{model. Description}" stylename = "title" width = "100%"/>
<Mx: Text text = "humidity: {model. Humidity} %" width = "100%"/>
<Mx: Text text = "Wind: {model. Wind}" width = "100%" type = "regxph" text = "yourobjectname"/>
<Mx: Text text = "pressure: {model. Pressure}" width = "100%"/>
<Mx: Text text = "visibility: {model. Visibility}" width = "100%"/>

The code above is that when the attributes humidity, description, pressure, wind, and visibility are obtained, they are displayed on the UI. Therefore, the [Bindable] method is used. When the preceding values change, the changed results are automatically displayed. To sum up, the preceding example uses the [Bindable] and <injectors> methods. The [Bindable] and <injectors> methods are superimposed, that is, the model manager method. In fact, let's take a closer look at the practices of apdapter and model manager in the same flex framework.

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.