Redimensionner et tourner un clip a l'aide des fleches

Contenu du snippet

soit un clip sur la scene que l'on peut deplacer avec la souris. On peut egalement avec les fleches du clavier le faire tourner et le redimensionner.

Source / Exemple :


import flash.geom.Transform;
import flash.geom.Matrix;

plasrou_mc.onPress = function() {
	this.startDrag(false);
};
plasrou_mc.onRelease = function() {
	this.stopDrag();
};
var num:Number = new Number();
var numleft = -5;
var numright = 5;
var nume = 1;
var compta:Number = 0;
var comptb:Number = 0;
var comptc:Number = 0;
var comptd:Number = 0;

var mouseListener:Object = new Object();
mouseListener.onMouseUp = function():Void  {
	if (plasrou_mc.hitTest(_xmouse, _ymouse)) {
		
		var posxrect = plasrou_mc._x;
		var posyrect = plasrou_mc._y;
		
		var keyListener:Object = new Object();
		keyListener.onKeyDown = function() {
			var tourneMatrix:Matrix = new Matrix();
			var translateMatrix:Matrix = new Matrix();
			var neo:Transform = new Transform(plasrou_mc);
			var echelleMatrix:Matrix = new Matrix();
			
			if (Key.isDown(Key.LEFT)) {
				compta = 1;
				if ((compta != comptc) && (compta != comptd)) {
					numleft = numleft-5;
					num = numleft+numright;
					tourneMatrix.rotate(num*Math.PI/180);
					translateMatrix.translate(posxrect,posyrect);
					tourneMatrix.concat(translateMatrix);
					dadaMatrix = tourneMatrix.clone();
				} else {
					numleft = numleft-5;
					num = numleft+numright;
					tourneMatrix.rotate(num*Math.PI/180);
					translateMatrix.translate(posxrect,posyrect);
					tourneMatrix.concat(translateMatrix);
					dadaMatrix = tourneMatrix.clone();
					tourneMatrix.concat(dodoMatrix);
					tourneMatrix.tx = posxrect;
					tourneMatrix.ty = posyrect;
				}
				neo.matrix = tourneMatrix;
				
			} else if (Key.isDown(Key.RIGHT)) {
				comptb = 1;
				if ((comptb != comptc) && (comptb != comptd)) {
					numright = numright+5;
					num = numright+numleft;
					tourneMatrix.rotate(num*Math.PI/180);
					translateMatrix.translate(posxrect,posyrect);
					tourneMatrix.concat(translateMatrix);
					dadaMatrix = tourneMatrix.clone();
				} else {
					numright = numright+5;
					num = numright+numleft;
					tourneMatrix.rotate(num*Math.PI/180);
					translateMatrix.translate(posxrect,posyrect);
					tourneMatrix.concat(translateMatrix);
					dadaMatrix = tourneMatrix.clone();
					tourneMatrix.concat(dodoMatrix);
					tourneMatrix.tx = posxrect;
					tourneMatrix.ty = posyrect;
				}
				neo.matrix = tourneMatrix;

			} else if (Key.isDown(Key.UP)) {
				comptc = 1;
				if ((comptc != compta) && (comptc != comptb)) {
					nume = nume+0.1;
					echelleMatrix.scale(nume,nume);
					translateMatrix.translate(posxrect,posyrect);
					echelleMatrix.concat(translateMatrix);
					dodoMatrix = echelleMatrix.clone();
				} else {
					nume = nume+0.1;
					echelleMatrix.scale(nume,nume);
					translateMatrix.translate(posxrect,posyrect);
					echelleMatrix.concat(translateMatrix);
					dodoMatrix = echelleMatrix.clone();
					echelleMatrix.concat(dadaMatrix);
					echelleMatrix.tx = posxrect;
					echelleMatrix.ty = posyrect;
				}
				neo.matrix = echelleMatrix;
				
			} else if (Key.isDown(Key.DOWN)) {
				comptd = 1;
				if ((comptd != compta) && (comptd != comptb)) {
					nume = nume-0.1;
					echelleMatrix.scale(nume,nume);
					translateMatrix.translate(posxrect,posyrect);
					echelleMatrix.concat(translateMatrix);
					dodoMatrix = echelleMatrix.clone();
				} else {
					nume = nume-0.1;
					echelleMatrix.scale(nume,nume);
					translateMatrix.translate(posxrect,posyrect);
					echelleMatrix.concat(translateMatrix);
					dodoMatrix = echelleMatrix.clone();
					echelleMatrix.concat(dadaMatrix);
					echelleMatrix.tx = posxrect;
					echelleMatrix.ty = posyrect;
				}
				neo.matrix = echelleMatrix;
			}
		};
		Key.addListener(keyListener);
	}
}
Mouse.addListener(mouseListener);

Conclusion :


Si quelqu'un a un code plus compact je suis preneur.

A voir également

Vous n'êtes pas encore membre ?

inscrivez-vous, c'est gratuit et ça prend moins d'une minute !

Les membres obtiennent plus de réponses que les utilisateurs anonymes.

Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.

Le fait d'être membre vous permet d'avoir des options supplémentaires.