I need to create a login in frame 1, after executing a SP to MSSQL and get the return true, then it gotoandplay frame 2.
How can I call SP in AS3?
I need to create a login in frame 1, after executing a SP to MSSQL and get the return true, then it gotoandplay frame 2.
How can I call SP in AS3?
To do anything related with databases while the flash player is not in AIR, you MUST use some sort of server side scripting language.
PHP, AMFPHP, ASP, ASP.NET etc. - are all server side languages.
White the server side code to call the stored procedure, get the results, and send it back.
In PHP, and ASP to send it back, it is an echo. The easiest way is to spit out a separated string. You can use any delimiter you want (semi-colon, comma, ampersand etc.) Then in flash, you get that string which you can split into an array and use that.
Does that help?
I use C# ASP.NET to build a webservice to call the SP in DB.
My questions:
1. How to call the webservice, pass parameters from AS3 to it?
The webservice link would be:
http://192.168.250.250/WS/service.asmx?op=Login
In C#, WS.Interface Login = new WS.Interface();
Login.login(username, password);
But, in AS3, how to call it?
2. When it returns a XML string, how to get it in AS3?
Do you have the sample AS code?
The guy at WellConsdered.be made a WebService package for AS3. I've only done testing with it, but it appeared in a book and it seems to work fine.
Here is a link to the site where you can get the code:
WellConsidered.be
This is an example code. Just put this on the main timeline frame one:
Code:
import be.wellconsidered.services.WebService;
import be.wellconsidered.services.Operation;
import be.wellconsidered.services.events.OperationEvent;
var ws = new WebService("http://www.webservicex.net/WeatherForecast.asmx?wsdl");
var op:Operation = new Operation(ws);
op.addEventListener (OperationEvent.COMPLETE, onResult);
op.addEventListener (OperationEvent.FAILED, onFault);
op.GetWeatherByPlaceName ("new york");
function onResult (e:OperationEvent):void {
for (var prop in e.data){
trace (e.data[prop]);
}
}
function onFault (e:OperationEvent):void {
trace (e.data);
}
I tried to define webservice in Flash CS3, but it said this feature is not supported by AS3. To use this feature, you must target AS1 / 2.
What happened?
Or, it moved to Flex?
If I need to do it in AS3, do I need to use LoadVars?
The Webservice panel that is built into the Flash IDE was designed only for AS2, and is merely a way of seeing the WSDL and does not actually do any code.
Once you download the WellConsidered package and have placed that code in your .fla directory (maintaining the folder structure), try creating a brand new .fla in the same folder, and just putting in the code that I gave you. See if that works.
That should give you a good starting point. Also I am sure that on the WellConsidered site that there are examples and possibly documentation
I read http://www.bloodforge.com/post/Using...ionScript.aspx
Do you think that using LoadVars would be easier?
But, how does
send_lv.sendAndLoad("http://www.bloodforge.com/webservice.asmx/MyMethod", result_lv, "POST");
get the return string?
I would say no. In AS2 I used the WebService class in almost every project I did for a year, and never did I have the problems bloodforge was explaining.
However, you are not using AS2 (right?)
If you are using AS3 this class will be easier. What bloodforge described is not even available in AS3.
Hi,
I setup the webservice on IIS. The method name is checkLogin.
I change the AS3 code:
When I run it on Flash CS3, it shows error:Code:
import be.wellconsidered.services.WebService;
import be.wellconsidered.services.Operation;
import be.wellconsidered.services.events.OperationEvent;
var ws = new WebService("http://192.168.250.250/WebService/Service.asmx?wsdl");
var op:Operation = new Operation(ws);
op.addEventListener (OperationEvent.COMPLETE, onResult);
op.addEventListener (OperationEvent.FAILED, onFault);
op.checkLogin("username","password");
function onResult (e:OperationEvent):void {
for (var prop in e.data){
trace (e.data[prop]);
}
}
function onFault (e:OperationEvent):void {
trace (e.data);
}
Error opening URL 'http://192.168.250.250/WebService/Service.asmx?wsdl'
[IOErrorEvent type="ioError" bubbles=false cancelable=false eventPhase=2 text="Error #2032: Stream Error. URL: http://192.168.250.250/WebService/Service.asmx?wsdl"]
But, I can open it on browser.
Also, after I download and install as3webservice.mxp, it does not show those 3 classes:
WebService, Operation and OperationEvent
that mentioned in http://www.wellconsidered.be/as3-webservice-component/
How should I fix it?
Please find the source code here:
http://www.cataclysmicrewind.com/flash/be.rar
I have zipped the package from my machine.
Try those.
Also, I have never had the 'pleasures' of testing any SWF files with a local Web Service running. I have always worked with them live. I do not know if that would effect anything but it could?
sorry, may I ask how can I include those *.as files into library in Flash CS3?
and do I just import them
import be.wellconsidered.services.WebService;
import be.wellconsidered.services.Operation;
import be.wellconsidered.services.events.OperationEvent;
in my flash code?
The class files do not go inside of the library. You only need to import them into your code.
do I include them
#include "WebService.as"
#include "Operation.as"
#include "webservice\WebServiceResponse.as"
...
nope. just as the example code I gave you.
import be.wellconsidered.services.WebService;
import be.wellconsidered.services.Operation;
import be.wellconsidered.services.events.OperationEvent;
I unzip your files to the fla directory.
C:\workspace\flashws\be\wellconsidered\services
flashws.fla is put under C:\workspace\flashws
I changed to use a public IP for the webservice
http://201.125.124.210/WebService/Service.asmx?wsdl
I can open it in any browser. 201.125.124.210 is an example.
But, when I run the flashws.swf, it still shows
Error opening URL 'http://201.125.124.210/WebService/Service.asmx?wsdl'
[IOErrorEvent type="ioError" bubbles=false cancelable=false eventPhase=2 text="Error #2032: Stream Error. URL: http://201.125.124.210/WebService/Service.asmx?wsdl"]
If that IP is supposed to be public, and it is still running now, I can't hit it.
Finally I can call the webservice without error after rebooting the machine.
Now, I have the question to get return value from webservice.
op.checkLogin("username","password");
It should return 1 for successful login and 0 for failure.
In the code:
Q.1 How can I get the return value?Code:function onResult (e:OperationEvent):void {
for (var prop in e.data){
trace (e.data[prop]);
}
}
function onFault (e:OperationEvent):void {
trace (e.data);
}
Q.2 This code places in frame 1, if the return value is 1, then how can it move to frame 2? If return value is 0, just stay on frame 1.
Thanks for your great help.
By the way, if I declare the var for the return value in frame 1 as code, can I get it in frame 2 as code? or I need to pass it to frame 2 as code?
Because the return value needs to be re-used across several frames' as code.
One trick that I use when working with Web Services in AS3 is to have an AS2 document open so you can use the WebService Panel. Let me explain.
The WebService Panel in Flash IDE is built for AS2 only. As such, the WebService panel will only work if the document you are working on is also AS2.
My suggestion is to open a brand new AS2 document.
Open the WebService Panel. (Window > Other Panels > Web Service)
Add your WSDL to the panel.
Once you have done this you get an awesome tree view of all of your methods, and what it returns.
From there you can see how to reference the variables being sent back from the Web Service.
To explain further, put the WSDL for the weather Web Service that I gave in the example code earlier. In the panel you will see a globe icon labeled WeatherForcast
If you expand it, you will see two (2) methods.
Expand the first method GetWeatherByZipCode.
You will then see the parameters you need to pass and the results.
Expand the results. It is saying you will receive an Object with a few numbers, a few strings, and an array.
Remember that this AS2 document is just so you can use the Web Service Panel.
In your onComplete method, e.data = the return object. So,
If you wanted to get the Latitude of the results you would say e.data.Latitude.
This process should get you the return information for the Web Service you are using.
Once you find the variable name, switch back to your AS3 document and try to trace it out: trace (e.data.variableName) *Or whatever your WSDL instructs*
As for your second question.
Using the timeline makes data storage a bit more tricky, however I will tell you the easiest way to hold on to that information throughout your movie.
Add a new Layer on the timeline.
Make it have one (1) keyframe that spans ALL frames in the timeline. (IF you have ten (10) frames, make that new layer have a frame in all ten with only on keyframe.
With that layer selected open the actions panel, and add a line of code that declares a variable such as :
var loginResults;
You are creating a variable that is called loginResults that will exist through all frames on the timeline.
Back in the layer where you have the WebService code, in the onComplete function, you want to save the information returned. You would do this by referencing the variable we created in the other layer and saving the results to it:
The next thing, to find out if the login failed or succeeded, you will want to use an if statement.Code:function onResult (e:OperationEvent):void {
loginResults = e.data; //remember to include the name of the var returned according to the WSDL
}
If the result = 1, login success otherwise login fail.
This code will look like this:
Altogether the code will look SOMETHING like this:Code:if (loginResults == 1){
//login success go to frame 2
gotoAndStop(2);
} else {
//login fail, put the appropriate code here
}
Code:function onResult (e:OperationEvent):void {
loginResults = e.data; //remember to include the name of the var returned according to the WSDL
if (loginResults == 1){
//login success go to frame 2
gotoAndStop(2);
} else {
//login fail, put the appropriate code here
}
}
I opened a as2 doc in Flash CS3, add the ws and can see the method that i need to call
there are 2 parameters that i need to pass, username and password
the return is:
results : Integer(int)
Then, I tried to use e.data.results
Here is the error:Code:var loginResult:int = 0;
op.CheckLogin("username","password");
function onResult (e:OperationEvent):void {
loginResult = e.data.results;
trace(loginResult);
}
ReferenceError: Error #1069: Property results not found on Number and there is no default value.
at flashws_fla::MainTimeline/onResult()
at flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunctio n()
at flash.events::EventDispatcher/dispatchEvent()
at be.wellconsidered.services::Operation/dispatchEvent()
at be.wellconsidered.services::Operation/::onServiceLoaded()
at flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunctio n()
at flash.events::EventDispatcher/dispatchEvent()
at flash.net::URLLoader/flash.net:URLLoader::onComplete()
So, it has problem in getting the Latitude of the results you would say e.data.Latitude
I need to fix that and able to go to the second question.
Thanks for help