5 Replies Latest reply on Jan 30, 2010 1:24 AM by TimDixon

    passing variables to flash




      Can someone explain quite simply how to pass an array (list) from director to a flash sprite on the stage?


      I can send single variables, but I need to send a list (it's actually a nested list).



      I'm sure this is something that requires the flash object asset to to, but can someone explain the lingo code and the actionscript code thats required.



      [PS. using Director MX2004, but may be upgrading to 11.5 - OS is windows xp]






        • 1. Re: passing variables to flash
          robdillon Most Valuable Participant

          Using AS 2, you can pass an array from Flash to Director using getVariable(). There are a bunch of gotcha's however. The original array in Flash will need to be a simple array. It can contain any type of value, strings or numbers or mixed. When Director imports the value, it will give you a series of strings separated by commas, similar to the Array.toString() method in Actionscript.


          So, if in Flash you have something like this:


          var myList:Array = new Array("one",13,"howdy");


          and then in Director you have something like this:


          on mouseUp me
            newVar = sprite(1).getVariable("myList", true)
            put newVar


          you should see:




          in the message window.


          So, you'll have some work to do to get this into a list in Director. If you have a nested array, you'll have to break it up and send it one chunk at a time and then reassemble it in Flash.

          • 2. Re: passing variables to flash
            TimDixon Level 1

            Thanks for the reply Rob!


            My problem is actually the other way though - I need to send a list from director to flash - Is it the same kind of issues? (I have Director collecting data and need flash to display this in a kind of table format. The amount of data varies each time.


            I'm sure I read a while back that using the flashObject in Director it was possible to create a flash array directly - But I can't seem to find any documentation on this - or more importantly, how to handle this array from the flash file imported into director!!



            Any ideas?

            • 3. Re: passing variables to flash
              robdillon Most Valuable Participant

              Sorry, I should have read more closely. This is probably the article that you were trying to find: http://www.adobe.com/devnet/director/articles/flash_in_director_5.html

              • 4. Re: passing variables to flash
                Production Monkey Level 3

                The code you want is probably something like:

                temp = sprite(1).newObject("Array", "one", "two", 3, 4)
                sprite(1).createVariable(#lisa, temp)
                put sprite(1).lisa[1]
                -- "two"

                Or use "sprite(1).setVariable(#lisa, temp)

                You should also read up on "convert()" and "propDirectAccess"

                Funny thing though. While key words like "convert" are not in the D10 help because they are part of the 10.1.1 update, they also don't seem to be listed in the D11.5 help which I just checked.

                The following pdf has the information you need. The last two sections pertain to your needs.


                Most importantly : Do not downgrade to D11.5 unless your really, really have to for some reason.

                • 5. Re: passing variables to flash
                  TimDixon Level 1

                  Hi All,


                  Just for anyone else looking for an answer to this, here's the simplest way I found to pass lists/arrays between flash and Director....


                  NOTE: I'm using an undocumented 'convert' function that is only available in Director 10.1.1 onwards...


                  ------------------------------------------------------------------------------------------ --------------

                  -- This GETS an array from Flash to Director

                  -- 'myFlashArray' is the name of the array in your Flash file

                  -- 'flaArray' is the new list created in Director

                  -- And obviously, the flash file is on sprite 1


                    flaArray = convert(#list, sprite(1).myFlashArray)

                    put flaArray


                  ------------------------------------------------------------------------------------------ --------------

                  -- This SENDS a Director list to flash (as an array)

                  -- 'zz' is just a temporary variable so the script is easier to read

                  -- 'dirList' is your Director List

                  -- 'myNewFlashArray' is the name of the newly created array in your flash file

                  -- again, the flash file is on sprite 1 in this case



                    dirList = ["item 1","item 2","item 3"]

                    zz = convert(#flashObjectArray, dirList).toString()

                    sprite(1).createVariable(#myNewFlashArray, zz )


                  ------------------------------------------------------------------------------------------ --------------


                  Hope this helps someone else too!