Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

freitag

[Resolvido] "toolTip" de uma IMAGEM criada dinamicamente.

Recommended Posts

Oi Pessoal

 

Estou tentando pegar imagens de um canvas e colocar em outro canvas alocando elas dinamicamente, mas com isso não consigo mais acessar algumas propriedades dela.

 

Abaixo o meu código destaco que o problema está nesta parte:

//--------------------------------------HERE IS MY PROBLEM

aImg.tooltip = canvasID_0.getChildAt(i).toolTip;

//--------------------------------------HERE IS MY PROBLEM

 

 

Como faço para pegar o toolTip de uma imagem criada dinamicamente.

 

 


<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">

    <mx:Script>
        <![CDATA[
          [Bindable]
          [Embed(source="trash.jpg")]
          private var img_01:Class;
        
            import mx.messaging.management.ObjectInstance;
            import mx.controls.TextInput;
            import mx.controls.Image;
            import mx.containers.Canvas;
            import mx.events.DragEvent;
      import mx.containers.Canvas;
      import mx.managers.DragManager;
      import mx.core.DragSource;
            import mx.core.Application;
        import mx.controls.Alert;
        import mx.managers.ToolTipManager;
        import mx.collections.ArrayCollection;
      import mx.controls.Alert;
        import mx.core.UITextField;
      import mx.controls.ToolTip; 
                    
            private function dragInit(event:MouseEvent, img:Class):void 
      {
        var objectoDrag:Image = event.currentTarget as Image;
        var origemDrag:DragSource = new DragSource();
        
        ToolTipManager.enabled = true;
        ToolTipManager.showDelay = 0;
        ToolTipManager.hideDelay = 10000;

        origemDrag.addData(img, 'img');
        origemDrag.addData(objectoDrag.width, 'width');
        origemDrag.addData(objectoDrag.height, 'height');
        origemDrag.addData(objectoDrag.toolTip, 'toolTip');

        
        var dragProxy:Image = new Image();
        dragProxy.source = event.currentTarget.source;

        DragManager.doDrag(objectoDrag, origemDrag, event, dragProxy);
      }
           
      private function dragEnterHandler(event:DragEvent):void 
      {
        var dropTarget:Canvas=event.currentTarget as Canvas;
      
        if (event.dragSource.hasFormat('img')) 
        {                   
          DragManager.acceptDragDrop(dropTarget);
        }
      }
      private function dragDropHandler(event:DragEvent):void 
      {
        var image:Image = new Image;
        var img:Class = event.dragSource.dataForFormat('img') as Class;
        var imageW:Number=event.dragSource.dataForFormat('width') as Number;
        var imageH:Number=event.dragSource.dataForFormat('height') as Number;
        var toolTipN:String=event.dragSource.dataForFormat('toolTip') as String;
  
        image.toolTip = toolTipN;
        image.addEventListener(MouseEvent.MOUSE_DOWN, initDrag,false,0,true);
        image.addEventListener(MouseEvent.MOUSE_UP, draggedStop,false,0,true);
        image.includeInLayout=false;
        image.x=event.currentTarget.mouseX-(imageW/2)-2; //-2 border
        image.y=event.currentTarget.mouseY-(imageH/2)-2; 
        image.source=img;
     
        if( (event.currentTarget.mouseX + (imageW/3)) < canvasID_0.width
              &&
          ( (event.currentTarget.mouseY + (imageH/3)) < canvasID_0.height)
        ) 
        {
         (event.currentTarget as Canvas).addChild(image);
        } 
      }
      
      private function initDrag(evt:MouseEvent):void 
      {
        (evt.currentTarget as Image).startDrag();
      }
      
      private function draggedStop(event:MouseEvent):void 
      {
        (event.currentTarget as Image).stopDrag();
        if(this.mouseX > canvasID_0.width || this.mouseY>canvasID_0.height ) 
        {
          canvasID_0.removeChild(event.currentTarget as Image);           
        } 
      }
  
      private function creationCompleteHandler(event:Event):void
      {
        var aImg:Array = new Array(
            {image: "0 IMG INI", tooltip: "0 tooltip", top: 0, lelf: 0},
            {image: "1 IMG INI", tooltip: "1 tooltip", top: 1, lelf: 1}          
          );
        var i:int;
       
             
        i=0;
        while(i < canvasID_0.numChildren) 
        {
        aImg[i].image = canvasID_0.getChildAt(i).name;
        //--------------------------------------HERE IS MY PROBLEM
        aImg[i].tooltip = canvasID_0.getChildAt(i).toolTip;
        //--------------------------------------HERE IS MY PROBLEM          
          aImg[i].top = canvasID_0.getChildAt(i).x;
          aImg[i].lelf = canvasID_0.getChildAt(i).y;
          i++;
        }
        imagensChild.dataProvider = aImg; 
      
      }
    ]]>
  </mx:Script>

    <mx:Canvas x="10" y="10" width="334.5" height="332" id="canvasID_0" dragEnter="dragEnterHandler(event);"  dragDrop="dragDropHandler(event);"  borderColor="#4380AA" backgroundColor="#FFFFFF" >
    </mx:Canvas>  
  <mx:Canvas x="371.25" y="10" width="334.5" height="332" id="canvasID_1" dragEnter="dragEnterHandler(event);"  dragDrop="dragDropHandler(event);"  borderColor="#4380AA" backgroundColor="#FFFFFF" >

  <mx:Image x="103.25" y="99" source="{img_01}" mouseMove="dragInit(event, img_01)" useHandCursor="true" buttonMode="true" toolTip="dica aqui" dragEnter="dragEnterHandler(event);"  dragDrop="dragDropHandler(event);"/>

  </mx:Canvas>
     <mx:DataGrid id="imagensChild" x="10" y="359">
      <mx:columns>
        <mx:DataGridColumn headerText="Image" 
           dataField="image"/>
        <mx:DataGridColumn headerText="Tool Tip"  
           dataField="tooltip"/>
        <mx:DataGridColumn headerText="Top"  
           dataField="top"/>
        <mx:DataGridColumn headerText="Left"  
           dataField="lelf"/>           
      </mx:columns>
    </mx:DataGrid>
  <mx:Button x="10" y="509" label="Get Data From child" click="creationCompleteHandler(event);" width="142"/>
   
   
   
</mx:Application>

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.