views:

391

answers:

4

How to recive an array from flash vars?

So I have HTML page. with flash app on it. I vant to send an array to flash. How to do such thing using flashVars (I have something like uid=12&sid=12&sid=32&sid=12&sid=32) so i need to get dinamic\random\beeg\unnown number of Sid's not losind UID how to du such thing?

btw I want to pass in an array of values and have it recognized by Flash as an Array object; For example, with POST and GET requests an array is formed as "field[]=value&field[]=value" etc.

+1  A: 

I'm confused, you want to send parameters to your flash movie or receive? And if you want to send them as I suspect, how are they produced in the first place? Is it from an HTML form on some other page? You can use PHP for this or JavaScript that will construct your HTML with the parameters passed.

// write flash obj with query string
function writeFlash() {
    // appearance vars, these can be customized to your liking
    var width = '200'
    var height = '100'
    var src = 'query.swf'
    // queries -- type in the variables you want to send to flash here
    var queries = '?uid='+QueryString('uid')+'&sid='+QueryString('sid')+''

    // assemble flash obj
    var l1 = '<object width="'+width+'" height="'+height+'" data="'+src+queries+'" type="application/x-shockwave-flash"><param name="quality" value="high" /><param name="src" value="'+src+queries+'" /></object>'

    // write all lines
    document.write(l1+l2+l3+l4+l5)
}

This is your answer in JavaScript, taken from http://noscope.com/journal/2003/12./query_string and slightly modified.

C. Papadopoulos
Kevin
A: 

In this situation, I usually create a dynamically generated XML file and pass the url to it as a flashvar.

The reason I prefer XML is that I hate having to write extra javascript which encodes the flashvars and then extra actionscript to parse them. However, if your flash app is very simple and you don't plan on adding many arrays/relationships to it then ignore my answer. :)

Kevin
-1, overkill for this question.
Sam
Depends on the situation; IMO binding to an XML document is more straightforward than encoding some delimited list and splitting it in the flash app.
Kevin
+1  A: 

If you could join the sid's into a comma-delimited string, then you could split them in the actionscript.

adamcodes
A: 

"How to recive an array from flash vars?"

Application.application.parameters.

jeremy.mooer