Can't believe this is so simple. Its even easier than consuming a web service any other way. This is because Flash provides a way to bind values returned by a web service to Flash Components. No coding is required; only a couple of clicks and drags, thats it! This is a great way to develop Flash tickers to display data (possibly Stock Quotes, Currency Exchange Rates, etc.) on a web page without ever needing to refresh it for updated data. So, how to go about doing this? Very simple.
1) Create a Web Service
Create a simple "Hello World" Web Service; one that simply returns the string "Hello World" when invoked. If you develop the Service using Visual Studio .NET, the code for "Hello World" is generated automatically. Run and test the Web Service in your web browser. Copy the URL for your Web Service Description or WSDL document i.e. if the URL for your web service is "http://localhost/FlashRemoting/HelloWorld.asmx", then you can access its service description at "http://localhost/FlashRemoting/HelloWorld.asmx?WSDL".
Run Macromedia Flash MX 2004 Professional, and create a new Flash document.
2) Link the Flash Movie to the Web Service
Open the "Web Services" panel by going to Window > Development Panels > Web Services. Click the globe icon on the panel; a small window will appear. Click the "+" Add button on the window, and enter the URL you copied for the WSDL document in step 1. (This will not work if you simply enter the URL for your web service; it MUST be the URL for the WSDL document). When you click the OK button, you will see that the Web Service has been added to the list in the Web Services panel. Expand the "[Your Web Service Name
]" Node in the panel and right-click the method you want to call. From the pop-up menu, click "Add Method Call". (An instance of the Web Service Connector component would be added to the stage).
3) Place Flash UI Components on the stage
Go to Window > Development Panels > Components, and drag a "Label" and "Button" control on to the main Flash movie stage.
4) Name all the Component Instances on the stage
Name all 3 component instances on the stage, the Label, the Button, and the WebServiceConnector component from the "Properties" panel.
5) Bind Web Service Result to the UI Component
In order to display the string returned from the web service, you need to bind the result to the Label component you placed on the stage. Go to Window > Development Panels > Component Inspector. Select the Label component on the stage and go to the "Bindings" tab on the "Component Inspector" window. Click the "+" Add Binding button. Select "text : String" from the list and click the OK button. Now that you have specified the UI component property to bind to, you now need to specify the Data Source that would provide the value to display in the Label component. Select the "bound to" item in the Key-Value list on the "Bindings" tab, and then click the Magnifying Glass icon (The "Bound To" window will appear). From the "Component Path" list on the left, select the "WebServiceConnector <[Your Web Service Name
]>" node, select "result : String" from the "Schema Location" list on the right, and click the OK button.
6) Add Behavior to Invoke/Trigger the Web Service
To invoke the web service, you need to add a behavior to the button. Go to Window > Development Panels > Behaviors. Select the Button component on the stage and on the "Behaviors" panel, click the "+" Add Behavior button. On the context menu, go to Data > Trigger Data Source (The "Trigger Data Source" window will appear). Select the "[Your Web Service Name
]" node and click the OK button.
7) Run the Flash Movie
Press Ctrl+Enter to compile and run the Flash movie. When you click the button, the web service will be invoked and the returned text will appear in the Label component.
Thats It! I told you it was very easy.
Look Mom ! No Code. :)
Adnan Farooq Hashmi,
MVP (Windows SDK),
User Group Leader - Core.NET (http://coredotnet.blogspot.com
Chair Infrastructure Committee - INETA Pakistan
Member INETA Speaker's Bureau