您的位置:首页 > 其它

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 a
Webservice 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.



6. Click on "Settings" button to launch "Advance Actionscript 3.0 Settings"



7. Click on the "library path" tab



8. Click on "Browse to SWC file" icon and get the "framwork.swc" and "rpc.swc" from the Flex SDK as follow :




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 :





Posted by
Tareq AlJaber

at
8:46 PM




12
comments:

RG Infotech
said...

Hi,

Really good information very helpful "Using Flex Webservice component in Flash CS4"

thanks

October 25, 2008 12:01 AM



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



Neeraj Bagdia
said...

Same here..
The function finishedLoading seems never to load...

Ne help??

December 11, 2008 8:44 PM



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



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



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



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



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



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



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



Rich
said...

This really great! Thanks

April 19, 2009 10:24 PM



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



Post a Comment

Newer Post

Older Post

Home

Subscribe to:
Post Comments (Atom)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: