2 Replies Latest reply on Sep 7, 2006 12:18 PM by bibberlam

    limitation of actionscript on a buttonMC

    bibberlam
      Hello everybody,

      I have a question about a button-movieclip. I would like to write a script, executed when releasing the button.

      The goal of the script is to create a number of new MovieClips in the root.mc. the amount of that number is given by an external txt-file. so far so good.

      Each newMC has to load a photo, and behind that photo there must be another newMC acting as a button. This button has to have indeed the exact size of the photo.

      therefor I tried to get the properties of the photo's for each MC to set the parameters of the button-mc in the back of the photo, but this returns "0" everytime. I now the problem, but i can't handle it... I can't get the properties of the loading photo's until they are totaly loaded. that's the problem: i putted some while actions in my script, but they seem not to work very well.

      I put my code here:
      on (release){
      text = new LoadVars();
      text.load ("aantal.txt");
      text.onLoad = function(succes) {
      if(succes){
      maximum = this.txt;
      trace(maximum);
      }
      }
      //creating little preview photo
      i=1;
      X=50;
      this.onEnterFrame = function() {
      while(i!=maximum){
      this.createEmptyMovieClip("preview"+i, i);
      this.createEmptyMovieClip("preview_back"+i, i+maximum);

      this["preview"+i].loadMovie("photo8.jpg");
      this["preview"+i]._x=X;
      this["preview"+i]._y=50;
      this["preview_back"+i]._x=X;
      this["preview_back"+i]._y=50;


      this.onEnterFrame = function() {
      while(bytes!=totalbytes){
      bytes=this["preview"+i].getBytesLoaded();
      totalbytes=this["preview"+i].getBytesTotal();
      }
      widthx=this["preview"+i]._width;
      heighty=this["preview"+i]._height;
      trace(i);
      trace (widthx);
      trace (heighty);
      }

      this["preview_back"+i].beginFill(0xff0000,100);
      this["preview_back"+i].moveTo(0,0);
      this["preview_back"+i].lineTo(0,hoogte);
      this["preview_back"+i].lineTo(breedte,hoogte);
      this["preview_back"+i].lineTo(breedte,0);
      this["preview_back"+i].lineTo(0,0);
      this["preview_back"+i].endFill();
      i++;
      X+=155;
      }

      this["preview_back"+i].onRelease=function(){
      _root.createEmptyMovieClip("picture", 101);
      _root.picture._x=200;
      _root.picture._y=50;
      _root.picture.loadMovie("project00.jpg");
      }
      }
      }

      What's wrong?? can someone help me?

        • 1. Re: limitation of actionscript on a buttonMC
          scsherwood
          I believe you're code is racing against the loading events. So, you need to write an event handler to execute on either the "onLoad" event of LoadVars or on the MovieClip.onLoad event. In either case the handler/code you write for each one won't execute until the onLoad event is complete. So, if you need to work on a MovieClip that is being loaded, you need to write an onLoad event handler for that Movieclip. When the MovieClip finishes loading, the onLoad event handler will fire and run the code on the clip.

          MovieClip.onLoad = function() {

          // your code here

          }
          • 2. Re: limitation of actionscript on a buttonMC
            bibberlam Level 1
            it doesn't work... In the bottom, you will see the changed script.

            on (release){
            text = new LoadVars();
            text.load ("aantal.txt");
            text.onLoad = function(succes) {
            if(succes){
            maximum = this.txt;
            trace(maximum);
            }
            }
            //creating small pictures
            //i=1;
            X=50;
            this.onEnterFrame = function() {
            while(i!=maximum){
            this.createEmptyMovieClip("preview"+i, i);
            this.createEmptyMovieClip("preview_back"+i, i+maximum);

            this["preview"+i].loadMovie("photo8.jpg");
            this["preview"+i].onLoad = function(){
            widthx=this["preview"+i]._width;
            heighty=this["preview"+i]._height;
            this["preview"+i]._x=X;
            this["preview"+i]._y=50;
            this["preview_back"+i]._x=X;
            this["preview_back"+i]._y=50;
            trace(i);
            trace (widthx);
            trace (heighty);

            this["preview_back"+i].beginFill(0xff0000,100);
            this["preview_back"+i].moveTo(0,0);
            this["preview_back"+i].lineTo(0, heighty);
            this["preview_back"+i].lineTo(widthx, heighty);
            this["preview_back"+i].lineTo(widthx,0);
            this["preview_back"+i].lineTo(0,0);
            this["preview_back"+i].endFill();

            this["preview"+i].onRelease=function(){
            _root.createEmptyMovieClip("picture", 101);
            _root.picture._x=200;
            _root.picture._y=50;
            _root.picture.loadMovie("project00.jpg");
            }
            i++;
            X+=155;

            }

            }
            }
            }