3 Replies Latest reply on Aug 28, 2008 1:48 AM by pete.h

    sending flash variables

    farazfo
      I have imported a flash file inside director...
      how can I access the variables which I used in the flash, through director?
      how can I send the variables from flash movie to the director?
      I used this command in the flash movie on a button:
      on (release) {
      getURL("event: FlashMouseEnter, \"hi\"");
      }
      but I could not send variables with this command! only the strings
      what should I do about variables?
        • 1. sending flash variables
          pete.h Level 1
          This is how I do it (this is from my memory, so I haven't tested this exact code):
          --------------------------------------------
          ACTIONSCRIPT :
          //(At the start of your script)
          // set up the listener that passes the event and variables to Director...
          var directorListener:Object = new Object();
          directorListener.handlerName = function(evt_obj:Object):Void { }

          //(At the end of the first frame of you script)
          if (System.capabilities.playerType == "DirectorXtra") {
          getURL("event:flashLoaded"); // Director can now do stuff with the flash object!
          } else {
          // commands to test swf outside of Director go here...
          }

          --------------------------------------------
          In LINGO, in the Flash sprite behaviour:

          on flashLoaded me
          //set up an intercept of any calls to the directorListener function...
          sp=sprite(spriteNum)
          listener=sp.directorListener
          sp.setCallBack(listener, "handlerName", #lingoHandler, me)
          end

          on lingoHandler me,directorListener,flashVariables
          put flashVariables.type
          put flashVariables.target._x
          put flashVariables.selectedIndex
          end
          --------------------------------------------
          Then, back in ACTIONSCRIPT, to pass Flash variables, not string values, use this code:
          --------------------------------------------
          //call the function in the directorListener event
          directorListener.handlerName ({type:"select", target:this, selectedIndex:23}); //the props in the Flash assoc. array can be anything! Add as many as you need. This is the object that gets passed as the 3rd parameter into your Lingo hander.

          For more on Flash<->Director variable passing and events, see this post
          • 2. Re: sending flash variables
            farazfo Level 1
            thank you veryyyy much :)
            one more question
            now I know how to call a function and send variables to director through flash
            but how can I call a function that I've written in flash through director?
            • 3. sending flash variables
              pete.h Level 1
              farazfo: That's the wonderfully simple part....

              ACTIONSCRIPT:

              function myFlashFunction(someNumber){ //code goes here}

              To call it in Lingo, just use:

              sprite(spriteNum).myFlashFunction(5)

              ...where sprite(spriteNum) is a reference to the Flash asset containing the AS function.

              Also, see the post I linked to in my previous post, for examples of passing Lingo Lists by converting to AS Arrays, and vice versa.