[swx] How to make flash wait for xml to load before using it

ben ben_da_dog at yahoo.co.uk
Sat Mar 8 23:30:11 PST 2008


Hi Jake,

I think you're going about it a bit the wrong way. It's best if you just 
instance a SWX object and specify your result handler. You don't need a 
timer.
The second thing i'm not sure either is why you want some XML? One of 
the major advantage of SWX (in my humble opinion) is that you don't have 
to deal with any daaaamn XML, and in particular parsing it in AS2, which 
totally sucks. Do you really need XML? You can send arrays of objects or 
nested objects back and forth with SWX.

Here's a sample, most basic code to use a SWX service:

/import org.swxformat.SWX;/

/var swx:SWX = new SWX();/
/swx.gateway = "http://<path_to_your_swx_gateway";/
/swx.encoding = "GET";/
/swx.debug = true;/
/ /
/var callParameters:Object =/
/{/
/    serviceClass: "YourService",/
/    method: "serviceMethod",/
/    args: [0],/
/    result: [this, resultHandler],/
/    timeout: [this, timeoutHandler],/
/    fault: [this, faultHandler]/
/}/
/// /
/function resultHandler(event:Object)/
/{/
/    trace("result!");/
/}/
/function timeoutHandler(event:Object)/
/{/
/    trace("timeoutHandler!");/
/}/
/function faultHandler(event:Object)/
/{/
/    trace("faultHandler!");/
/}/

/swx.call(callParameters);

/ /stop();/

The object is created, given some result, timeout & fault event 
handlers, then the call is made, then stop.
When the result comes through, resultHandler is triggered, or fault or 
timeout if any error occurred.
Consult the docs for more details.

Hope that helps. Good luck.

Ben
Down with XML!

Jake Ketcheson wrote:
> Hey everybody,
>
> I've been having some problems trying to grab and parse xml coming back 
> to me from a custom php script.. I'm relatively new to Flash and Action 
> Scripting, so this may just be easily fixable..
>
> So my problem is I send off a request to my class from flash, which is 
> suppose to just return to me a simple xml string.. From there I want to 
> be able to parse the string out, and loop through the children to create 
> elements on the flash file..
>
> My actionscript is as follows:
>
> stop();
> import mx.utils.Delegate;
> System.security.allowDomain('*');
> var checkLoadProgressInterval;
> var openStores_xml
> function preparexml(){
>     dataHolder.serviceClass = "Store";
>     dataHolder.method = "GetStoreHours";
>
>    
>     dataHolder.debug = true;
>
>        dataHolder.loadMovie("------(removed for confidentiality 
> reasons)", "GET");
>     checkLoadProgressInterval = setInterval(this, "checkLoadProgress", 250);
>    
>
>    
> }
> function checkLoadProgress()
> {
>     if (dataHolder.getBytesLoaded() > 24 && (dataHolder.getBytesLoaded() 
> == dataHolder.getBytesTotal()))
>    {
>        clearInterval(checkLoadProgressInterval);
>        resultHandler(dataHolder);
>    }
> }
> function resultHandler(event:Object)
> {
>     // Load is complete.
>    
>    
>     // Display the result.
>     openStores_xml = event.result;
>     test.text = openStores_xml;
> }
> function XMLopenStores() {
>    
>    
>     stores = [];
>     opens = [];
>     openStores = openStores_xml.firstChild.childNodes[0];
>     total = openStores.childNodes.length;
>     for (i=0; i<total; i++) {
>         stores[i] = 
> openStores.childNodes[i].childNodes[0].firstChild.nodeValue;
>
>         opens[i] = 
> openStores.childNodes[i].childNodes[1].firstChild.nodeValue;
>
>     }
>    
> }
> preparexml();
> XMLopenStores();
> trace(stores[1]);
> trace(opens[1]);
>
> count = 1;
>
> storeBox0.num=0
> while (count<total) {
>     this.storeBox0.duplicateMovieClip("storeBox"+count, count);
>     //this["storeBox"+count]._y = count*45+40
>     this["storeBox"+count].num= count
>     count += 1;
>    
>
> }
>
> Now the problem is I know its returning the right data, since my test 
> field gets filled with the xml coming back from the class.. But when it 
> comes down to the looping of the children from the xml in 
> XMLopenStores() I'm getting undefined errors from the trace().. Now I 
> assume this is because its going through the loop before the data is 
> actually loaded into the variable.. So how do I make it wait for that 
> variable to be full of data before using it? Or am I going about this in 
> an entirely incorrect way?
>
> Thanks for any and all help you guys could provide for me!
>
> _______________________________________________
> swx mailing list
> swx at osflash.org
> http://osflash.org/mailman/listinfo/swx_osflash.org
>
>   

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://osflash.org/pipermail/swx_osflash.org/attachments/20080309/c21799ac/attachment.html 


More information about the swx mailing list