10 Replies Latest reply on Jan 21, 2007 7:15 AM by Newsgroup_User

    how to fix asynchronous communication between fscommand and javascript

    -Darius-
      Hi all, I'm using fscommand to get a Value into Flash and modify it.

      Everytime Flash doesn't recognize the value because
      Flash doesn't wait and the value isn't filled at the modification process.

      So i found a solution with Buttons, but i want to let this litlle demo-code (attached) run without Buttons.
      Is there a way to insert a short pause or something like in java thread.sleep(xxx)?

      Maybe it's also a problem with the SCORM-API (But that is not the point)

      I hope you can help me,

      Kind regards,
      Darius
        • 1. Re: how to fix asynchronous communication between fscommand and javascript
          Level 7
          Darius,

          > Is there a way to insert a short pause or something like in java
          > thread.sleep(xxx)?

          There's no sleeping in ActionScript. But you can wait before triggering
          functions with setInterval() (use its partner clearInterval() to keep the
          triggering from repeating) or the valid-but-undocumented setTimeout(). (The
          only reason it's undocumented is that it was left out of the Help docs
          inadvertently.) These functions both work similarly to their JavaScript
          counterparts.

          What may be better for you, if you have flexibility in the Flash Player
          you publish for, is the ExternalInterface class. Have you checked that out?


          David Stiller
          Adobe Community Expert
          Dev blog, http://www.quip.net/blog/
          "Luck is the residue of good design."


          • 2. how to fix asynchronous communication between fscommand and javascript
            -Darius- Level 1
            Thanks for the hint.
            I tried to use functions and the setInterval-method, but it doesn't seem to work. (I always receive: undefined as value)

            Does someon see the mistake (code attached)?

            Regards, Darius
            • 3. Re: how to fix asynchronous communication between fscommand and javascript
              Level 7
              Darius,

              > I tried to use functions and the setInterval-method, but
              > it doesn't seem to work.

              setInterval() works; it just may not work the way you expect. ;)

              > Does someon see the mistake (code attached)?

              It's probably best, if you step away from this current project -- just
              for a moment -- and make a small, self-contained setInterval() test on its
              own, first. Once you figure out how that function works -- once you master
              it -- that's when you might carry that knowledge back to the more complex
              code you already have.

              > var f:String="";
              >
              > function getSCORMData():String{
              > fscommand("LMSGetValue","cmi.suspend_data,returnval");
              > return f=returnval;
              > }

              This return statement is returning the value of the following expression
              ...

              f = returnval

              ... which is an assignment. As long as it's possible to set f (is this a
              variable?) to returnval, the expression f=returnval will always resolve to a
              Boolean true. Which means getSCORMData() will always return true. Not sure
              if that's what you're after.

              > setInterval(setSCORMData("A"),10000);

              In this line, you're apply the parentheses operator to the getSCORMData
              object. getSCORMData is a function, and it's set in motion by the ()
              operator. So even though it looks like you want this to fire off in ten
              seconds (10,000 milliseconds), you're firing it off immediately. Note, too,
              that the setInterval() function accepts parameters at the end, rather than
              between the parentheses (which, again, shouldn't be present, here).

              What you need is more along the lines of this:

              setInterval(setSCORMData, 10000, "A");


              David Stiller
              Adobe Community Expert
              Dev blog, http://www.quip.net/blog/
              "Luck is the residue of good design."


              • 4. Re: how to fix asynchronous communication between fscommand and javascript
                -Darius- Level 1
                quote:

                n this line, you're apply the parentheses operator to the getSCORMData
                object. getSCORMData is a function, and it's set in motion by the ()
                operator. So even though it looks like you want this to fire off in ten
                seconds (10,000 milliseconds), you're firing it off immediately.


                I think that is the main mistake, how can I let the Flash wait 10 seconds to start a function?

                Big thanks for you answers!

                P.S: I also tried the ExternalInterface-method, this seems to be asynchronous, too...no value captured (code attached)
                • 5. Re: how to fix asynchronous communication between fscommand and javascript
                  Level 7
                  Darius,

                  > I think that is the main mistake, how can I let the Flash wait
                  > 10 seconds to start a function?

                  Read that last reply of mine. ;)


                  David Stiller
                  Adobe Community Expert
                  Dev blog, http://www.quip.net/blog/
                  "Luck is the residue of good design."


                  • 6. Re: how to fix asynchronous communication between fscommand and javascript
                    Level 7
                    >> I think that is the main mistake, how can I let the Flash wait
                    >> 10 seconds to start a function?
                    >
                    > Read that last reply of mine. ;)

                    I should add: make sure you understand clearInterval(), so that your
                    setInterval() triggering doesn't occur more often that you want it to.


                    David Stiller
                    Adobe Community Expert
                    Dev blog, http://www.quip.net/blog/
                    "Luck is the residue of good design."


                    • 7. how to fix asynchronous communication between fscommand and javascript
                      -Darius- Level 1
                      quote:

                      Originally posted by: Newsgroup User
                      Darius,

                      > I think that is the main mistake, how can I let the Flash wait
                      > 10 seconds to start a function?

                      Read that last reply of mine. ;)


                      David Stiller
                      Adobe Community Expert
                      Dev blog, http://www.quip.net/blog/
                      "Luck is the residue of good design."





                      It would be helpful if you could post a sample or modify my code, to create a delay ;)
                      Maybe setInterval is the wrong command

                      Refards, Darius
                      • 8. Re: how to fix asynchronous communication between fscommand and javascript
                        Level 7
                        Darius,

                        >>> how can I let the Flash wait 10 seconds to start
                        >>> a function?
                        >>
                        >> Read that last reply of mine. ;)

                        > It would be helpful if you could post a sample or
                        > modify my code, to create a delay ;)

                        I did! That's why I said to read over my previous reply. :) I showed
                        you where your syntax went awry, then restated one of your setInterval()
                        calls that way it should appear.

                        Have you experimented yet in a new FLA? I'm not trying to toy with you,
                        I promise. At this point, I think it will help you more to find the answer
                        that's already here in this thread. Part of troubleshooting and problem
                        solving means taking a closer look. ;)


                        David Stiller
                        Adobe Community Expert
                        Dev blog, http://www.quip.net/blog/
                        "Luck is the residue of good design."


                        • 9. Re: how to fix asynchronous communication between fscommand and javascript
                          -Darius- Level 1
                          Allright!
                          I've found a solution.

                          It's a little bit quick&dirty, but it works ;)

                          If someone see some improvement in changing the code, please feel free to modify and post it ;)

                          Regards, Dary
                          • 10. Re: how to fix asynchronous communication between fscommand and javascript
                            Level 7
                            Darius,

                            > Allright!
                            > I've found a solution.

                            Great! :)

                            > It's a little bit quick&dirty, but it works ;)

                            That's the important part, is moving ahead. If you find the time, look
                            for ways to improve a solution -- but "it works" is certainly good. :) A
                            setInterval() or setTimeout() approach would require fewer lines, which
                            would arguably make one of those the quicker choice -- nothing really
                            "dirty" in your code, that I can see. ;) I'm surprised, actually, that you
                            found this approach easier than figuring out setInterval(), especially since
                            my replies contained or linked to sample code. But hey, you overcame an
                            obstacle, and programming is often comprised of nothing more than that.


                            David Stiller
                            Adobe Community Expert
                            Dev blog, http://www.quip.net/blog/
                            "Luck is the residue of good design."