Prototype de size

Résolu
cs_caviar Messages postés 329 Date d'inscription samedi 4 janvier 2003 Statut Membre Dernière intervention 29 mars 2015 - 15 nov. 2007 à 12:20
cs_caviar Messages postés 329 Date d'inscription samedi 4 janvier 2003 Statut Membre Dernière intervention 29 mars 2015 - 16 nov. 2007 à 09:29
    Saluté ...
j'ai un petit problème de prototype pour gérer la taille ...
voici le code que j'ai

//---------------------------------------------------
MovieClip.prototype.size = function(wdth, hght, acc) {
    // loader._visible = 1;
    trace('yo'+this._width);
    w = (wdth-this._width)/acc;
    h = (hght-this._height)/acc;
    if (Math.abs(w)<.1 && Math.abs(h)<.1) {
        delete this.onEnterFrame; //pk ça s'arrete pas ?
    } else {
        this._width += w;
        this._height += h;
       
    }
};
this.onEnterFrame = function() {
    c.size(154.2, 450, 4);
};

bon le truc c'est que la ligne delete this.onEnterFrame; //pk ça s'arrete pas ? ne semble jamais s'exécuter puisque mon trace continue sans cesse...

ensuite j'aimerai bien pouvoir spécifier une seule des deux valeurs wdth ou hght, et que l'autre se calcule proportionnellement par rapport à la taille de départ du clip (et du ration l/h en fait ...)

bref j'ai besoin d'un peu d'aide d'un matheux sur ce coup je crois ...
thxx !
@++

2 réponses

cs_caviar Messages postés 329 Date d'inscription samedi 4 janvier 2003 Statut Membre Dernière intervention 29 mars 2015 2
16 nov. 2007 à 09:29
    hop ... voila un proto pour ceux que ça intéresse

/*****ZOOM TAILLE ******/
function zoomClip(objet, X, Y, speed) {
    trace('zoom');
    if (!zoomClip_array) {
        zoomClip_array = [[], []];
    }
    var found = false;
    for (i=0; i<=zoomClip_array[0].length; i++) {
        if (zoomClip_array[0][i] == objet) {
            found = true;
            if (zoomClip_array[1][i] != objet._zoom) {
                clearInterval(zoomClip_array[1][i]);
                zoomClip_array[1][i] = objet._zoom;
            }
            if ((Math.ceil(objet._width)<(Math.ceil(X-1))) || (Math.ceil(objet._width)>(Math.ceil(X+1)))) {
                objet._width += (X-objet._width)/speed;
            } else {
                objet._width = X;
            }
            if ((Math.ceil(objet._height)<(Math.ceil(Y-1))) || (Math.ceil(objet._height)>(Math.ceil(Y+1)))) {
                objet._height += (Y-objet._height)/speed;
            } else {
                objet._height = Y;
            }            if ((objet._width X) && (objet._height Y)) {
                clearInterval(objet._zoom);
            }
        }
    }
    if (found == false) {
        var long = zoomClip_array[0].length;
        zoomClip_array[0][long] = objet;
        zoomClip_array[1][long] = objet._zoom;
    }
}
MovieClip.prototype.zoom = function(targetX, targetY, speed) {
        //trace(targetY+'   '+this._width+'  scale='+this._xscale);
    //c'est ici qu'on recalcule les proportions si une n'est pas donnée
    tailleOriginX = (this._width/this._xscale)*100;
    tailleOriginY = (this._height/this._yscale)*100;
    ratio = tailleOriginX/tailleOriginY
    //trace ('ratio='+ratio);
    //trace('tailleOriginX ='+tailleOriginX+'tailleOriginY ='+tailleOriginY);
    if (targetX == '') {
        targetX = targetY/ratio;
    }
    if (targetY == '') {
        targetY = targetX/ratio;
    }
    clearInterval(this._zoom);
    this._zoom = setInterval(zoomClip, 40, this, targetX, targetY, speed);
};

peut s'utiliser comme ça

monclip.zoom (400,'',20);
le param vide sera automatiquement calculé au ratio ;)
@+
3
cs_goldenboy68 Messages postés 1596 Date d'inscription samedi 3 janvier 2004 Statut Membre Dernière intervention 9 juin 2011 2
16 nov. 2007 à 09:03
tu déclares ton "onEnterFrame" à l'extérieur du MovieClip avec "this" et tu veux le supprimer à l'intérieur avec "this" aussi...y'a forcément un problème, le "this" renvoie certainement pas la même chose dans les 2 cas (tu peux vérifier avec un trace(this); . faudra éventuellement jouer avec this._parent ou en désespoir avec _root .

Pour ton problème de redimensionnement :
        ratioImage = cible._width/cible._height;
        if (ratioImage>(limiteImageW/limiteImageH)) {
            cible._width = limiteImageW;
            cible._height = cible._width/ratioImage;
        } else {
            cible._height = limiteImageH;
            cible._width = cible._height*ratioImage;
        }
=> à modifier en fonction de ce que tu veux vraiment.

@+! Samy
0
Rejoignez-nous