views:

47

answers:

1

I'm working on a little blog app in flash and can't seem to load any variables with html embedded. Is there a way around this? flash code:

var urlLoader:URLLoader = new URLLoader(new URLRequest(path + "index.php"));
urlLoader.addEventListener(Event.COMPLETE, showData);

function showData(e:Event):void
{
    var dataObj:URLVariables = new URLVariables( e.target.data );

    trace(dataObj.title); // would traces fine
    trace(dataObj.content); // throws error
}

index.php is:

<?php
$results = "title=this is my title and will print fine";
$results .= "&content=This will cause an error <b>Because of these html tags</b>";
print $results
?>

I can't be the first guy in history looking to take advantage of some html in my passed variables, I've heard of AMFPHP, but am hoping there is a more simple solution, like:

flash_encode($myVar);

(similar to json_encode);

Thanks for the input. -J

+2  A: 

You could try urlencode the vars in your PHP script. Then, inside flash you can use unescape ( or also decodeURI?)

With AMFPHP you send type-persistent objects to/from flash, not only string.

Also, you could use JSON, there are libraries such as as3CoreLib that provide JSON decoding to flahs.

goliatone
Personally I would just strongly avoid URLVariables for complex structures. XML(+CDATA) or JSON are definitely more adequate for this.
Theo.T
Agree, although I would add that if you are making your own services AMFPHP or similar would be even better. Faster transfer and typed object in the results are cool. But for small stuff xml/JSON...
goliatone
JSON works PERFECTLY. Very excited now. Thank you.
Jascha