Using Classes

This is a discussion on "Using Classes" within the Flash & Multimedia Forum section. This forum, and the thread "Using Classes are both part of the Design Your Website category.



Go Back   Webforumz.com > Main Forums > Design Your Website > Flash & Multimedia Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Nov 3rd, 2007, 05:07
Reputable Member
Join Date: Jan 2004
Location: California
Age: 19
Posts: 209
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to tox0tes
Using Classes

I am trying to assign a class from an external .as file to a movieclip in the library.

Class file:

Code: Select all
/**********************************************  
DistortImage class  
Availability  
Flash Player 6.  

Description  
Tesselate a movieclip into several triangles  
to allow free transform distorsion.  

Method summary for the DistortImage class  
getBounds - returns the original bounding box  
setTransform - distort image by the passsed  
rect coordinates.  

###############################################  
thanks to peter joel for his transformation  
math code and thomas wagner for the basic idea.  

(C) http://www.andre-michelle.com  
    free to use !  
**********************************************/  


class DistortImage  
{  
      private var parent: MovieClip;  
      private var symbolId: String;  

      private var width: Number;  
      private var height: Number;  

      private var xMin: Number, xMax: Number, yMin: Number, yMax: Number;  

      private var hseg: Number;  
      private var vseg: Number;  

      private var hsLen: Number;  
      private var vsLen: Number;  

      private var points: Array;  
      private var triAngles: Array;  

      function DistortImage( parent: MovieClip, symbolId: String, vseg: Number, hseg: Number )  
      {  
            this.parent = parent;  
            this.symbolId = symbolId;  
            this.vseg = vseg;  
            this.hseg = hseg;  

            if ( arguments.length > 4 )  
            {  
                  width = arguments[ 4 ];  
                  height = arguments[ 5 ];  
            }  
            else  
            {  
                  getImageSize();  
            }  

            init();  
      }  

      private function getImageSize()  
      {  
            var getDimension: MovieClip = parent.attachMovie( symbolId , "getDimension" , 0 );  
            width       = int( getDimension._width );  
            height      = int( getDimension._height );  
            getDimension.removeMovieClip();  
      }  

      private function init(): Void  
      {  
            points = new Array();  
            triAngles = new Array();  

            var ix: Number;  
            var iy: Number;  

            var w2: Number = width / 2;  
            var h2: Number = height / 2;  

            hsLen = width / ( vseg + 1 );  
            vsLen = height / ( hseg + 1 );  

            var x: Number, y: Number;  

            for ( ix = 0 ; ix < vseg + 2 ; ix++ )  
            {  
                  for ( iy = 0 ; iy < hseg + 2 ; iy++ )  
                  {  
                        x = ix * hsLen;  
                        y = iy * vsLen;  
                        points.push( { x: x, y: y, sx: x, sy: y } );  
                  }  
            }  

            for ( ix = 0 ; ix < vseg + 1 ; ix++ )  
            {  
                  for ( iy = 0 ; iy < hseg + 1 ; iy++ )  
                  {  
                        createTriAngle( ix, iy, 1, [ points[ iy + ix * ( hseg + 2 ) ] , points[ iy + ix * ( hseg + 2 ) + 1 ] , points[ iy + ( ix + 1 ) * ( hseg + 2 ) ] ] );  
                        createTriAngle( ix, iy,-1, [ points[ iy + ( ix + 1 ) * ( hseg + 2 ) + 1 ] , points[ iy + ( ix + 1 ) * ( hseg + 2 ) ] , points[ iy + ix * ( hseg + 2 ) + 1 ] ] );  
                  }  
            }  

            xMin = yMin = 0;  
            xMax = width;  
            yMax = height;  

            render();  
      }  

      private function createTriAngle( x: Number, y: Number, align: Number, vertices: Array ): Void  
      {  
            var n: Number;  
            var triAngle: MovieClip;  

            n = triAngles.length;  

            triAngle = parent.createEmptyMovieClip( 't_' + n , n );  

            var inner: MovieClip       = triAngle.inner = triAngle.createEmptyMovieClip( 'inner' , 0 );  
            var mask: MovieClip       = inner.createEmptyMovieClip( "mask" , 0 );  
            var image                   = inner.attachMovie( symbolId , "img_" , 1 );  

            inner._rotation = -45;  

            mask.beginFill( 0 );  
            mask.moveTo( -1 , -1 );  
            mask.lineTo( 101 , -1 );  
            mask.lineTo( -1 , 101 );  
            mask.lineTo( -1 , -1 );  
            mask.endFill();  

            triAngle.setMask( mask );  

            image._xscale = 10000 / hsLen;  
            image._yscale = 10000 / vsLen;  

            if ( align == 1 )  
            {  
                  image._x = -x * 100;  
                  image._y = -y * 100;  
            }  
            else  
            {  
                  image._rotation = -180;  
                  image._x = ( x + 1 ) * 100;  
                  image._y = ( y + 1 ) * 100;  
            }  

            triAngle.vertices = vertices;  
            triAngles.push( triAngle );  
      }  

      function setTransform( x0 , y0 , x1 , y1 , x2 , y2 , x3 , y3 ): Void  
      {  
            var w = width;  
            var h = height;  
            var w2_0 = x1-x0;  
            var w2_1 = x2-x3;  
            var h2_0 = y1-y0;  
            var h2_1 = y2-y3;  

            for ( var p in points )  
            {  
                  var point = points[p];  

                  var gx = ( point.x - xMin ) / w;  
                  var gy = ( point.y - yMin ) / h;  
                  var bx = x0 + gy * ( x3 - x0 );  
                  var by = y0 + gy * ( y3 - y0 );  

                  point.sx = bx + gx * ( ( x1 + gy * ( x2 - x1 ) ) - bx );  
                  point.sy = by + gx * ( ( y1 + gy * ( y2 - y1 ) ) - by );  
            }  

            render();  
      }  

      private function render(): Void  
      {  
            var t: Number;  
            var tmc: MovieClip;  
            var inner: MovieClip;  
            var vertices: Array;  
            var p0, p1, p2;  

            var atan2: Function = Math.atan2;  
            var sqrt: Function = Math.sqrt;  
            var cos: Function = Math.cos;  
            var tan: Function = Math.tan;  

            var arm,p0x,p0y,dx10,dy10,dx20,dy20,ap1,ap2,da12;  

            for ( t in triAngles )  
            {  
                  tmc = triAngles[t];  

                  inner = tmc.inner;  
                  vertices = tmc.vertices;  

                  p0 = vertices[0];  
                  p1 = vertices[1];  
                  p2 = vertices[2];  

                  tmc._rotation = (180/Math.PI)*(-(da12=((ap1=atan2(dy10=p1.sy-(p0y=tmc._y=p0.sy),dx10=p1.sx-(p0x=tmc._x=p0.sx)))-(ap2=atan2(dy20=p2.sy-p0y,dx20=p2.sx-p0x)))/2)+ap1);  
                  tmc._yscale = 100 * tan( da12 );  
                  inner._xscale = sqrt(dx20*dx20+dy20*dy20)/(arm=100/(Math.SQRT1_2 * 2)/cos(da12))*100.5;  
                  inner._yscale = sqrt(dx10*dx10+dy10*dy10)/arm*100.5;  

            }  
      }  

      function getBounds(): Object  
      {  
            return { xMin: xMin, xMax: xMax, yMin: yMin, yMax: yMax };  
      }  
}  
Main .fla file:

Code: Select all
import DistortImage;
attachMovie("blue", "blue", this.getNextHighestDepth(), {
DistortImage:setTransform;
});
It doesn't work though. Does anyone have experience assigning classes to movieclips?
Reply With Quote

  #2 (permalink)  
Old Nov 9th, 2007, 14:12
Multimedia Specialist
Join Date: Apr 2007
Location: Arizona
Age: 25
Posts: 666
Blog Entries: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Sgaspar11
Re: Using Classes

Maybe something like this:
Code: Select all
import DistortImage;
attachMovie("blue", "blue", this.getNextHighestDepth(), 
DistortImage, setTransform);
Last Blog Entry: Yay!? (Oct 8th, 2007)
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
variable classes CloudedVision PHP Forum 4 Feb 14th, 2008 03:07
Classes in PHP pas2gether PHP Forum 11 Oct 13th, 2007 17:24
Classes pa007 PHP Forum 6 Jul 12th, 2007 15:22
Classes Gee Bee JavaScript Forum 1 Mar 8th, 2006 08:31
Styles in classes? timmytots Web Page Design 4 Dec 2nd, 2005 01:20


All times are GMT. The time now is 11:58.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43