[swx] How to make flash wait for xml to load before using it
Jake Ketcheson
jake at fiveht.com
Sun Mar 9 01:11:31 PST 2008
I'm using XML because the classes were originally written to spit back
XML.. I played with it a bit more after I sent off the email and got it
working using the swx library.. And after a good night of leisure it
struck me that using XML was a mistake from the beginning (I believe the
native way would be JSON? If not is there any tutorials out there of how
to format data back?). Unfortunately the budget and time constraints
leave me stuck with how it was originally done, but I'll definitely
bring it up in the next round of updates.
Thanks a huge amount for the reply back though.. If anything I've found
the support out there for action scripting is second to none.
ben wrote:
> 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
>>
>>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> swx mailing list
> swx at osflash.org
> http://osflash.org/mailman/listinfo/swx_osflash.org
>
More information about the swx
mailing list