Blog Stats
  • Posts - 104
  • Articles - 0
  • Comments - 197
  • Trackbacks - 379

 

Consuming a Web Service with Flash

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
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Feedback

# re: Consuming a Web Service with Flash

Gravatar Wow!! This was so helpful! I got acquinted with the WSC just today and I was havind difficulties but this little tut made it a LOT clearer. Thanx!! ^_^ 5/11/2005 8:29 PM | OKami

# re: Consuming a Web Service with Flash

Gravatar Really helpful thanks. Your instructions were clear and everything worked on the first try. 7/1/2005 3:21 PM | Zugzug

# re: Consuming a Web Service with Flash

Gravatar Thank you SO much, your tutorial really helped me to understand how to consume web services. Once again thanks.
8/27/2005 12:56 AM | KuiloTron

# re: Consuming a Web Service with Flash

Gravatar This has helped me so much, thanks... I'm hitting a wall in one area though... My Web Service returns a query/array.. and I'm not sure how to access the results.. Is there an interface for this or a good tut?

webmigit@gmail.com 2/16/2006 8:46 PM | Great Article

# re: Consuming a Web Service with Flash

Gravatar thank you very much for the clearest introduction on the net 7/6/2006 1:49 PM | kutay

# re: Consuming a Web Service with Flash

Gravatar It helped me for interacting with web service from flash. Thank you very much. 7/20/2006 2:06 PM | Kannan

# re: Consuming a Web Service with Flash

Gravatar How to consume secured web service from flash
( HTTPS)??? 8/7/2006 4:15 PM | Kannan

# re: Consuming a Web Service with Flash

Gravatar Does this work with Flash Professional 8? Apart from the fact my menu layout is slightly different from yours, my service is never actually called... Strange! 10/1/2006 5:14 PM | David

# re: Consuming a Web Service with Flash

Gravatar Hloy crap. It worked! Cool tut man, tnx 10/30/2006 5:27 PM | Raymond

# re: Consuming a Web Service with Flash

Gravatar This is by far the best tutorial I've seen - and I've seen lots of them in the last couple of weeks - anywhere!

Nice work all around Mr. Hashmi! You saved me lots of pain, I only wish I would have found this before all the garbage I went through first... 11/3/2006 12:10 AM | Geekster

# re: Consuming a Web Service with Flash

Gravatar Well, that was great!. Now, what should I do to pass parameters when invoking a web service method that needs some parameters as input? 3/7/2007 11:50 AM | Ariel

# re: Consuming a Web Service with Flash

Gravatar AMAZING u Made my work lot more easier 10/23/2007 7:59 AM | Sarfaraz Nazir

# re: Consuming a Web Service with Flash

Gravatar chamar o webservice a partir do flash 11/13/2007 4:00 AM | unicace

# re: Consuming a Web Service with Flash

Gravatar Great article. Very straightforward. 1/28/2008 5:06 AM | JB

# re: Consuming a Web Service with Flash

Gravatar The following article might also be useful:

http://livedocs.adobe.com/flash/mx2004/main_7_2/wwhelp/wwhimpl/common/html/wwhelp.htm?context=Flash_MX_2004&file=00003020.html 1/28/2008 5:53 AM | JB

# re: Consuming a Web Service with Flash

Gravatar OH, THANK YOU VERY MUCH
it's the panacea from all my troubles!!! 2/3/2009 2:05 PM | iyakov

# re: Consuming a Web Service with Flash

Gravatar your the man dude!!
keep it up with more tutes with this very very high quality of instruction!!

many thanx :-) 5/3/2009 6:03 AM | Firas

# re: Consuming a Web Service with Flash

Gravatar Hi, Thanks a lot for this article. I have a problem that when I run the source .FLA file it is working perfectly, connects to the web service and fetches the result. But when i run the SWF alone or embed the SWF in a browser It is not working. Please help!!!!!.. Much appreciate your quick reply.

Thanks 5/18/2009 12:14 PM | Teddy

# re: Consuming a Web Service with Flash

Gravatar Hello,
i created a destop widget using flash.Currently i am using http:// protocol and i am getting the results as i expected, but when i changed http to https am not able to connect to the web services. Basically client blocked all the requests from http, so i need to use https request only.
Currently i am trying with cross domains. But i could not able to connect to Client’s web services in case of https.

its a stand alone application(widget)

if you have any solution.please send me


Thanks ,
Ramesh.
6/16/2009 11:39 PM | ramesh

# re: Consuming a Web Service with Flash

Gravatar great document :) 8/24/2009 1:41 AM | prakash

# Offer You.

Gravatar Great headline. If your cookie has a bite-sized action and your reader completes the action, I think two things happen. Their self-confidence goes up (which feels good) and their trust in you increases. 12/4/2009 4:41 PM | Debt Relief

# re: Consuming a Web Service with Flash

Gravatar I have succesfully consumed web service with strings but what do isend for dateTime ? I am trying to get flash to work with http://ws.cdyne.com/SmsWS/SMS.asmx?op=SendSMSAdvanced having trouble with dateTime. any ideas?

objSendSMSAdvanced = objWebService.SendSMSAdvanced(txt_sms.text,LicenseKeysms,txt_msgsms.text,0,true,0); 2/16/2010 10:43 AM | SMS Web Service

# re: Consuming a Web Service with Flash

Gravatar Excelent!! beatiful!! perfect =) 3/3/2010 11:04 AM | yskatll

# re: Consuming a Web Service with Flash

Gravatar my life finally has sense ! 6/1/2011 5:52 AM | Dario

Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification:
 
 

 

 

Copyright © INETA Pakistan