oquinquil265
Messages postés2Date d'inscriptionjeudi 3 mars 2011StatutMembreDernière intervention15 avril 2011
-
30 mars 2011 à 15:17
oquinquil265
Messages postés2Date d'inscriptionjeudi 3 mars 2011StatutMembreDernière intervention15 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();
}
oquinquil265
Messages postés2Date d'inscriptionjeudi 3 mars 2011StatutMembreDernière intervention15 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;
//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;
}
}
}
//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);