13 Replies Latest reply on Nov 16, 2006 8:34 AM by 2m

    FlashVars

    cutie369 Level 1
      Isn't there at least one big strong man who can help me with this.

      I do have a question in regards to FlashVars and how you test for the existance of a certain value inside a SWF movie?

      This code right here works fine for me.
      if (_level0.myURL == undefined) {

      }
      else {
      pflipper.gotoPage(3);
      gotoAndStop(1);
      }

      However, it is not what I need. I want to be able to setup an if statement with multiple else if statements. I have tried almost every possible combination except the correct one.

      Here is what I would like to do. If _level0.myURL == 1 then gotoPage(1) & gotoAndStop(1) else if _level0.myURL == 4 then gotoPage(2) & gotoAndStop(4)

      Can you please tell me what is the correct syntact for doing this.
        • 1. Re: FlashVars
          arunbe Level 1
          I think, the way you are using now is the general.
          Otherwise you can trace all the varialbles in the _root.
          like this...
          for ( i in _root)
          {
          trace(i);
          }

          But, in this case, you know the FlashVar name, so you can use like this....
          No other easiest way , I think......
          • 2. Re: FlashVars
            cutie369 Level 1
            Can anyone help me how to develop this for loop. I am not familiar with how to construct it. Also, I am not able to run trace while the swift is in an HTML page..

            for ( i in _root)
            {
            trace(i);
            }
            • 3. Re: FlashVars
              arunbe Level 1
              hi,
              this for loop is just to detect the variables and objects used in the main file.
              So , you can use this just to idenfy the the variables and Objects.
              But, the way you are using now, is the only way.....i think.
              Anyhow, if anyone know better idea, i can also know that....
              • 4. Re: FlashVars
                cutie369 Level 1
                Arun, is there no way to determine what the value of the FlashVar myURL is and react to it based on what it's value is?
                • 5. Re: FlashVars
                  arunbe Level 1
                  hey, you can receive the values.
                  But, you cant predict them with all the variables in the main movie.
                  Look, if am sending a FlashVars likse my_swf.swf?myFlashVar="myName".

                  Here we go,
                  I can receive the value of myFlashVar in the my_swf files. like this,

                  // In the main timeline frame
                  if(this.myFlashVars != undefined)
                  {
                  trace("The Flash Vars :"+ this.myFlashVars);
                  }
                  kool, this wil help, i think... :)
                  • 6. Re: FlashVars
                    2m Level 2
                    Well what you do is just right, as far as I understand.

                    I suppose you set myURL via flashvars, so the way to do it is:

                    if (_level0.myURL == "option1"){
                    do this;
                    do that;
                    }
                    else if (_level0.myURL == "option3") {
                    do this;
                    do that;
                    }
                    else if (_level0.myURL == "option4") {
                    do this;
                    do that;
                    }
                    else { // this servers for undefined
                    do something else;
                    }

                    I hopr hat helps, if not pleas post a url or a zip for us to see the problem.

                    Markus
                    • 7. Re: FlashVars
                      cutie369 Level 1
                      Can anyone help me develop this further. It seems clear to me that I can never access level0.myURL directly to determine it's value. However it seems that I need to loop over _level0 to determine the existance of the value of myURL which got passed in through FlashVars to _level0. I need to loop over _level0 to determine what is there? This is where I need help. Here is some starting code. Can someone help me complete it.

                      var myURL = _level0.myURL
                      for (var myURL in _level0) {
                      //substatements; // Statements typically use thisElem in some way
                      pflipper.gotoPage(3);
                      gotoAndStop(1);
                      }
                      What code do I need to test to see if myURL exists in the for loop?
                      • 8. Re: FlashVars
                        2m Level 2
                        Sorry to contradict, but it is perfectly legal (and it also works!) to access the variables that come via flashvars, the way you (try to) do it.

                        (You can also use loops, but there is no need to do so)

                        If it is not working, there must be another reason. So I repeat, pleas post a URL, so that we can see and reconstruct the problem.

                        Give us a chance to be your heroes ;-)
                        • 9. Re: FlashVars
                          cutie369 Level 1
                          2m, I need a hero. I have been racking my brain on this for 2 days. I have put your code in with the multiple if else statements and it is still not working. I am passing the URL variable through ColdFusion. Here is the URL http://www.graphicartsworld.com/level3.cfm?T1ID=15&T2ID=25&T3ID=16&myURL=4

                          Also, here is a link to download my FLA
                          http://www.graphicartsworld.com/pflipper.fla
                          • 10. Re: FlashVars
                            2m Level 2
                            As it seems the problem is not inside Flash, but with your cold-fusion I'm more of a PHP-guy, so I might not be of great help there, but I can try to point you:

                            </div>
                            <script type="text/javascript">
                            // <![CDATA[

                            var so = new SWFObject("pflipper.swf", "pflipper", "500", "600", "8.0.23", "#636363", true);
                            so.addVariable("myURL", getQueryParamValue("4"));
                            so.write("comm");

                            // ]]>
                            </script>

                            the highlighted part should be something the is already evaluated to a value by cf, I'd say, and it should also be inside quotation marks, for swf object to work correctly.

                            Hope that helps.

                            Markus
                            • 11. Re: FlashVars
                              cutie369 Level 1
                              Markus, I don't think that is it because when I run this code. It works just fine.

                              if (_level0.myURL == undefined) {

                              }
                              else {
                              pflipper.gotoPage(3);
                              gotoAndStop(1);
                              }

                              This is my ColdFusion code.

                              <cfif NOT ISDefined('URL.myURL')>
                              <cfset URL.myURL = 1>
                              </cfif>
                              <script src="js/swfobject.js" type="text/javascript"></script>
                              <div id="comm" style="margin:0px; padding:0px; text-align:left; width:500px; height:350px; background-color:#636363;">
                              <strong>You need to upgrade your Flash Player</strong>
                              <code>noscript</code>
                              </div>
                              <script type="text/javascript">
                              // <![CDATA[

                              var so = new SWFObject("pflipper.swf", "pflipper", "500", "600", "8.0.23", "#636363", true);
                              so.addVariable("myURL", getQueryParamValue("<cfoutput>#URL.myURL#</cfoutput>"));
                              so.write("comm");

                              // ]]>
                              </script>
                              • 12. Re: FlashVars
                                cutie369 Level 1
                                How can I write out to the page what values are at _level0 after the HTML page has loaded?
                                • 13. Re: FlashVars
                                  2m Level 2
                                  First: it is no wonder that the part:
                                  if (_level0.myURL == undefined) {

                                  }
                                  else {
                                  pflipper.gotoPage(3);
                                  gotoAndStop(1);
                                  }
                                  works, as your variable myURL on level0 isn't undefined, but of what ever value JavaScript makes of "getQueryParamValue("4")".

                                  so your cf should look more like:

                                  so.addVariable("myURL", "<cfoutput>getQueryParamValue(#URL.myURL#)</cfoutput>");

                                  but that is just guess work, or my first attempt at cf ever...

                                  second: You could either try to work with the debugger, but that can be tricky, or write the values you find (there you need the for in loop) to a text field, but most easily you can use a text field on the main timeline that is "hardwired" the flash 5 way to you variable. All that shouldn't be a problem once your values are submitted to flash correctly which they aren't right now - trust me, after all that's what heroes are for ;-)