16 Replies Latest reply on Apr 1, 2007 5:09 PM by injpix

    Variable in loadMovie

      I've been battling with this for a whole day now. I'm using a database to store information and then calling it back into Flash using a PHP script which outputs all the necessary variables. All the text comes in fine but I'm having difficulty with loading a picture into a blank movie clip (called mcNews_pic).

      The picture variable (called news_image) that's output is the JPEG's path - it comes out as: "images/news/news_1.jpg"

      The ActionScript that loads in the variables is on the first frame of the movie.

      Putting the image path directly into the loadMovie line works fine, but the variable name doesn't seem to work in there...

      mcNews_pic.loadMovie(news_image); // doesn't work
      mcNews_pic.loadMovie("images/news/news_1.jpg"); // works fine

      The variable displays fine in a test text field I've made as well.

      Any ideas? It's driving me mad... I'm sure I've done something wrong but whatever I try doesn't seem to work.

      I also want to make sure I retain Flash 5 compatibility if possible.

      Any help is appreciated!


        • 1. Re: Variable in loadMovie
          injpix Level 3
          ‘news_image’ is a variable name you created, when the loadMovie() is invoked it probably is not defined at this point. Put the following trace statement right before the loadMovie();

          trace(“news_image >>> “+news_image);

          Does it come up as ‘undefined’? If so you probably need to use an event handler to invoke a function that contains the loadMovie() only when news_image is defined.
          • 2. Re: Variable in loadMovie
            Tiller Level 1

            Thanks for your reply.

            The variable name is definitely defined as I have a text field that is set up to receive the contents of the variable which works fine.

            I did try the trace command, but since it has to be run from the server I'm not sure how to get any output from the command through Safari.

            • 3. Re: Variable in loadMovie
              injpix Level 3
              If you are unable to test the swf thru Flash’s IDE then create a textfield that will render the value of the variable. Like the code below;

              //var news_image = "images/photos/ball.jpg"

              this.createTextField("my_txt", 1, 100, 100, 300, 100);
              var my_fmt:TextFormat = new TextFormat();
              my_fmt.size = 16;
              my_fmt.color = 0xFF0000;
              my_txt.text = news_image;
              • 4. Re: Variable in loadMovie
                injpix Level 3
                Ah...hmmm, you already tried this textfield thing? If you did is that textfield rendering "images/news/news_1.jpg"?
                • 5. Re: Variable in loadMovie
                  injpix Level 3
                  Hmm…you are compiling this as a Flash 5 swf? That may be a problem the LoadVars object is available in Flash 6 and above. I am assuming you are using LoadVars.
                  • 6. Re: Variable in loadMovie
                    Tiller Level 1
                    Thanks for your replies!

                    Yes, the textfield does come out as "images/news/news_1.jpg" so that's all fine.

                    I've tried outputting as Flash 6 and Flash 7 and still no joy.

                    I'm using loadVariablesNum (not LoadVars) as I wanted to keep compatibility with older Flash players. Is that still okay?

                    • 7. Re: Variable in loadMovie
                      Rothrock Level 5
                      My guess is that there is a return or some such at the end of the variable. So it looks like it is the correct value, but isn't.

                      I'm not familiar with PHP, but this is a common problem for folks using regular text files.
                      • 8. Re: Variable in loadMovie
                        injpix Level 3
                        Rothrock brought up an interesting point that I was not aware of. If that is the case, perhaps you can extract a certain number of characters to that string. The code below will find the “.” that is right before the file extension name and will start to extract the filename with the extension. Once it did that it will reassign/recondition the variable.

                        You may also want to look into the valueOf() that is a part of the String Object. The link to the livedocs is below;
                        http://livedocs.adobe.com/flash/8/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveD ocs_Parts&file=00002713.html
                        • 9. Re: Variable in loadMovie
                          Tiller Level 1
                          There doesn't appear to be any space/returns after the variable. I checked the PHP code and that's fine. The variables produced look like the following (if it helps):

                          heading=Heading here&date=1st April 2007&news_image="images/news/news_1.jpg"&caption=Text is here

                          Thanks for all your help so far!

                          • 10. Re: Variable in loadMovie
                            Tiller Level 1
                            I've been looking on Google (a lot!) and found a snippet of information that suggested a loadMovie command may need a bit of time before the data gets fed to it.

                            To test this theory I set up a button (that just loaded the picture after being clicked using the same variable as before) and it worked fine!

                            So by the sounds of it I need to tell it to wait until the data is loaded before doing loadMovie. Something like onClipEvent sounds like what I need to use. I'm not really up to speed with Flash, so I'll spend ages trying to work that out now!

                            • 11. Re: Variable in loadMovie
                              Rothrock Level 5
                              AHA! I completely forgot the most popular reason.

                              Yes, there is a time delay between when you request the loadVariablesNum and the data arrives – just like everything on the net.

                              However, Flash doesn't wait until that data comes back before it proceeds.

                              If you use the newer LoadVars class there is an onLoad event that is called when the data comes back and then you can issue your loadMovie (or better yet MovieClipLoader) command.

                              Otherwise you will need to use some other test to determine that the data has loaded.
                              • 12. Re: Variable in loadMovie
                                Tiller Level 1
                                Yes, in theory it's a great idea! I can't seem to get it to work though.

                                LoadVariables is on frame 1 of the timeline and I've got the OnClipEvent code on the picture MovieClip.

                                This should work, shouldn't it?

                                on main timeline, frame 1:

                                loadVariables("flash_test.php", "_root");

                                on the mcNews_pic instance:

                                onClipEvent (data) {

                                Thanks for all your help so far... and yes, I'd love to use some of the newer LoadVars commands and so on, but I'm trying to keep it at Flash 5 (although I may change my mind on that if this proves too much more hassle!).

                                • 13. Re: Variable in loadMovie
                                  Tiller Level 1
                                  Ahh... I need to target the LoadVariables to the same movie clip that's got the OnClipEvent.

                                  So now I have to get this movie clip to pass all the variables back to the timeline so the text boxes all fill in as they should.

                                  Nothing's ever easy!

                                  • 14. Re: Variable in loadMovie
                                    Rothrock Level 5
                                    Glad this is going to work out for you.

                                    However, if you continue to use loadVariables and and the onClipEvent type of structure you are halfway making it harder for yourself than it needs to be.

                                    The new styles of coding make Flash a lot easier. :)
                                    • 15. Re: Variable in loadMovie
                                      Tiller Level 1
                                      Yes, I can tell that! I think most people have newer versions of Flash player these days so I'm sure I can get away with Flash 6 at least. Is there a website that tells these sorts of stats do you know?

                                      I'll be redeveloping the website one of these days so I'll go through and streamline for a newer Flash at the same time.

                                      Anyway, thanks to you and myIP very much for helping me - really appreciated!

                                      • 16. Re: Variable in loadMovie
                                        injpix Level 3
                                        Below is a link show Flash Player's penetration.

                                        I would assume your target audience would have something greater then Flash Player 5 by now. If you do choose to use something greater then FP 5, then use the LoadVars class. And be sure you know the differences between onLoad and onData event handler.