In this article I’m going to show how to consume a Web service and some of the pros and cons of it. When you’re done reading you should have an understanding of what data binding is, how to use it in your applications, and how to achieve similar results without using it.
Unfortunately for some, Flash Professional is required to follow along with the examples. If you haven’t upgraded Flash to the Professional version yet, taking advantage of the Web service integration and data binding might just be a good enough reason to.
What Are Web Services?
A Web service is, more or less, a remote procedure call wrapped in an XML package and typically transmitted over HTTP. You make a request to the URL of the Web service, passing in any appropriate parameters, and are greeted with an XML packet containing the result of the function call. The standard XML format for Web service messages is SOAP – Simple Object Access Protocol.
Web services can be inspected by requesting the WSDL – Web Services Description Language – of the service. The WSDL explains how to interact with the service, what methods are available, what their parameters are, etc. The WSDL format isn’t the easiest to read. Thankfully, Flash will help us out with WSDL interpretation, which we’ll see a little later.
What Is Data Binding?
Now that we have an idea what Web services are, data binding is next on the explanation hit-list. Data binding is… well, magic. Through data binding you can “glue” two separate pieces of a program together. Whenever one piece changes the other piece will automatically notice that change and update itself without any coding necessary. As an added bonus, data binding can be a one- or two-way street.
Data binding is remarkably simple to use and can be done without writing a single line of code. Because of this, it’s a blessing and a curse at the same time. It eliminates the need for you to program what could be complex interactions, but the “magical” aspects of data binding can make it a maintenance nightmare.
In the coming examples, I’ll show you how to use it, how to avoid using it, and finally make some recommendations for when data binding is appropriate.
How to bind a Web Service with Flash?
1- First make a simple web service that fetch data from data base like Sql Server 2005 and return data in objects like:-
pro[i] = new ProDetail();
pro[i].Pro_name = row.ToString();
pro[i].Pro_type = row.ToString();
pro[i].Pro_color = row.ToString();
pro[i].Price = row.ToString();
pro[i].Description = row.ToString();
2- Then open Flash Professional 8, and goto Window and select Components
3- then click on User interface and drop Text Area onto the stage.
4- Give Instance Name to the Text Area in Properties panel.
5- Now go to Window and click on Other Panels and select Web Services
6- Now click on Glob and give the WSDL address of web service which would be like this.
7- After giving WSDL address of web service to Glob, Flash will have all the methods, your web service have.
8- the method you want to use just Right click on it and select Add Method Call (An instance of the Web Service Connector component would be added to the stage) as shown in fig:-
9- Name the Web Service Connector component from the “Properties” panel.
Bind Web Service Result to the UI Component:
10- In order to display the results returned from the web service, you need to bind the result to the Text Area component you placed on the stage. Go to Window > Development Panels > Component Inspector. Select the Text Area 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.
11- Now click on Bound To in the Component Inspector, a window will open. Click on Web service Connector and at left side (Schema Location) select the object you want to bind with Text Area component and click OK.
12- And set Direction “In”.
13- Now bind the Web Service connector and set its Direction “out” and click on Bound To bind with Text Area in the Component Path.
14- Now create another layer and name it “Action’.
15- Now type the following action:-
16- Now play your movie and see that what ever in your database, flash displays…