using flex Webservice component in flash cs4
2009-04-29 10:44
232 查看
Thursday, October 23, 2008
Using Flex Webservice component in Flash CS4
One of the most common requests for the Flash team is to provide aWebservice component for Actionscript 3.0 like the one Flash has for
Actionscript 2.0. Finally, Flash has provided the features in CS4 to
allow users to use any Flex components that does not rely on Flex framework such as Flex WebService component and HTTPService.
In
the below example am going to demonstrate how users can use Flex
WebService in Flash to get countries names and populate them in a Flash
DataGrid component.
1. File > New
2. Select "Flash File (Actionscript 3.0)".
3. Open the Component panel and drag a DataGrid component to the stage and call it "dg".
5. File > Publish settings and click on "Flash" tab.
![](http://3.bp.blogspot.com/_OlxOkLTYmG8/SQFS3PVLCnI/AAAAAAAAAAk/wj-jo51TbUs/s320/Picture+9.png)
6. Click on "Settings" button to launch "Advance Actionscript 3.0 Settings"
![](http://1.bp.blogspot.com/_OlxOkLTYmG8/SQFTt_Jm71I/AAAAAAAAAAs/UjOIKVJJeRo/s320/Picture+10.png)
7. Click on the "library path" tab
![](http://1.bp.blogspot.com/_OlxOkLTYmG8/SQFTt_Jm71I/AAAAAAAAAAs/UjOIKVJJeRo/s320/Picture+10.png)
8. Click on "Browse to SWC file" icon and get the "framwork.swc" and "rpc.swc" from the Flex SDK as follow :
![](http://2.bp.blogspot.com/_OlxOkLTYmG8/SQFVdvCYm6I/AAAAAAAAAA0/4g5FH0P6FpM/s320/Picture+12.png)
You can download FlexSDK and select the above SWC's from the following location
"sdks/3.0.0/frameworks/libs/"
9. Open the action panel and import the following:
import mx.rpc.soap.*;
import mx.core.*;
import mx.rpc.events.*;
import fl.data.DataProvider;
10. The following 2 lines of code are required if you are using SDK 3.0.0 but not if you are using higher version of SDK
//The following 2 lines to register class for
//Interface"mx.interface::IResourceManager
var resourceManagerImpl:Object = ApplicationDomain.currentDomain.getDefinition("mx.resources::ResourceManagerImpl");
Singleton.registerClass("mx.resources::IResourceManager", Class(resourceManagerImpl));
11. Now copy the following and paste below the above 2 line of codes
var foo:WebService = new WebService();
foo.addEventListener("load", finishedLoading);
foo.loadWSDL("http://www.webservicex.net/country.asmx?WSDL");
var myOperation:Operation;
function finishedLoading(evt:LoadEvent):void
{
myOperation = Operation(foo.getOperation("GetCountries"));
myOperation.addEventListener("fault", wsdlFault);
myOperation.addEventListener("result", wsdlResult);
myOperation.send();
}
function wsdlFault(evt:FaultEvent):void
{
trace(evt.fault);
}
function wsdlResult(evt:ResultEvent):void
{
trace(evt.result);
var myResult:Object = evt.result;
var len:Number = myResult.length;
var xml:XML = XML(evt.result);
var dp:DataProvider = new DataProvider(xml);
dg.dataProvider = dp;
}
12. Test Movie and you should get a list of all the countries inside the datagrid :
![](http://1.bp.blogspot.com/_OlxOkLTYmG8/SQFZQa0MXjI/AAAAAAAAAA8/NT777atz_YU/s320/Picture+13.png)
Posted by
Tareq AlJaber
at
8:46 PM
![](http://www.blogger.com/img/icon18_edit_allbkg.gif)
12
comments:
RG Infotechsaid...
Hi,
Really good information very helpful "Using Flex Webservice component in Flash CS4"
thanks
October 25, 2008 12:01 AM
![](http://www.blogger.com/img/icon_delete13.gif)
Thomas
said...
Hi,
it doesn't work fine for me.
Looks like the WS is never loaded.
function finishedLoading(evt:LoadEvent):void is never executed at runtime.
I used your example with http://www.webservicex.net/country.asmx?WSDL
What could happen ?
November 30, 2008 5:19 PM
![](http://www.blogger.com/img/icon_delete13.gif)
Neeraj Bagdia
said...
Same here..
The function finishedLoading seems never to load...
Ne help??
December 11, 2008 8:44 PM
![](http://www.blogger.com/img/icon_delete13.gif)
Tareq AlJaber
said...
I just tried it and worked for me. Would you please e-mail me your Fla and i will check it out for you.
Thanks,
Tareq
treguess@gmail.com
December 13, 2008 12:05 AM
![](http://www.blogger.com/img/icon_delete13.gif)
drukepple
said...
I've created the example, nothing else in the file. When I hit "Test
Movie," it takes an ungodly amount of time to compile...something like
40 seconds. I have a Dual G5 2.7 GHz PowerMac and am used to pretty
speedy compiles. Am I to expect this when using Flex SWCs? Or any SWCs?
It has to be those since I don't have anything else really going on in
the file. For good measure I removed the DataGrid component but still
had really long compiles. Anyone else having this issue?
January 2, 2009 8:56 PM
![](http://www.blogger.com/img/icon_delete13.gif)
Tareq AlJaber
said...
The performance issue you are seeing is because you are compiling
against all the classes in the flex framework "Framework.swc". You
won't see this problem with SWC's you create using Flex or Flash.
January 2, 2009 11:02 PM
![](http://www.blogger.com/img/icon_delete13.gif)
I think I am...
said...
What is the trick to send parameters to the web service? I checked the Flex docs and it wasn't immediately apparant.
March 31, 2009 6:58 AM
![](http://www.blogger.com/img/icon_delete13.gif)
polarfileio
said...
I have a the same question... how can we pass multiple parameters?
myOperation=Operation(ws.getOperation("GetWeatherByZipCode("+zip+")"));
April 6, 2009 6:45 AM
![](http://www.blogger.com/img/icon_delete13.gif)
nightcrawler
said...
When I test the movie, I get not a data grid, but a horrific flash
of components. The error says "access of undefined property dg."
The source being the line:
"dg.dataProvider= dp;"
Also,
the web service used in the example no longer works... I changed the
address to another and still got the same Seizure buttons response.
April 8, 2009 4:02 PM
![](http://www.blogger.com/img/icon_delete13.gif)
Tareq AlJaber
said...
dg is the name of the datagrid instance on stage. You are getting
the error because you did not give an instance name to the datagrid.
what you need to do is select the datagrid on stage and give it a name
as dg inside the Properties Inspector.
Let me know if you still have a problem and i will send you an FLA.
April 8, 2009 7:08 PM
![](http://www.blogger.com/img/icon_delete13.gif)
Rich
said...
This really great! Thanks
April 19, 2009 10:24 PM
![](http://www.blogger.com/img/icon_delete13.gif)
r3nz0
said...
it works for me...
but, I little confused, how to edit the data.. it's same with web service in as2 !?
can u give me an example code to change or edit the data !?
thanks before... ^^
April 22, 2009 10:40 PM
![](http://www.blogger.com/img/icon_delete13.gif)
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
相关文章推荐
- How to invoke Java web service in ASP.net using C#
- Download Adobe Flash Builder 4 and Flex Component Kit for Adobe Flash Professional CS4
- 【转载】Using the Web Service Callbacks in the .NET Application
- Using .Net, Flex, and Red5 to create a flash web application
- Building a RESTful Web Service Using Spring Boot In Eclipse
- Using Session State in a Web Service
- jQuery Autocomplete using Web Service in ASP.Net
- Part 17 Consuming ASP NET Web Service in AngularJS using $http
- Send and Receive JSON objects to Web Service Methods using jQuery AJAX in ASP.Net
- Using the Web Service Callbacks in the .NET Application
- Update SPListItem using Web Service
- MDT 2010 - Setting the Computer Description in AD without a webservice
- Introduction to using Java Persistence API in a web application in Java EE environment
- Android: Reading, using and working with XML data and web services in Android
- Flash + SharePoint WebService播放视频 (一)
- Flex 解析显示.net web service的DataTable返回
- android in practice_Using a Service for caching data(portfolio project)
- WebService in MOSS
- webpack打包遇到locals[0] does not appear to be a `module` object with Hot Module replacement API enabled. You should disable react-transform-hmr in production by using `env` section in Babel configuration
- [Flex]基于Flex+Webservice+xml的Poll System的构想