Geeks With Blogs
INETA Pakistan Blogs Home of INETA Geeks
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 Posted on Thursday, April 28, 2005 4:15 AM | Back to top


Comments on this post: Consuming a Web Service with Flash

# re: Consuming a Web Service with Flash
Requesting 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!! ^_^
Left by OKami on May 11, 2005 8:29 PM

# re: Consuming a Web Service with Flash
Requesting Gravatar...
Really helpful thanks. Your instructions were clear and everything worked on the first try.
Left by Zugzug on Jul 01, 2005 3:21 PM

# re: Consuming a Web Service with Flash
Requesting Gravatar...
Thank you SO much, your tutorial really helped me to understand how to consume web services. Once again thanks.
Left by KuiloTron on Aug 27, 2005 12:56 AM

# re: Consuming a Web Service with Flash
Requesting 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
Left by Great Article on Feb 16, 2006 8:46 PM

# re: Consuming a Web Service with Flash
Requesting Gravatar...
thank you very much for the clearest introduction on the net
Left by kutay on Jul 06, 2006 1:49 PM

# re: Consuming a Web Service with Flash
Requesting Gravatar...
It helped me for interacting with web service from flash. Thank you very much.
Left by Kannan on Jul 20, 2006 2:06 PM

# re: Consuming a Web Service with Flash
Requesting Gravatar...
How to consume secured web service from flash
( HTTPS)???
Left by Kannan on Aug 07, 2006 4:15 PM

# re: Consuming a Web Service with Flash
Requesting 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!
Left by David on Oct 01, 2006 5:14 PM

# re: Consuming a Web Service with Flash
Requesting Gravatar...
Hloy crap. It worked! Cool tut man, tnx
Left by Raymond on Oct 30, 2006 5:27 PM

# re: Consuming a Web Service with Flash
Requesting 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...
Left by Geekster on Nov 03, 2006 12:10 AM

# re: Consuming a Web Service with Flash
Requesting 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?
Left by Ariel on Mar 07, 2007 11:50 AM

# re: Consuming a Web Service with Flash
Requesting Gravatar...
AMAZING u Made my work lot more easier
Left by Sarfaraz Nazir on Oct 23, 2007 7:59 AM

# re: Consuming a Web Service with Flash
Requesting Gravatar...
chamar o webservice a partir do flash
Left by unicace on Nov 13, 2007 4:00 AM

# re: Consuming a Web Service with Flash
Requesting Gravatar...
Great article. Very straightforward.
Left by JB on Jan 28, 2008 5:06 AM

# re: Consuming a Web Service with Flash
Requesting 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
Left by JB on Jan 28, 2008 5:53 AM

# re: Consuming a Web Service with Flash
Requesting Gravatar...
OH, THANK YOU VERY MUCH
it's the panacea from all my troubles!!!
Left by iyakov on Feb 03, 2009 2:05 PM

# re: Consuming a Web Service with Flash
Requesting Gravatar...
your the man dude!!
keep it up with more tutes with this very very high quality of instruction!!

many thanx :-)
Left by Firas on May 03, 2009 6:03 AM

# re: Consuming a Web Service with Flash
Requesting 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
Left by Teddy on May 18, 2009 12:14 PM

# re: Consuming a Web Service with Flash
Requesting 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.
Left by ramesh on Jun 16, 2009 11:39 PM

# re: Consuming a Web Service with Flash
Requesting Gravatar...
great document :)
Left by prakash on Aug 24, 2009 1:41 AM

# Offer You.
Requesting 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.
Left by Debt Relief on Dec 04, 2009 4:41 PM

# re: Consuming a Web Service with Flash
Requesting 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);
Left by SMS Web Service on Feb 16, 2010 10:43 AM

# re: Consuming a Web Service with Flash
Requesting Gravatar...
Excelent!! beatiful!! perfect =)
Left by yskatll on Mar 03, 2010 11:04 AM

# re: Consuming a Web Service with Flash
Requesting Gravatar...
my life finally has sense !
Left by Dario on Jun 01, 2011 5:52 AM

# After publishing it is not connecting to webservice
Requesting Gravatar...
Hi all,
I created the webservice by seeing this instructions. when i click the file and from there when i publish and click button we should go to the webservice and getting the data. But when i clicked the published swf file and when i click the button . There is no
response . It is not connecting to the webservice . How to rectify this issue.
Thanks,
sachin prasad.
Left by sachin prasad on Apr 14, 2012 7:54 AM

Your comment:
 (will show your gravatar)
 


Copyright © INETA Pakistan | Powered by: GeeksWithBlogs.net | Join free