2 Replies Latest reply on Jun 17, 2009 1:43 PM by joyzserrano

    Image Dynamic Masking

    joyzserrano

      I got this code from an online source. I will appreciate your help in editing the code very much.

       

      NEED HELP IN THE FOLLOWING:

      I need the image to be inside the stage and not load externally.

      I also want the masking to start when mouse rolls over.

       

       

      the file id made out of 2 frames and has an external file named test.jpg...

       

      frame 1:

       

      Stage.scaleMode = "noScale";
      _root.createEmptyMovieClip("foo",1);
      _root.foo.createEmptyMovieClip("img",2);
      _root.foo.onEnterFrame = function()
      {
      if(this._width > 100 && this.img.getBytesLoaded() >= this.img.getBytesTotal() && this.img.getBytesLoaded() > 0)
      {
        this._x = 80-this._width/2
        this._y = 300-this._height/2
        nextFrame();
      }
      }

      if(n==undefined)
      {
      loadMovie("test.jpg",_root.foo.img);
      } else {
      loadMovie(n,_root.foo.img);
      }
      stop();

       

      -------------------------------------------

      frame 2:

       

      stop();
      _global.h = 50;
      _root.createEmptyMovieClip("mask",3);
      _root.foo._visible = 0
      _root.foo.img.setMask(_root.mask);
      mask.onEnterFrame = function()
      {
      this.onMouseMove = function()
      {
        this.a++;
        this.createEmptyMovieClip("l"+this.a,10+this.a);
        this.lc = this['l'+this.a];
        with(this.lc)
        {
         beginFill(0x000000,100);
         moveTo(0,-h/2)
         lineTo(100,-h/2)
         lineTo(100,h/2)
         lineTo(0,h/2)
         lineTo(0,-h/2)
         endFill();
        }
        this.x1 = _root._xmouse;
        this.y1 = _root._ymouse;
        this.lc._x = this.x1;
        this.lc._y = this.y1;
        this.x2 = this['l'+(this.a-1)]._x == undefined ? _root._xmouse : this['l'+(this.a-1)]._x;
        this.y2 = this['l'+(this.a-1)]._y == undefined ? _root._ymouse : this['l'+(this.a-1)]._y;
        this.lx = this.x1 - this.x2;
        this.ly = this.y1 - this.y2;
        this.rotation = Math.atan2 (this.lx,this.ly);
        this.rotation *= 180/Math.PI;
        this.lc._rotation = 270-this.rotation;
        this.lc._xscale = Math.sqrt(this.lx*this.lx+this.ly*this.ly)+1;
        _root.foo.img.setMask(_root.mask);
        updateAfterEvent();
      }
      _root.foo._visible = 1
      }

      mask.onMouseUp = function()
      {
      this.a++
      this.onMouseMove = undefined;
      }

      foo2._alpha = 20
      this.onMouseMove

       

        • 1. Re: Image Dynamic Masking
          dublyner Level 1

          Is this AS3?  I'm no expert, but if the image isn't loading I might suggest using an event to wait for the JPG to fully load before executing your other functions.  Something like this:


               public class loader extends Sprite {
                    private var loadObj          :     Loader          = new Loader();

           

                    public function loader() {
                         var url               :     String               = "insert_file_path_here";
                         var target          :     URLRequest     = new URLRequest(url);
                        
                         loadObj.contentLoaderInfo.addEventListener(Event.COMPLETE, initHandler);
                         loadObj.load(target);
                    }
                   
                    public function initHandler(event:Event):void {
                         addChild(loadObj);
                    }
               }

           

          That would load an external image or movie clip, and when it was ready add it to the stage of the movie.  The way I have it written there is for a document class, but you could modify that code for a frame script instead.

          • 2. Re: Image Dynamic Masking
            joyzserrano Level 1

            I onlye got this from an onlie source. not sure if its AS2 or 3. sorry.

             

            regarding my inquiry... It's the other way around. i want to lay out the image in the stage. and not load it externally.

            whats currently happening is that anything that I put in the stage even if its in a different layer, when I execute the code, everything in the stage is being erased by the dynamic mask.

             

            by the way..thank you so much for your time. i really appreciate it.