How To Populate Dynamic Text in Flash from a Web Service?
I have a MS Access query ProductDetailsAll that is queried using an ASP.net web service. The service simply fills a data table with query results.
How do I setup and pass parameters from Flash? I need to sear ProductDetailsAll for records having CategoryID 1 or 3 based on use开发者_运维知识库r selection. How is the CategoryID passed from Flash to the web service?
I have created rectangle objects in Flash. Each one must contain product name, description, price and the image from the ProductDetailsAll query. How do I pass the search phrase from Flash to the query? Do I use dynamic text boxes to house the returned values?
Thanks, Sid
EDIT To elaborate further: I have a combo box cbRentalType with values 1 (Sale), 3 (Party) or All. I have a combo box cbCatSelect that needs to read the SubCategory from the database table. I have a textbox txtSearch that will house the product keyword and should be queried from the KeywordID field in the database table.
How do I set outbound variables in Actionscript equal to the values of the above objects? How do I return query results matching these values and map them into Flash variables? I have 16 rectangle objects on the movie clip. Each one will house one item from the query result with output of product image, product name, description and price. If the query returns more than 16 records, how do I populate another frame to contain the full query result?
Finally, I found a code sample that is used to setup the ASP.NET web service connection. The AS3 code is as follows:package {
import flash.display.MovieClip;
import flash.events.MouseEvent;
import mx.rpc.soap.*;
import mx.rpc.events.*;
import mx.rpc.AbstractOperation;
import flash.events.Event;
public class MainDocument extends MovieClip {
private var ProductWebService:WebService;
private var serviceOperation:AbstractOperation;
public function MainDocument() {
// constructor code
addEventListener(Event.ENTER_FRAME, SetupWebService);
}
function SetupWebService(event:Event):void
{
var url:String ="http://www.mydomain.com/WebService/completedb.asmx?WSDL";
ProductWebService = new WebService();
ProductWebService.loadWSDL(url);
ProductWebService.addEventListener(LoadEvent.LOAD,BuildServiceRequest);
}
function BuildServiceRequest(evt:LoadEvent)
{
serviceOperation=ProductWebService.getOperation("GetProducts");
serviceOperation.addEventListene
(FaultEvent.FAULT,DisplayError);
serviceOperation.addEventListener
(ResultEvent.RESULT,DisplayResult);
serviceOperation.send([GenerateRandomNumber(0,9)]);
}
function DisplayError(evt:FaultEvent)
{
trace("error");
}
function DisplayResult(evt:ResultEvent)
{
var productName:String = evt.result as String;
productText.Text=productName;
}
function GenerateRandomNumber(min:int,max:int):int
{
return Math.floor(Math.random()*(1+max-min))+min;
}
}
}
The specific solution is difficult to see from an outside perspective, but it's safe to say that you'll need to work with the URLRequest class and the URLLoader class.
The basic idea is that to communicate from flash to your server-side script (ASP), you want to POST data to that script by taking flash variables (strings, numbers) adding them to your URLRequest object's .data property, and then using a URLLoader class to 'send' that data to your asp script.
Here's a tutorial that discusses this with PHP - the concepts remain the same in ASP: http://www.kirupa.com/forum/showpost.php?p=2373966&postcount=1
To communicate from your script back to flash, you'll want to use the same basic technique, but use the onComplete callback (described above) in flash to access your data.
A common headache you might hit, should the flash & asp live on different servers, is a crossdomain security issue. You might need to set up the appropriate privileges via a crossdomain.xml file.
...and Yes, you'll want to use dynamic textfields and set their .text (or .htmlText) properties to the results of your ASP page, somewhere in your onComplete callback.
Hope this helps - good luck
精彩评论