Flex Study Notes application communicates with Group

Source: Internet
Author: User

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>

 

 

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.