12 Replies Latest reply on May 27, 2006 8:15 PM by Rothrock

    JPG LoadMovie events?

    Beachie1
      Please help me with this...

      This works:

      this.createEmptyMovieClip("box_mc", 100);
      box_mc._x = 32;
      box_mc._y = 32;
      with (box_mc) {
      lineStyle(1, 0xCCCCCC);
      beginFill(0xEEEEEE);
      moveTo(0, 0);
      lineTo(80, 0);
      lineTo(80, 60);
      lineTo(0, 60);
      lineTo(0, 0);
      endFill();
      };
      box_mc.onPress = function() {
      this._x -= this._width/2;
      this._y -= this._height/2;
      this._xscale = 200;
      this._yscale = 200;
      };
      box_mc.onRelease = function() {
      this._xscale = 100;
      this._yscale = 100;
      this._x += this._width/2;
      this._y += this._height/2;
      };

      This does not work:

      this.createEmptyMovieClip("box_mc", 100);
      box_mc._x = 32;
      box_mc._y = 32;
      with (box_mc) {
      loadMovie("smiley.jpg");
      };

      box_mc.onPress = function() {
      this._x -= this._width/2;
      this._y -= this._height/2;
      this._xscale = 200;
      this._yscale = 200;
      };
      box_mc.onRelease = function() {
      this._xscale = 100;
      this._yscale = 100;
      this._x += this._width/2;
      this._y += this._height/2;
      };

      WHY NOT??!?
        • 1. Re: JPG LoadMovie events?
          Rothrock Level 5
          You might want to read the help files for MovieClip.loadMovie(); paying particular attention to the paragraph that begins with. "Using event handlers with MovieClip.loadMovie() can be unpredictable."
          • 2. Re: JPG LoadMovie events?
            Beachie1 Level 1
            quote:

            Originally posted by: Rothrock
            You might want to read the help files for MovieClip.loadMovie(); paying particular attention to the paragraph that begins with. "Using event handlers with MovieClip.loadMovie() can be unpredictable."
            Thankyou! Oddly enough, my help mentions nothing about that, but I've tracked it down on the macromedia site..
            • 3. Re: JPG LoadMovie events?
              Juankpro Level 2
              The problem is that when you load movies the event handlers like onPress and onReleased are erased to be replaced for the versions used by the loaded movie. Becuase the loaded movie doen't have them aoriginally then they are just erased.
              • 4. Re: JPG LoadMovie events?
                Beachie1 Level 1
                quote:

                Originally posted by: juankpro
                The problem is that when you load movies the event handlers like onPress and onReleased are erased to be replaced for the versions used by the loaded movie. Becuase the loaded movie doen't have them aoriginally then they are just erased.
                Thanks for your reply The help mentions using onClipEvent() or on() but I'm not sure how I can assign one of these to a loaded movie..

                • 5. Re: JPG LoadMovie events?
                  Juankpro Level 2
                  Assign thiis to the clip into which the new clip is going to be loaded.
                  • 6. Re: JPG LoadMovie events?
                    Beachie1 Level 1
                    quote:

                    Originally posted by: juankpro
                    Assign thiis to the clip into which the new clip is going to be loaded.
                    There's the problem though - I'm creating the clip(s) dynamically with createemptymovieclip, so I can't attach an event.

                    • 7. Re: JPG LoadMovie events?
                      Juankpro Level 2
                      Then you must attach the code after loading and not before.For this use the MovieClipLoader object or an onEnterFrame poll function:

                      MovieClipLoader:
                      You create a MovieClipLoader then a listener for events, register this listener as the listener for the loader. When the jpg file is loaded the onLoadInit event executes and then you can attach the methods. The loadClip method load the clip on the first parameter to the clip on the second parameter.



                      • 8. JPG LoadMovie events?
                        Beachie1 Level 1
                        Hi,

                        I appreciate your help

                        I'm almost a newbie to ActionScript (although I'm more than competent in C++, PHP, ASP and Perl), but I simply cannot make this work. I tried your code, and also some that I found on the net, but I get NOTHING. I'm using Flash MX 6.0 and Flash Player version 8.0.24.0. I'm now into my second day of dicking around just trying to load a JPEG and do some basic (you would expect) functionality, and I'm starting to wonder if it's all worth the trouble - ActionScript just seems flaky.
                        • 9. Re: JPG LoadMovie events?
                          Rothrock Level 5
                          Well that would be your problem right there! The MovieClipLoader class wasn't introduced until Flash 7. Also the help files before version 7 were absolutely awful so that was why it didn't explain the part I mentioned.

                          You will have to make your own preloader code that checks to see when the clip has fully loaded. This is something you should learn anyways for so many reasons.

                          Basically you need to repeatedly check to see if the clip is completely loaded. So here is a basic example.

                          this.createEmptyMovieClip("holder",1000);
                          holder.loadMovie("somefile.swf");
                          this.onEnterFrame=function(){
                          var bT=holder.getBytesTotal();
                          var bL=holder.getBytesLoaded();
                          if(bT==bL && holder._width>0){
                          //it is now loaded and you can do what you would like:
                          delete this.onEnterFrame;
                          }
                          }

                          I think that is it. I just typed it from memory so I might have made a mistake. And it is very basic, but might give you the general idea. Try it in a brand-new simple file before you try and work it into your current project.

                          PS: And if you can, upgrade your copy of Flash!
                          • 10. JPG LoadMovie events?
                            Juankpro Level 2
                            Yep this code won't work on Flash MX i.e. Flash 6 only on Flash 7 and Flash 8. I didn't know you were using that version. But here is the corresponding version for Flash MX.

                            • 11. Re: JPG LoadMovie events?
                              Beachie1 Level 1
                              You guys rock! Thanks! I actually own MX 2004, but haven't installed it on my laptop.. duh..
                              • 12. Re: JPG LoadMovie events?
                                Rothrock Level 5
                                Cool. With MX04, you can use the MovieClipLoader which is IMHO much easier, but understanding the concept behind the old-school preloader is (again IMHO) a very important skill for understanding Flash.

                                I would add one thing to juankpro's (much nicer than mine) code. Notice in mine that part of the condition is to check the _width of the clip as well as the bytesLoaded and bytesTotal. In rare cases (probably not this example) and with certain browsers and versions of Flash player (in other words, in really hard to repeat and yet maddeningly troublesome cases) your loaded clip won't actually be available until the _width is greater than zero even though the bytes have completely loaded.

                                It is kind of the old-school equivalent of the issues surrounding the use of onLoadInit instead of onLoadComplete.

                                Good luck!