AS3 Compile error to call WS

techques
techques used Ask the Experts™
on
I have a AS3 need to call 2 functions in a WS to get 2 return parameters.

But, it has

Compile Error:
1046: Type was not found or was not a compile-time constant: OperationEvent.
function onResult(e:OperationEvent):void {
function onFault(e:OperationEvent):void {
function onResult1(e:OperationEvent):void {
function onFault1(e:OperationEvent):void {

function GetStreamName(opName:String) {
   var ws = new WebService("http://[publicip]/WebService/Service.asmx?wsdl");
   var op:Operation = new Operation(ws);   
   op.addEventListener(OperationEvent.COMPLETE, onResult);
   op.addEventListener(OperationEvent.FAILED, onFault);
   op.CheckStreamName(opName);
}
 
function onResult(e:OperationEvent):void {	      
   for (var prop in e.data){
		   trace (e.data[prop]);
   }
   streamName = String(e.data);
}
   
function onFault(e:OperationEvent):void {
	trace (e.data);
	prompt.text = "Fail";
}
 
function GetOpID(opName:String) {
   var ws = new WebService("http://[publicip]/WebService/Service.asmx?wsdl");
   var op:Operation = new Operation(ws);   
   op.addEventListener(OperationEvent.COMPLETE, onResult1);
   op.addEventListener(OperationEvent.FAILED, onFault1);
   op.CheckOpID(opName);
}
 
function onResult1(e:OperationEvent):void {	      
   for (var prop in e.data){
		   trace (e.data[prop]);
   }
   OpID = String(int(e.data));
}
   
function onFault1(e:OperationEvent):void {
	trace (e.data);
	prompt.text = "Fail";
}

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2009

Commented:
are you using some external class that has an Operation and OperationEvent?
you need to import it if so.

Author

Commented:
I imported those as source files.

1046: Type was not found or was not a compile-time constant: WebServiceCall.

1180: Call to a possibly undefined method WebServiceCall.

Author

Commented:
I can import the as files.

I use http://www.wellconsidered.be/as3-webservice-component/

There are 3 methods in a webservice.

I can call the first method from AS3. However, I cannot call the 2nd and 3rd methods and have the following error:

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at be.wellconsidered.services.webservice::WebServiceC all/::createSoapCall()
at be.wellconsidered.services.webservice::WebServiceC all$iinit()
at be.wellconsidered.services::Operation/loadMethod()
at be.wellconsidered.services::WebService/::executeQeuedOperations()
at be.wellconsidered.services::WebService/:nDescrExtractComplete()
at flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunctio n()
at flash.events::EventDispatcher/dispatchEvent()
at be.wellconsidered.services.webservice::WebServiceM ethodCollection/extract()
at be.wellconsidered.services::WebService/:nDescrLoaded()
at flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunctio n()
at flash.events::EventDispatcher/dispatchEvent()
at flash.net::URLLoader/flash.net:URLLoader:nComplete()
Success in ‘20 With a Profitable Pricing Strategy

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Top Expert 2009

Commented:
ok i've used that component before, no problems.
where are you calling the methods vs. where they are defined.
what the code is saying is it can't find what you're refering to.

Author

Commented:
Since I use Flash CS3 which does not support web service panel, I open a Flash AS2 file, add the WSDL and the webservice panel can locate the webservice and display 3 web methods in a tree view.
CheckUserRole()
CheckUserName()
CheckUserCredit()

I put the as3webservice source code with the same folder of the fla.

In the first frame, the following is the as3 code.

When I run it in Flash CS3, it has the above Error #1009.

I think it cannot find the web methods:
CheckUserName()
CheckUserCredit()

It can only find the web method: CheckUserRole()

Does as3webservice only support one web method?

Or, I did not import as3webservice properly and so it cannot recognize the other 2 web methods?




import be.wellconsidered.services.WebService;
import be.wellconsidered.services.Operation;
import be.wellconsidered.services.events.OperationEvent;
 
GetUserName("12");
 
function GetUserName(UserID:String):void {
   var ws = new WebService("http://[publicip]/WebService/Service.asmx?wsdl");
   var op:Operation = new Operation(ws);   
   op.addEventListener(OperationEvent.COMPLETE, onResult);
   op.addEventListener(OperationEvent.FAILED, onFault);
   op.CheckUserName(UserID);
}
 
function onResult(e:OperationEvent):void {       
   for (var prop in e.data){
     trace (e.data[prop]);
   }
   userName:String = String(e.data);
}
   
function onFault(e:OperationEvent):void {
 trace (e.data);
 prompt.text = "Fail";
}
 
 
GetUserCredit("12");
 
function GetUserCredit(UserID:String):void {
   var ws = new WebService("http://[publicip]/WebService/Service.asmx?wsdl");
   var op:Operation = new Operation(ws);   
   op.addEventListener(OperationEvent.COMPLETE, onResult1);
   op.addEventListener(OperationEvent.FAILED, onFault1);
   op.CheckUserCredit(UserID);
}
 
function onResult1(e:OperationEvent):void {       
   for (var prop in e.data){
     trace (e.data[prop]);
   }
   userCredit:int = int(e.data);
}
   
function onFault1(e:OperationEvent):void {
 trace (e.data);
 prompt.text = "Fail";
}

Open in new window

Top Expert 2009
Commented:
the idea of opening it and doing something in  AS2 and then doing something in aS3 scares me.

here's a sample from my code
import be.wellconsidered.services.WebService;
import be.wellconsidered.services.Operation;
import be.wellconsidered.services.events.OperationEvent;
 
 
var ws = new WebService(serverIP + "/Main.asmx?wsdl");
var tempArr:Array = new Array();
var op:Operation = new Operation(ws);
op.addEventListener(OperationEvent.COMPLETE, onResult);
op.addEventListener(OperationEvent.FAILED, onFault);
 
then in my doOperation i use a case statement to handle the different operations.
 
doOperation("checkUser");
 
etc.

Open in new window

Author

Commented:
Then, how do you use as3webservice in Flash CS3 which does not support web service panel?

How do you use tempArr?

Do you know how to add as3webservice and those 3 web methods of that WSDL in Flash AS3?


Top Expert 2009

Commented:
i take it you got it? i dont' use the panel just do the stuff in code. Use to do that in AS2 as well.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial