Zoom avec cadre en AS3

oquinquil265 Messages postés 2 Date d'inscription jeudi 3 mars 2011 Statut Membre Dernière intervention 15 avril 2011 - 30 mars 2011 à 15:17
oquinquil265 Messages postés 2 Date d'inscription jeudi 3 mars 2011 Statut Membre Dernière intervention 15 avril 2011 - 1 avril 2011 à 09:35
bonjour a tous !
J'essaie de "traduire" un code AS2 en AS3. Le code en question, permet de zoomer sur une image en affichant la partie zoomée dans un cadre externe a l'image.
voici mon code en AS3 qui ne marche pas comme il faudrait...
Merci d'avance pour votre aide !
bonne fin de journée.



var conteneur:Sprite = new Sprite();
conteneur.addChild(grande);
var grande:Sprite = new Sprite();
conteneur.addChild(grande);
conteneur.addChild(masque);
grande.mask = masque;



var masquelar=masque.width;
var masquelong=masque.height;
var masquex=masque.x;
var masquey=masque.y;
var viseurlar=viseur.width;
var viseurlong=viseur.height;
var petitelar=petite.width;
var petitelong=petite.height;
var grandelar=grande.width;
var grandelong=grande.height;
var petitex=petite.x;
var petitey=petite.y;
var rapport=grandelar/petitelar;

//permet de placer automatiquement le viseur
viseur.x=petitex + (petitelar/2);

//au centre de la petite carte
viseur.y=petitey + (petitelong/2);


//viseur btn
viseur.addEventListener(MouseEvent.MOUSE_DOWN, mousedown);
function mousedown(event:MouseEvent):void {
//The x & y coordinates of the top-left corner of the rectangle.
var my_x2:int = petitex + (viseurlar/2);
var my_y2:int = petitey + (viseurlar/2);

//The height and width of the rectangle.
var myWidth2:int = (petitex + petitelar - (viseurlong/2)) - my_x2
var myHeight2:int = (petitey + petitelong - (viseurlong/2)) - my_y2;

//Create a new instance of the rectangle class with the coordinates above.
var boundArea:Rectangle=new Rectangle(my_x2, my_y2, myWidth2 ,myHeight2);

startDrag(true,boundArea);
}

viseur.addEventListener(MouseEvent.MOUSE_UP, mouseup);
function mouseup(event:MouseEvent):void {
stopDrag();
}


grande.addEventListener(Event.ENTER_FRAME, fl_EnterFrameHandler);

function fl_EnterFrameHandler(event:Event):void
{
grande.x=(masquex+(masquelar/2))-((viseur.x-petitex)*rapport);
grande.y=(masquey+(masquelong/2))-((viseur.y-petitey)*rapport);
}

4 réponses

pegase31 Messages postés 6138 Date d'inscription dimanche 21 décembre 2003 Statut Modérateur Dernière intervention 4 septembre 2013 12
30 mars 2011 à 16:44
Pour permettre aux gens de te répondre, le mieux serait d'expliquer ce qui ne fonctionne pas comme il faudrait.

Peg'
Admin Codes-Sources
0
aerolyte Messages postés 465 Date d'inscription mardi 17 avril 2007 Statut Membre Dernière intervention 4 mai 2013 1
30 mars 2011 à 23:22
Bonjour,

De mémoire, le script complet en AS3 est fourni dans la doc officiel

Cordialement
0
piere2 Messages postés 235 Date d'inscription lundi 26 février 2007 Statut Membre Dernière intervention 26 mai 2013
31 mars 2011 à 09:34
Bonjour,
Commence par déclarer tes variables avant de les utiliser.
Ensuite il faudrait aussi déclarer le type de la variable ex:

grande n'est pas déclarée.

ensuite tu écris:

var grandelar = grande.width;

au lieu de:

var grandelar:int = grande.width;


Pi'ère2
0
oquinquil265 Messages postés 2 Date d'inscription jeudi 3 mars 2011 Statut Membre Dernière intervention 15 avril 2011
1 avril 2011 à 09:35
Merci à tous pour vos réponses. Ne sachant pas maitriser les sprites, classes... j'ai refait un autre programme en AS3 beaucoup plus efficace. Il permet de réaliser un zoom centré sur le pointeur de la souris,le zoom en question étant borné et suivant un profil en puissance. Bien sur le drag & drop est disponible ! De plus l'image ne sort jamais du cadre de ma fenêtre lors d'un zoom arrière. Je poste le code, si des personnes sont intéressées...
//définitions des variables d'entrée
mc_board.width = mc_image.width;
mc_board.height = mc_image.height;
mc_image.x=mc_board.x;
mc_image.y=mc_board.y;


mc_image.addEventListener(MouseEvent.MOUSE_DOWN, startDragging);
stage.addEventListener(MouseEvent.MOUSE_UP, stopDragging);

//drag-and-drop appliqué à l'image
function startDragging(mev:MouseEvent):void {

//The x & y coordinates of the top-left corner of the rectangle.
var my_x:int = mc_board.x - (mc_image.width - mc_board.width);
var my_y:int = mc_board.y - (mc_image.height - mc_board.height);

//The height and width of the rectangle.
var myWidth:int = mc_image.width - mc_board.width;
var myHeight:int = mc_image.height - mc_board.height;

//Create a new instance of the rectangle class with the coordinates above.
var boundArea:Rectangle=new Rectangle(my_x, my_y, myWidth ,myHeight);

mc_image.startDrag(false,boundArea);
}

function stopDragging(mev:MouseEvent):void {
mc_image.stopDrag();
}


//Définition des variables pour la fonction zoom
var tempX = mc_image.x; // position du point de transformation avant redimensionnement
var tempY = mc_image.y; // position du point de transformation avant redimensionnement
var tempW = mc_image.width; // largeur du conteneur avant redimensionnement
var tempH = mc_image.height; // hauteur du conteneur avant redimensionnement
var resultW = mc_image.width; // largeur obtenue par le redimensionnement
var resultH = mc_image.height; // hauteur obtenue par le redimensionnement
var ratio = 1.1; // définition du ratio fixe pour le zoom

//Paramètres de réglage du zoom de mc_image
var stepZoom = 0.1; //pas du zoom
var cptZoom = 1.0; //initialisation du compteur
var factorZoomIn = 1; //facteur multiplicatif du zoom+
var factorZoomOut = 1; //facteur multiplicatif du zoom-
var zoomMax = 1.5; //valeur maximale du zoom+
var zoomMin = 1; //valeur minimale du zoom-
var nb_ite_in = Math.ceil((zoomMax - zoomMin)/(stepZoom*factorZoomIn))*3;


//Zoom en utilisant la molette de la souris
var cptZoomCurseur = 0;
mc_image.addEventListener(MouseEvent.MOUSE_WHEEL, zoomCurseur);
function zoomCurseur(e:MouseEvent):void // Zoom sur la position du curseur
{
if (e.delta > 0) { //delta > 0 lorsque la molette va vers l'avant : réduction
if (cptZoomCurseur > 0) {
cptZoomCurseur = Math.max(cptZoomCurseur - (e.delta), 0);
trace(cptZoomCurseur);
if ( cptZoom >= (zoomMin + (factorZoomOut*stepZoom)) ) {
mc_image.width /= cptZoom;
mc_image.height /= cptZoom;
cptZoom = cptZoom - (factorZoomOut*stepZoom);
}
else {
mc_image.width /= cptZoom;
mc_image.height /= cptZoom;
cptZoom = zoomMin;
}
}
}
else { //delta < 0 lorsque la molette va vers l'arrière : agrandissement
if (cptZoomCurseur < nb_ite_in) {
cptZoomCurseur = Math.min(cptZoomCurseur - (e.delta), nb_ite_in);
trace(cptZoomCurseur);
if ( cptZoom <= (zoomMax - (factorZoomIn*stepZoom)) ) {
cptZoom = cptZoom + (factorZoomIn*stepZoom);
mc_image.width *= cptZoom;
mc_image.height *= cptZoom;
}
else {
cptZoom = zoomMax;
mc_image.width *= cptZoom;
mc_image.height *= cptZoom;
}
}
}

mc_image.x += (tempW - mc_image.width)/(tempW/(mc_image.parent.mouseX - tempX));
mc_image.y += (tempH - mc_image.height)/(tempH/(mc_image.parent.mouseY - tempY));
tempX = mc_image.x;
tempY = mc_image.y;
tempW = mc_image.width;
tempH = mc_image.height;

//permet de recentrer l'image sur mc_board à tout moment.
mc_image.addEventListener(MouseEvent.MOUSE_WHEEL, startDragging2);
function startDragging2(mev:MouseEvent):void {

//The x & y coordinates of the top-left corner of the rectangle.
var my_x:int = mc_board.x - (mc_image.width - mc_board.width);
var my_y:int = mc_board.y - (mc_image.height - mc_board.height);

//The height and width of the rectangle.
var myWidth:int = mc_image.width - mc_board.width;
var myHeight:int = mc_image.height - mc_board.height;

//Create a new instance of the rectangle class with the coordinates above.
var boundArea:Rectangle=new Rectangle(my_x, my_y, myWidth ,myHeight);

mc_image.startDrag(false,boundArea);
}
}
0
Rejoignez-nous