Hello world for communication between Flash/flex and fluorinefx!

Source: Internet
Author: User

The flex and. net interoperability (6): Flex and. net collaborative development tool fluorinefx is based on vs2008 + flex builder3. I have tried it several times on vs2010 + flash builder4, it is always unsuccessful (maybe you should review your character at night). So with this article, it is a supplement to vs2010/flash builder4 environment.

The. NET Server defines a method in testlib. CS according to another method in fluorinefx to obtain external data by referring to Silverlight:

 
Public String helloworld (string p) {return "hello," + P + ", welcome to fluroinefx! ";}

Then, you can seeFlashHow to call:

1,Now that you need to connect to the gateway, you must first have the connection object remotingconnection.

 
Package {import flash.net. netconnection; import flash. system. security; import flash.net. *; public class remotingconnection extends netconnection {public function remotingconnection (gatewayurl: string) {security. allowdomain (gatewayurl); this. objectencoding = objectencoding. amf3; this. connect (gatewayurl );}}}

Allow access to the gateway URL-> set the encoding-> open the connection, in one breath, no hard to understand

2,As3 callCode:

Package {import flash. display. sprite; import flash. events. mouseevent; import flash.net. responder; import flash. text. textfield; import flash. text. textfieldautosize; import flash. text. textfieldtype; [SWF (Height = 80, width = 400)] public class main extends sprite {private var Gateway: remotingconnection; private var responder: responder; private var txtinput: textfield; private var txtresult: textfield; private var lblin Put: textfield; private var BTN: customsimplebutton; private var btnlabel: textfield; public function main () {Init ();} private function Init (): void {gateway = new remotingconnection (http: // localhost: 1718/gateway. aspx); // create the connection object lblinput = new textfield (); lblinput. TEXT = "Enter the parameter:"; lblinput. selectable = false; lblinput. autosize = textfieldautosize. right; addchild (lblinput); lblinput. height = 20; lblinput. X = 10; lblinput. y = 10; AD Dchild (lblinput); txtinput = new textfield (); txtinput. border = true; txtinput. width = 200; txtinput. height = 20; txtinput. type = textfieldtype. input; txtinput. TEXT = "Yang Guo under the bodhi tree"; txtinput. y = lblinput. y; txtinput. X = lblinput. X + lblinput. width + 5; addchild (txtinput); BTN = new customsimplebutton (60, 20, "call"); addchild (BTN); BTN. y = txtinput. y; BTN. X = txtinput. X + txtinput. width + 10; txtresult = new textfield (); addchild (txtresul T); txtresult. X = lblinput. x; txtresult. y = lblinput. Y + lblinput. height + 10; txtresult. width = 380; txtresult. autosize = textfieldautosize. center; txtresult. textcolor = 0xff0000; BTN. addeventlistener (mouseevent. click, btnclick);} private function btnclick (E: mouseevent): void {gateway. call ("servicelib. testlib. helloworld ", new Responder (onresult, onfault), txtinput. text); // call method BTN. enabled = false; BTN. mouseenabled = Fals E;} // successful callback function private function onresult (Result: string): void {// trace ("success:", result); // success: Hello, yang Guo under the bodhi tree, welcome to fluroinefx! Txtresult. TEXT = result; BTN. enabled = true; BTN. mouseenabled = true;} // The failed callback function private function onfault (Result: string): void {// trace ("failed:", result); txtresult. TEXT = result; BTN. enabled = true; BTN. mouseenabled = true ;}}}

It looks long, but you don't need to read it. Most of the code is used to create an interface. The key part is only a few lines of comments!

This is the running result. The overall SWF is less than 5 kb, which is short and concise!

Let's take a look.FlexHow to use:

Create a flex project in Flash builder and copy remotingconnection. As to the src directory. The complete mxml code is as follows:

<? 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 "width =" 299 "Height =" 188 "> <FX: SCRIPT> <! [CDATA [import flash.net. responder; private var Gateway: remotingconnection; private var responder: responder; protected function btncall_clickhandler (Event: mouseevent): void {// todo auto-generated method stubif (Gateway = NULL) {gateway = new remotingconnection ("http: // localhost: 1718/gateway. aspx ");} gateway. call ("servicelib. testlib. helloworld ", new Responder (onresult, onfault), txtinput. text); this. btncall. Mouseenabled = false; this. btncall. enabled = false;} private function onresult (Result: string): void {txtresult. TEXT = result; this. btncall. mouseenabled = true; this. btncall. enabled = true;} private function onfault (Result: string): void {txtresult. TEXT = result; this. btncall. mouseenabled = true; this. btncall. enabled = true ;}]]> </FX: SCRIPT> <FX: declarations> <! -- Place non-visual elements (e.g ., services, value objects) Here --> </FX: declarations> <s: Label x = "10" Y = "10" text = "Enter the following parameters: "id =" lblinput "/> <s: textinput x = "88" Y = "6" id = "txtinput" text = "Yang Guo under the bodhi tree"/> <s: button x = "224" Y = "7" label = "Submit" id = "btncall" Click = "btncall_clickhandler (event)"/> <s: textarea x = "6" Y = "36" width = "287" Height = "145" id = "txtresult"/> </S: Application>

The logic is exactly the same as just now!

This is the running interface. It seems to be more professional, but the size of the final generated SWF is much larger (there must be something missing)

ExampleSource codeDownload: http://cid-2959920b8267aaca.office.live.com/self.aspx/Flash/FluorineFx.rar

Related Article

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.