The calculation result in the middle is a group, and the and B filling and calculation results are in the application. The following functions implement communication between the application and the group.
Interface Rendering
Application Development
View code
<? XML version = "1.0" encoding = "UTF-8"?>
<S: Application xmlns: FX = "http://ns.adobe.com/mxml/2009"
Xmlns: S = "Library: // ns.adobe.com/flex/spark"
Xmlns: MX = "Library: // ns.adobe.com/flex/mx" minwidth = "955" minheight = "600" xmlns: Group = "group. *">
<S: layout>
<S: verticallayout/>
</S: layout>
<FX: declarations>
<! -- Place non-visual elements (such as services and value objects) Here -->
</FX: declarations>
<FX: SCRIPT>
<! [CDATA [
[Bindable]
Public VaR Result: String = New String ();
Protected Function Btnadd_clickhandler (Event: mouseevent): void
{
// Add grpcaluculate
Grpcaluculate. Calculate (txta. Text, txtb. Text );
}
]>
</FX: SCRIPT>
<Mx: Form>
<Mx: formitem label = "A:">
<S: textinput id = "txta"/>
</MX: formitem>
<Mx: formitem label = "B:">
<S: textinput id = "txtb"/>
</MX: formitem>
<Mx: formitem>
<S: button label = "add" id = "btnadd" Click = "btnadd_clickhandler (event)"/>
</MX: formitem>
</MX: Form>
<Group: calculategroup id = "grpcaluculate" Height = "100"/>
<Mx: Form>
<Mx: formitem label = "Calculation Result:">
<S: textinput text = "{result}"/>
</MX: formitem>
</MX: Form>
</S: Application>
Group Development
Create a folder Group , Create in this folder Mxml Module Calculategroup. mxml
View code
<? XML version = "1.0" encoding = "UTF-8"?>
<S: group xmlns: FX = "http://ns.adobe.com/mxml/2009"
Xmlns: S = "Library: // ns.adobe.com/flex/spark"
Xmlns: MX = "Library: // ns.adobe.com/flex/mx" width = "400" Height = "100">
<S: layout>
<S: basiclayout/>
</S: layout>
<FX: declarations>
<! -- Place non-visual elements (such as services and value objects) Here -->
</FX: declarations>
<FX: SCRIPT>
<! [CDATA [
[Bindable]
Public VaR Addresult:String = New String ();
/* * Addition Calculation */
Public Function Calculate (: String , B: String ): Void
{
Try
{
Addresult = String ( Number (A) + Number (B ));
}
Catch (Ex: Error)
{
}
}
Protected Function Btnsub_clickhandler (Event: mouseevent): void
{
// Subtract and submit the result
This. parentdocument. Result = String ( Number (Addresult )- Number (Txtc. Text ));
}
]>
</FX: SCRIPT>
<Mx: Form>
<Mx: formitem label = "Calculation Result:">
<S: textinput id = "txtresult" text = "{addresult}"/>
</MX: formitem>
<Mx: formitem label = "C">
<S: textinput id = "txtc"/>
</MX: formitem>
<Mx: formitem>
<S: button label = "Subtract" id = "btnsub" Click = "btnsub_clickhandler (event)"/>
</MX: formitem>
</MX: Form>
</S: group>