Visualizzazione dei risultati da 1 a 6 su 6
  1. #1

    [AS2] Funzione che posiziona clip al resize

    Non sono riuscito a trovare un titolo migliore ^^
    Mi stavo chiedendo se non esista già una funzione del genere (sicuramente esisterà e il topic lo scrivo anche perché così magari me la passate ^^), intanto vi posto la mia.

    Praticamente serve a posizionare un clip al centro o ai bordi in tutte le combinazioni possibili. La funzione parte al resize, ma ovviamente si può lanciare a piacere. Ho messo anche un parametro lockStage, che serve per fare riferimento alle dimensioni dello stage iniziale e non quello finale.

    Per fare la prova create un clip e piazzatelo nello stage chiamatelo menu (o come volete ma poi cambiate il riferimento nel codice). Create una rettangolo che copra l'area dello stage iniziale così vedete anche la differenza tra lockStage a true e a false. Provate tutte le possibili combinazioni. Ah su STAGE_A e STAGE_L ho messo l'area del mio stage, perché prendendole dinamicamente ho visto che (almeno in fase di debug) qualche volte ricevevo 956 e 546.

    La funzione funziona con lo stage allineato al centro, mi piacerebbe crearla per tutte le combinazioni possibile (Stage.align="T" "TL" "BL" e via dicendo).

    Codice PHP:
    import mx.transitions.Tween;
    import mx.transitions.easing.*;
    Stage.scaleMode "noScale";
    //Stage.align="T"
    var STAGE_L 960 //Stage.width;
    var STAGE_A 550 //Stage.height;
    // ############################################
    // # posizione un clip nello stage           
    // # il parametro lockStage permette di allinearsi allo stage iniziale invece di quello finale
    // ############################################
    MovieClip.prototype.posiziona = function(orizzontale:Stringverticale:Stringoffx:Numberoffy:NumberlockStage:Boolean):Void  {
        
    trace(STAGE_L);
        if (
    offx == undefined) {
            
    offx 0;
        }
        if (
    offy == undefined) {
            
    offy 0;
        }
        var 
    posx:Numberposy:Number;
        
    // posizione su asse x
        
    switch (orizzontale.toLowerCase()) {
        case 
    "left" :
        case 
    "l" :
            if (
    lockStage) {
                
    posx offx;
            } else {
                
    posx = (STAGE_L-Stage.width)/2+offx;
            }
            break;
        case 
    "right" :
        case 
    "r" :
            if (
    lockStage) {
                
    posx STAGE_L-this._width-offx;
            } else {
                
    posx = (STAGE_L-Stage.width)/2+Stage.width-this._width-offx;
            }
            break;
        case 
    "center" :
        case 
    "c" :
            
    posx = (STAGE_L-this._width)/2+offx;
        }
        
    posx Math.round(posx);
        
    //posizione su asse y
        
    switch (verticale.toLowerCase()) {
        case 
    "top" :
        case 
    "t" :
            if (
    lockStage) {
                
    posy offy;
            } else {
                
    posy = (STAGE_A-Stage.height)/2+offy;
            }
            break;
        case 
    "bottom" :
        case 
    "b" :
            if (
    lockStage) {
                
    posy = (Stage.height-this._height)-(Stage.height-STAGE_A)-offy;
            } else {
                
    posy = (Stage.height-this._height)-(Stage.height-STAGE_A)/2-offy;
            }
            break;
        case 
    "middle" :
        case 
    "m" :
            
    posy = (STAGE_A-this._height)/2+offx;    
            
    //posy = (Stage.height-this._height)/2+offy;
        
    }
        
    posy Math.round(posy);
        
    trace(Stage.width+" > "+posx+" "+Stage.height+" > "+posy);
        new 
    Tween(this"_x"Regular.easeOutthis._xposx.5true);
        new 
    Tween(this"_y"Regular.easeOutthis._yposy.5true);
    };
    var 
    listResize:Object = new Object();
    listResize.onResize = function() {
        
    menu.posiziona("r""b"00true);
    };
    Stage.addListener(listResize); 

  2. #2
    provato!!.. interessante Stan......

    non e' che puoi darmi una mano riguardo alla discussione dell'altra volta, sono andato avanti ma sono bloccato ora.. puoi vedere

    qui

    se puoi , grazie...

    -Nextart.it Graphic Solutions

  3. #3

  4. #4
    Ok, questa sistema la posizione in ogni scenario possibile. Non è molto elegante ma funziona, se qualcuno volesse migliorarla meglio ^^

    Tra l'altro ho notato nu comportamento assurdo dello Stage.align.

    Se imposti a BL e poi vai a leggere ti ritrovi LB, ovvero con le lettere capovolte. Alla fine non sarebbe manco tanto strano se non fosse che TR rimane TR ^^

    Codice PHP:
    // ############################################
    // # posizione un clip nello stage           
    // # il parametro lockStage permette di allinearsi allo stage iniziale invece di quello finale
    // ############################################
    MovieClip.prototype.posiziona = function(orizzontale:Stringverticale:Stringofx:Numberoffy:NumberlockStage:Boolean):Void  {
        if (
    offx == undefined) {
            
    offx 0;
        }
        if (
    offy == undefined) {
            
    offy 0;
        }
        var 
    posx:Numberposy:Number;

        
    // posizione su asse x
        
    switch (orizzontale.toLowerCase()) {
            case 
    "left" :
            case 
    "l" :
                
    // SE HO CHIESTO DI ALLINEARE A SINISTRA
                
    switch (Stage.align) {
                    case 
    "" :
                    case 
    "B" :
                    case 
    "T" :
                        
    //SE LO STAGE E' CENTRATO
                        
    if (lockStage) {
                            
    posx offx;
                        } else {
                            
    posx = (STAGE_L-Stage.width)/2+offx;
                        }
                        break;
                    case 
    "L" :
                    case 
    "LT" :
                    case 
    "LB" :
                        
    // SE LO STAGE E' A SX
                        
    posx offx;
                        break;
                    case 
    "R" :
                    case 
    "TR" :
                    case 
    "RB" :
                        
    // SE LO STAGE E' A DX
                        
    if (lockStage) {
                            
    posx offx;
                        } else {
                            
    posx STAGE_L-Stage.width+offx;
                        }
                        break;
                }
                break;
            case 
    "right" :
            case 
    "r" :
                
    // SE HO CHIESTO DI ALLINEARE A DESTRA
                
    switch (Stage.align) {
                    case 
    "" :
                    case 
    "B" :
                    case 
    "T" :
                        
    //SE LO STAGE E' CENTRATO
                        
    if (lockStage) {
                            
    posx STAGE_L-this._width-offx;
                        } else {
                            
    posx = (STAGE_L-Stage.width)/2+Stage.width-this._width-offx;
                        }
                        break;
                    case 
    "L" :
                    case 
    "LT" :
                    case 
    "LB" :
                        
    // SE LO STAGE E' A SX
                        
    if (lockStage) {
                            
    posx STAGE_L-this._width-offx;
                        } else {
                            
    posx Stage.width-this._width-offx;
                        }
                        break;
                    case 
    "R" :
                    case 
    "TR" :
                    case 
    "RB" :
                        
    // SE LO STAGE E' A DX
                        
    posx STAGE_L-this._width-offx;
                }
                break;
            case 
    "center" :
            case 
    "c" :
                
    // SE HO CHIESTO DI ALLINEARE AL CENTRO
                
    switch (Stage.align) {
                    case 
    "" :
                    case 
    "B" :
                    case 
    "T" :
                        
    //SE LO STAGE E' CENTRATO
                        
    posx = (STAGE_L-this._width)/2+offx;
                        break;
                    case 
    "L" :
                    case 
    "LT" :
                    case 
    "LB" :
                        
    // SE LO STAGE E' A SX
                        
    if (lockStage) {
                            
    posx = (STAGE_L-this._width)/2+offx;
                        } else {
                            
    posx = (Stage.width-this._width)/2+offx;
                        }
                        break;
                    case 
    "R" :
                    case 
    "TR" :
                    case 
    "RB" :
                        
    // SE LO STAGE E' A DX
                        
    if (lockStage) {
                            
    posx = (STAGE_L-this._width)/2+offx;
                        } else {
                            
    posx = (Stage.width-this._width)/2-(Stage.width-STAGE_L)+offx;
                        }
                        break;
                }
        }
        
    posx Math.round(posx);

        
    //posizione su asse y
        
    switch (verticale.toLowerCase()) {
            case 
    "top" :
            case 
    "t" :
                
    // SE HO CHIESTO DI ALLINEARE SOPRA
                
    switch (Stage.align) {
                    case 
    "" :
                    case 
    "L" :
                    case 
    "R" :
                        
    //SE LO STAGE E' CENTRATO VERTICALMENTE
                        
    if (lockStage) {
                            
    posy offy;
                        } else {
                            
    posy = (STAGE_A-Stage.height)/2+offy;
                        }
                        break;
                    case 
    "T" :
                    case 
    "LT" :
                    case 
    "TR" :
                        
    //SE LO STAGE E' ALLINEATO IN ALTO
                        
    posy 0;
                        break;
                    case 
    "B" :
                    case 
    "LB" :
                    case 
    "RB" :
                        
    //SE LO STAGE E' ALLINEATO IN ALTO
                        
    if (lockStage) {
                            
    posy 0;
                        } else {
                            
    posy = -Stage.height+STAGE_A;
                        }
                        break;
                }
                break;
            case 
    "bottom" :
            case 
    "b" :
                
    // SE HO CHIESTO DI ALLINEARE IN BASSO
                
    switch (Stage.align) {
                    case 
    "" :
                    case 
    "L" :
                    case 
    "R" :
                        
    //SE LO STAGE E' CENTRATO VERTICALMENTE
                        
    if (lockStage) {
                            
    posy = (Stage.height-this._height)-(Stage.height-STAGE_A)-offy;
                        } else {
                            
    posy = (Stage.height-this._height)-(Stage.height-STAGE_A)/2-offy;
                        }
                        break;
                    case 
    "T" :
                    case 
    "LT" :
                    case 
    "TR" :
                        
    //SE LO STAGE  E' ALLINEATO IN ALTO
                        
    if (lockStage) {
                            
    posy STAGE_A-this._height-offy;
                        } else {
                            
    posy Stage.height-this._height-offy;
                        }
                        break;
                    case 
    "B" :
                    case 
    "LB" :
                    case 
    "RB" :
                        
    //SE LO STAGE  E' ALLINEATO IN BASSO
                        
    posy STAGE_A-this._height-offy;
                        break;
                }
                break;
            case 
    "middle" :
            case 
    "m" :
                
    //SE HO CHIESTO DI CENTRARE VERTICALMENTE
                
    switch (Stage.align) {
                    case 
    "" :
                    case 
    "L" :
                    case 
    "R" :
                        
    //SE LO STAGE E' CENTRATO VERTICALMENTE
                        
    posy = (STAGE_A-this._height)/2+offx;
                        break;
                    case 
    "T":
                    case 
    "LT":
                    case 
    "TR":
                        
    //SE LO STAGE E' ALLINEATO IN ALTO
                        
    if (lockStage){
                            
    posy = (STAGE_A-this._height)/2+offx;
                        }else{
                            
    posy = (Stage.height-this._height)/2+offx;
                        }
                        break;
                    case 
    "B":
                    case 
    "LB":
                    case 
    "RB":
                        
    //SE LO STAGE E' ALLINEATO IN BASSO
                        
    if (lockStage){
                            
    posy = (STAGE_A-this._height)/2+offx;
                        }else{
                            
    posy = (Stage.height-this._height)/2-Stage.height+STAGE_A+offx;
                        }
                        break;
                }
        }
        
    posy Math.round(posy);
        
    //trace(Stage.width+" > "+posx+" "+Stage.height+" > "+posy);
        
    new Tween(this"_x"Strong.easeOutthis._xposx.8true);
        new 
    Tween(this"_y"Strong.easeOutthis._yposy.8true);
        
        
    }; 

  5. #5
    Utente di HTML.it L'avatar di skill83
    Registrato dal
    Mar 2002
    Messaggi
    2,024
    c'è un errore ofx offx penso....

  6. #6
    Sì vero, mi sono scordato di aggiornarlo, ma è piuttosto evidente che è facile per chiunque mettere a posto ^^

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.