Visualizzazione dei risultati da 1 a 9 su 9
  1. #1
    Utente di HTML.it
    Registrato dal
    Oct 2001
    Messaggi
    99

    importare una classe in AS2

    Salve a tutti, e scusate la domanda cretina...

    ho trovato questa classe e vorrei utilizzarla, ma dato che non l'ho mai fatto non so come fare.
    Ho trovaro in giro istruzioni su come fare l'import e sul fatto che bisogna aggiungere la cartella nella quale è inserita la classe nelle preferenze actionscript di flash, ma a me proprio non va...
    Mi continua a dare errori...

    C'è qualcuno che può darmi una mano?

  2. #2
    Utente di HTML.it L'avatar di and80
    Registrato dal
    Mar 2003
    Messaggi
    15,182
    per quella particolare classe puoi fare così

    1. metti il file che contiene la classe nella stessa cartella del fla in cui la vuoi sfruttare
    2. apri il file .as ed editi la riga che nel post che hai linkato, porta il n. 28:

    class com.kiroukou.graphics.DistordImage

    diventa

    class DistordImage

    3. senza fare nessuna importazione, richiami semplicemente l'istanza della classe, come indicato nell'esempio di utilizzo



  3. #3
    Utente di HTML.it
    Registrato dal
    Oct 2001
    Messaggi
    99
    Ciao, e grazie per l'aiuto.
    Ho fatto come mi hai detto e ho messo il file DistordImage.as nella stessa cartella del fla, ma quando lanscio l'swf mi dice che c'è un errore in DistordImage.as alla riga 3...
    Il file con la classe è questo:

    codice:
    import flash.geom.Matrix;
    import flash.display.BitmapData;
     
    class DistordImage
    {
        private var _mc:MovieClip;
        private var _w:Number;
        private var _h:Number;
        // -- skew and translation matrix
        private var _sMat:Matrix ;
        private var _tMat:Matrix ;
     
        private var _xMin, _xMax, _yMin, _yMax:Number;
     
        private var _hseg:Number;
        private var _vseg:Number;
     
        private var _hsLen:Number;
        private var _vsLen:Number;
     
        private var _p:Array;
        private var _tri:Array;
       
        private var _texture:BitmapData;
     
        /* Constructor
         *
         * @param mc MovieClip :  the movieClip containing the distorded picture
         * @param symbolId String : th link name of the picture in the library
         * @param vseg Number : the vertical precision
         * @param hseg Number : the horizontal precision
         */
        public function DistordImage( mc:MovieClip, symbolId:String, vseg:Number, hseg:Number )
        {
            _mc = mc;
            _texture = BitmapData.loadBitmap( symbolId );
            _vseg = vseg;
            _hseg = hseg;
           
            _w = _texture.width ;
            _h = _texture.height;
            __init();
           
        }
     
     
        private function __init( Void ): Void
        {
            _p = new Array();
            _tri = new Array();
           
            var ix:Number;
            var iy:Number;
     
            var w2:Number = _w / 2;
            var h2:Number = _h / 2;
     
            _xMin = _yMin = 0;
            _xMax = _w; _yMax = _h;
           
            _hsLen = _w / ( _hseg + 1 );
            _vsLen = _h / ( _vseg + 1 );
     
            var x:Number, y:Number;
            // -- we create the points
            for ( ix = 0 ; ix <_vseg + 2 ; ix++ )
            {
                for ( iy = 0 ; iy <_hseg + 2 ; iy++ )
                {
                    x = ix * _hsLen;
                    y = iy * _vsLen;
                    _p.push( { x: x, y: y, sx: x, sy: y } );
                }
            }
            // -- we create the triangles
            for ( ix = 0 ; ix <_vseg + 1 ; ix++ )
            {
                for ( iy = 0 ; iy <_hseg + 1 ; iy++ )
                {
                    _tri.push([ _p[ iy + ix * ( _hseg + 2 ) ] , _p[ iy + ix * ( _hseg + 2 ) + 1 ] , _p[ iy + ( ix + 1 ) * ( _hseg + 2 ) ] ] );
                    _tri.push([ _p[ iy + ( ix + 1 ) * ( _hseg + 2 ) + 1 ] , _p[ iy + ( ix + 1 ) * ( _hseg + 2 ) ] , _p[ iy + ix * ( _hseg + 2 ) + 1 ] ] );
                }
            }
     
            __render();
        }
     
        /* setTransform
         *
         * @param x0 Number the horizontal coordinate of the first point
         * @param y0 Number the vertical coordinate of the first point 
         * @param x1 Number the horizontal coordinate of the second point
         * @param y1 Number the vertical coordinate of the second point 
         * @param x2 Number the horizontal coordinate of the third point
         * @param y2 Number the vertical coordinate of the third point 
         * @param x3 Number the horizontal coordinate of the fourth point
         * @param y3 Number the vertical coordinate of the fourth point 
         *
         * @description : Distord the bitmap to ajust it to those points.
         */
        function setTransform( x0:Number , y0:Number , x1:Number , y1:Number , x2:Number , y2:Number , x3:Number , y3:Number ): Void
        {
            var w:Number = _w;
            var h:Number = _h;
            var dx30:Number = x3 - x0;
            var dy30:Number = y3 - y0;
            var dx21:Number = x2 - x1;
            var dy21:Number = y2 - y1;
            var l:Number = _p.length;
            while( --l> -1 )
            {
                var point:Object = _p[ l ];
                var gx = ( point.x - _xMin ) / w;
                var gy = ( point.y - _yMin ) / h;
                var bx = x0 + gy * ( dx30 );
                var by = y0 + gy * ( dy30 );
     
                point.sx = bx + gx * ( ( x1 + gy * ( dx21 ) ) - bx );
                point.sy = by + gx * ( ( y1 + gy * ( dy21 ) ) - by );
            }
     
            __render();
        }
     
        private function __render( Void ):Void
        {
     
            var t:Number;
            var vertices:Array;
            var p0, p1, p2:Object;
            var c:MovieClip = _mc;
            var a:Array;
            c.clear();
            _sMat = new Matrix();
            _tMat = new Matrix();
           
            var l:Number = _tri.length;
            while( --l> -1 )
            {
                a = _tri[ l ];
                p0 = a[0];
                p1 = a[1];
                p2 = a[2];
                var x0:Number = p0.sx;
                var y0:Number = p0.sy;
                var x1:Number = p1.sx;
                var y1:Number = p1.sy;
                var x2:Number = p2.sx;
                var y2:Number = p2.sy;
                   
                var u0:Number = p0.x;
                var v0:Number = p0.y;
                var u1:Number = p1.x;
                var v1:Number = p1.y;
                var u2:Number = p2.x;
                var v2:Number = p2.y;
     
                _tMat.tx = u0;
                _tMat.ty = v0;
           
                _tMat.a = ( u1 - u0 ) / _w;
                _tMat.b = ( v1 - v0 ) / _w;
                _tMat.c = ( u2 - u0 ) / _h;
                _tMat.d = ( v2 - v0 ) / _h;
           
                _sMat.a = ( x1 - x0 ) / _w;
                _sMat.b = ( y1 - y0 ) / _w;
                _sMat.c = ( x2 - x0 ) / _h;
                _sMat.d = ( y2 - y0 ) / _h;
           
                _sMat.tx = x0;
                _sMat.ty = y0;
           
                _tMat.invert();
                _tMat.concat( _sMat );
               
                c.beginBitmapFill( _texture, _tMat, false, false );
                c.moveTo( x0, y0 );
                c.lineTo( x1, y1 );
                c.lineTo( x2, y2 );
                c.endFill();
            }
        }
    }
    ma non capisco dove sia questo errore...
    Mi potresti aiutare?

  4. #4
    Utente di HTML.it L'avatar di and80
    Registrato dal
    Mar 2003
    Messaggi
    15,182
    se mi dici che errore ti da, posso provarci

  5. #5
    Utente di HTML.it
    Registrato dal
    Oct 2001
    Messaggi
    99
    Il problema è che mi dice solo che c'è un errore, ma non mi dice di che tipo...

  6. #6
    Utente di HTML.it L'avatar di and80
    Registrato dal
    Mar 2003
    Messaggi
    15,182
    eh, in effetti è un po' fastidioso quando lo fa... se c'è un errore sarebbe anche il caso di segnalarne almeno un minimo correttamente il punto

    un paio di cose

    1. posta il codice che hai utilizzato per crearti l'esempio
    2. ho dato per scontato che stai utilizzando una versione di flash pari alla 8 e che pubblichi correttamente per FP8+AS2, è una supposizione giusta?

  7. #7
    Utente di HTML.it
    Registrato dal
    Oct 2001
    Messaggi
    99
    Si, le impostazioni di pubblicazione sono giuste.
    Ti allego il sorgente.
    Ecco il link

    Grazie ancora

  8. #8
    Utente di HTML.it L'avatar di and80
    Registrato dal
    Mar 2003
    Messaggi
    15,182
    non so perchè... ma nel tuo .as hai importato dei caratteri invisibili che rompono le scatole al parser :master:

    fai una cosa... elimina quel file .as e creane in flash uno nuovo, poi incollaci il codice prendendolo da questo post

    Codice PHP:
    import flash.geom.Matrix;
    import flash.display.BitmapData;
    class 
    DistordImage {
        private var 
    _mc:MovieClip;
        private var 
    _w:Number;
        private var 
    _h:Number;
        
    // -- skew and translation matrix
        
    private var _sMat:Matrix;
        private var 
    _tMat:Matrix;
        private var 
    _xMin_xMax_yMin_yMax:Number;
        private var 
    _hseg:Number;
        private var 
    _vseg:Number;
        private var 
    _hsLen:Number;
        private var 
    _vsLen:Number;
        private var 
    _p:Array;
        private var 
    _tri:Array;
        private var 
    _texture:BitmapData;
        
    /* Constructor
             *
             * @param mc MovieClip :  the movieClip containing the distorded picture
             * @param symbolId String : th link name of the picture in the library
             * @param vseg Number : the vertical precision
             * @param hseg Number : the horizontal precision
        */
        
    public function DistordImage(mc:MovieClipsymbolId:Stringvseg:Numberhseg:Number) {
            
    _mc mc;
            
    _texture BitmapData.loadBitmap(symbolId);
            
    _vseg vseg;
            
    _hseg hseg;
            
    _w _texture.width;
            
    _h _texture.height;
            
    __init();
        }
        private function 
    __init(Void):Void {
            
    _p = new Array();
            
    _tri = new Array();
            var 
    ix:Number;
            var 
    iy:Number;
            var 
    w2:Number _w/2;
            var 
    h2:Number _h/2;
            
    _xMin _yMin=0;
            
    _xMax _w;
            
    _yMax _h;
            
    _hsLen _w/(_hseg+1);
            
    _vsLen _h/(_vseg+1);
            var 
    x:Numbery:Number;
            
    // -- we create the points
            
    for (ix=0ix<_vseg+2ix++) {
                for (
    iy=0iy<_hseg+2iy++) {
                    
    ix*_hsLen;
                    
    iy*_vsLen;
                    
    _p.push({x:xy:ysx:xsy:y});
                }
            }
            
    // -- we create the triangles
            
    for (ix=0ix<_vseg+1ix++) {
                for (
    iy=0iy<_hseg+1iy++) {
                    
    _tri.push([_p[iy+ix*(_hseg+2)], _p[iy+ix*(_hseg+2)+1], _p[iy+(ix+1)*(_hseg+2)]]);
                    
    _tri.push([_p[iy+(ix+1)*(_hseg+2)+1], _p[iy+(ix+1)*(_hseg+2)], _p[iy+ix*(_hseg+2)+1]]);
                }
            }
            
    __render();
        }
        
    /* setTransform
             *
             * @param x0 Number the horizontal coordinate of the first point
             * @param y0 Number the vertical coordinate of the first point 
             * @param x1 Number the horizontal coordinate of the second point
             * @param y1 Number the vertical coordinate of the second point 
             * @param x2 Number the horizontal coordinate of the third point
             * @param y2 Number the vertical coordinate of the third point 
             * @param x3 Number the horizontal coordinate of the fourth point
             * @param y3 Number the vertical coordinate of the fourth point 
             *
             * @description : Distord the bitmap to ajust it to those points.
        */
        
    function setTransform(x0:Numbery0:Numberx1:Numbery1:Numberx2:Numbery2:Numberx3:Numbery3:Number):Void {
            var 
    w:Number _w;
            var 
    h:Number _h;
            var 
    dx30:Number x3-x0;
            var 
    dy30:Number y3-y0;
            var 
    dx21:Number x2-x1;
            var 
    dy21:Number y2-y1;
            var 
    l:Number _p.length;
            while (--
    l>-1) {
                var 
    point:Object _p[l];
                var 
    gx = (point.x-_xMin)/w;
                var 
    gy = (point.y-_yMin)/h;
                var 
    bx x0+gy*(dx30);
                var 
    by y0+gy*(dy30);
                
    point.sx bx+gx*((x1+gy*(dx21))-bx);
                
    point.sy by+gx*((y1+gy*(dy21))-by);
            }
            
    __render();
        }
        private function 
    __render(Void):Void {
            var 
    t:Number;
            var 
    vertices:Array;
            var 
    p0p1p2:Object;
            var 
    c:MovieClip _mc;
            var 
    a:Array;
            
    c.clear();
            
    _sMat = new Matrix();
            
    _tMat = new Matrix();
            var 
    l:Number _tri.length;
            while (--
    l>-1) {
                
    _tri[l];
                
    p0 a[0];
                
    p1 a[1];
                
    p2 a[2];
                var 
    x0:Number p0.sx;
                var 
    y0:Number p0.sy;
                var 
    x1:Number p1.sx;
                var 
    y1:Number p1.sy;
                var 
    x2:Number p2.sx;
                var 
    y2:Number p2.sy;
                var 
    u0:Number p0.x;
                var 
    v0:Number p0.y;
                var 
    u1:Number p1.x;
                var 
    v1:Number p1.y;
                var 
    u2:Number p2.x;
                var 
    v2:Number p2.y;
                
    _tMat.tx u0;
                
    _tMat.ty v0;
                
    _tMat.= (u1-u0)/_w;
                
    _tMat.= (v1-v0)/_w;
                
    _tMat.= (u2-u0)/_h;
                
    _tMat.= (v2-v0)/_h;
                
    _sMat.= (x1-x0)/_w;
                
    _sMat.= (y1-y0)/_w;
                
    _sMat.= (x2-x0)/_h;
                
    _sMat.= (y2-y0)/_h;
                
    _sMat.tx x0;
                
    _sMat.ty y0;
                
    _tMat.invert();
                
    _tMat.concat(_sMat);
                
    c.beginBitmapFill(_texture_tMatfalsefalse);
                
    c.moveTo(x0y0);
                
    c.lineTo(x1y1);
                
    c.lineTo(x2y2);
                
    c.endFill();
            }
        }

    a me ha funzionato

  9. #9
    Utente di HTML.it
    Registrato dal
    Oct 2001
    Messaggi
    99
    GRAZIE!!!!
    Ora funziona benissimo


Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.