2013-03-01 12 views
10

Desidero richiamare la funzione di ingrandimento e riduzione del menu di scelta rapida dal pulsante personalizzato Nell'applicazione Adobe Flex.Chiamare lo zoom avanti e indietro dal menu di scelta rapida dal pulsante personalizzato in flex3

Codice qualcosa di simile:

onZoomInButtonClick() 
{ 
this.contextMenu.customItems.zoom.doIn(); 
} 
+1

Nizza domanda. Penso che la soluzione nativa sia impossibile. –

+0

C'è un altro modo per fare lo zoom. Voglio fare lo zoom in advancedatagrid usando ctrl + mousewheel. Lo scaling – AsadYarKhan

risposta

3

Ok, advancedatagrid può ascoltare eventi della tastiera, quando il tasto Ctrl - per ascoltare gli eventi rotellina del mouse e scala il cambiamento, vedi esempio:

<?xml version="1.0" encoding="utf-8"?> 
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
       xmlns:s="library://ns.adobe.com/flex/spark" 
       xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"> 
     <fx:Script> 
      <![CDATA[ 

       protected function doMouseWheel(evt:MouseEvent):void 
       { 
        scaleX = scaleY += evt.delta * 0.1; 
       } 

       protected function adg_keyDownHandler(event:KeyboardEvent):void 
       { 
        if (event.ctrlKey) 
        { 
         systemManager.addEventListener(MouseEvent.MOUSE_WHEEL, doMouseWheel); 
        } 
       } 

       protected function adg_keyUpHandler(event:KeyboardEvent):void 
       { 
        if (!event.ctrlKey) 
        { 
         systemManager.removeEventListener(MouseEvent.MOUSE_WHEEL, doMouseWheel); 
        } 
       } 

      ]]> 
     </fx:Script>  

     <mx:AdvancedDataGrid id="adg" keyDown="adg_keyDownHandler(event)" keyUp="adg_keyUpHandler(event)" 
          horizontalCenter="0" verticalCenter="0"> 
      <mx:columns> 
       <mx:AdvancedDataGridColumn dataField="@label"/> 
       <mx:AdvancedDataGridColumn dataField="@data" /> 
      </mx:columns> 
      <mx:dataProvider> 
       <s:XMLListCollection id="dp"> 
        <s:source> 
         <fx:XMLList> 
          <product label="Product 1" data="3" /> 
          <product label="Product 2" data="1" /> 
          <product label="Product 3" data="4" /> 
          <product label="Product 4" data="1" /> 
          <product label="Product 5" data="5" /> 
          <product label="Product 6" data="9" /> 
         </fx:XMLList> 
        </s:source> 
       </s:XMLListCollection> 
      </mx:dataProvider> 
     </mx:AdvancedDataGrid> 

    </s:Application> 
+0

non sta producendo il risultato di qualità. Voglio la funzione di zoom. – AsadYarKhan

+0

pensi ci siano delle differenze? –

+0

sì nel ridimensionamento si aumenta la larghezza e l'altezza dell'oggetto ma nello zoom si gioca con la tela, si veda questo http://superuser.com/questions/153998/whats-the-difference-between-zoom-and-scale-in- gimp – AsadYarKhan

2

Per lo zoom dentro/fuori una grafica vettoriale, si cambiano chiaramente le sue proprietà scaleX e scaleY in modo uniforme. Il renderer vettoriale di Flash ti disegna un'immagine corretta. Al fine di zoomare su una bitmap e non ottenere un output di pixel, è necessario convertirlo in un vettore oggetto grafico come questo:

var sh:Shape=new Shape(); 
sh.graphics.beginBitmapFill(yourBitmap); 
sh.graphics.lineStyle(0,0,0); // to not have border lines 
sh.graphics.drawRect(0,0,yourBitmap.width,yourBitmap.height); 
sh.graphics.endFill(); 

E poi regolando scaleX e scaleY di quella forma produrrà uscita interpolata come apparentemente volere.

+0

Il mio oggetto è advancedDatagrid o Grid.Voglio zoomare non bitmap :) – AsadYarKhan

+0

Devi scendere alle primitive. Inoltre, controlla se il 'cacheAsBitmap' della griglia di dati è falso. – Vesper

+0

cosa spiegare per favore vai in primitice ?? – AsadYarKhan

7

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; 
} 
+0

Grazie il tuo codice è quasi funzionante ma Se queste cose si risolvono sarà contrassegnato come risposta e bounty is urs .: – AsadYarKhan

+0

per favore come disabilitare lo scroll scroll quando ctrl è premere, quando premo control e scorri sulla griglia inizia a scorrere verticalmente piuttosto che a zoomare. – AsadYarKhan

+0

In secondo luogo, quando fornisco questo (oggetto dell'applicazione ingrandisce la scala 4) ma quando fornisco l'oggetto griglia allora non esegue lo zoom solo una volta significa solo una volta che scala l'oggetto, continuo a scorrere dopo non ingrandisce di più affatto .. ??? why – AsadYarKhan

Problemi correlati