Non c'è (almeno per quanto ne so) nessun modo per accedere ai comandi di zoom in/out del lettore flash tramite codice.
Si può fingere se effettuando le seguenti operazioni nella classe di documento (in alto oggetto di visualizzazione più in fase)
stage.addEventListener(MouseEvent.MOUSE_WHEEL,mouseWheel,true,2); //listen on the capture phase of the event and give a higher priority than default so it reacts before your grid
function mouseWheel(e:MouseEvent):void {
if(!e.ctrlKey) return; //Ctrl has to be pressed or we ignore the wheel
e.stopImmediatePropagation(); //this stops the event from firing on anything else, like your data grid
var tmpScale:Number = scaleX + (e.delta > 0 ? .2 : -.2); //lets zoom in/out in incriments of 20% (.1)
if(tmpScale < 1){ //if the scale is less than one now, lets keep it at 1
tmpScale = 1;
this.scaleX = 1;
this.x = 0;
this.scaleY = 1;
this.y = 0;
return;
}
if(tmpScale > 4){ //lets set the max to 4
tmpScale = 4;
}
scaleAroundMouse(this,tmpScale);
}
function scaleAroundMouse(objectToScale:DisplayObject, scaleAmount:Number, bounds:Rectangle = null):void {
// scaling will be done relatively
var relScaleX:Number = scaleAmount/objectToScale.scaleX;
var relScaleY:Number = scaleAmount/objectToScale.scaleY;
// map vector to centre point within parent scope
var scalePoint:Point = objectToScale.localToGlobal(new Point(objectToScale.mouseX, objectToScale.mouseY));
scalePoint = objectToScale.parent.globalToLocal(scalePoint);
// current registered postion AB
var AB:Point = new Point(objectToScale.x, objectToScale.y);
// CB = AB - scalePoint, objectToScale vector that will scale as it runs from the centre
var CB:Point = AB.subtract(scalePoint);
CB.x *= relScaleX;
CB.y *= relScaleY;
// recaulate AB, objectToScale will be the adjusted position for the clip
AB = scalePoint.add(CB);
// set actual properties
if(bounds){
var limits:Rectangle = new Rectangle(
bounds.x + (bounds.width - (objectToScale.width * relScaleX)),
bounds.y + (bounds.height - (objectToScale.height * relScaleY)),
(objectToScale.width * relScaleX) - bounds.width,
(objectToScale.height * relScaleY) - bounds.height
);
if(AB.x < limits.x) AB.x = limits.x;
if(AB.x > limits.x + limits.width) AB.x = limits.x + limits.width;
if(AB.y < limits.y) AB.y = limits.y;
if(AB.y > limits.y + limits.height) AB.y = limits.y + limits.height;
}
objectToScale.scaleX = scaleAmount;
objectToScale.scaleY = scaleAmount;
objectToScale.x = AB.x;
objectToScale.y = AB.y;
}
Nizza domanda. Penso che la soluzione nativa sia impossibile. –
C'è un altro modo per fare lo zoom. Voglio fare lo zoom in advancedatagrid usando ctrl + mousewheel. Lo scaling – AsadYarKhan