Acabei de testar o seu código aqui e funciona sim. Só tive q fazer uma pqna
alteracao:
applicationComplete = "init()"  :) ... nos exemplos q vc mandou vc nao
referencia o init em nenhum momento.

Outra coisa, nesse exemplo, vc precisa considerar a largura/altura do
componente q está sendo arrastado em relação o x,y do startDrag, isso para q
o seu componente "nao estoure" os limites da área, pois a constraint só
considera 'dentro da área' o ponto onde o mouse está dentro do seu
componente.

E, por final, vc também precisa considerar a posição do seu canvas em
relação ao stage. Pesquise pelos métodos "globalToLocal" e "localToGlobal"
para q vc pegue o x,y do seu canvas em relação a posição global do stage.


Agora, como eu disse no primeiro e-mail, talvez acho q seja melhor vc
trabalhar com a classe DragManager.. é muito fácil trabalhar com ela, ale'm
dq esse tipo de operação (validar e restringir área de drop) é uma baba..
veja o exemplo desse link (Example: Simple drag-and-drop operation for a
nonlist-based control):

http://help.adobe.com/en_US/Flex/4.0/UsingSDK/WS2db454920e96a9e51e63e3d11c0bf69084-7cfe.html#WS2db454920e96a9e51e63e3d11c0bf64595-7ff4


[]'s





2011/8/22 Principe borodin <[email protected]>

> o canvas continua dando barra de rolagem...
>
> On Aug 22, 12:56 pm, Principe borodin <[email protected]>
> wrote:
> > deu certo nao
> >
> > nem assim...
> > <?xml version="1.0" encoding="utf-8"?>
> > <s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009";
> >                                            xmlns:s="library://
> ns.adobe.com/flex/spark"
> >                                            xmlns:mx="library://
> ns.adobe.com/flex/mx" width="700"
> > height="600">
> >         <fx:Declarations>
> >                 <!-- Place non-visual elements (e.g., services, value
> objects) here
> > -->
> >         </fx:Declarations>
> >         <fx:Script>
> >                 <![CDATA[
> >
> >                         import mx.events.DragEvent;
> >                         import flash.geom.Rectangle;
> >                         private var area:Rectangle= new
> > Rectangle(canvas.x,canvas.y,canvas.width,canvas.height);;
> >                         private function init():void
> >                         {
> >                                 area = new
> > Rectangle(canvas.x,canvas.y,canvas.width,canvas.height);
> >
> campo.addEventListener(MouseEvent.MOUSE_DOWN,sd);
> >
> campo.addEventListener(MouseEvent.MOUSE_UP,sot);
> >                         }
> >                         private function sd(event:MouseEvent):void
> >                         {
> >
> event.currentTarget.startDrag(false,area);
> >                         }
> >                         private function sot(event:MouseEvent):void
> >                         {
> >                                 event.currentTarget.stopDrag();
> >                         }
> >                 ]]>
> >         </fx:Script>
> >         <mx:Canvas id="canvas" x="20" y="20" width="500" height="400">
> >                 <s:TextInput id="campo" x="20" y="20"/>
> >         </mx:Canvas>
> > </s:WindowedApplication>
> >
> > e nem assim...
> >
> > <?xml version="1.0" encoding="utf-8"?>
> > <s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009";
> >                                            xmlns:s="library://
> ns.adobe.com/flex/spark"
> >                                            xmlns:mx="library://
> ns.adobe.com/flex/mx" width="700"
> > height="600">
> >         <fx:Declarations>
> >                 <!-- Place non-visual elements (e.g., services, value
> objects) here
> > -->
> >         </fx:Declarations>
> >         <fx:Script>
> >                 <![CDATA[
> >
> >                         import flash.geom.Rectangle;
> >                         import mx.events.DragEvent;
> >                         private var area:Rectangle;
> >                         private function init():void
> >                         {
> >                                 area = new
> > Rectangle(canvas.x,canvas.y,canvas.width,canvas.height);
> >
> campo.addEventListener(MouseEvent.MOUSE_DOWN,sd);
> >
> campo.addEventListener(MouseEvent.MOUSE_UP,sot);
> >                         }
> >                         private function sd(event:MouseEvent):void
> >                         {
> >
> event.currentTarget.startDrag(false,area);
> >                         }
> >                         private function sot(event:MouseEvent):void
> >                         {
> >                                 event.currentTarget.stopDrag();
> >                         }
> >                 ]]>
> >         </fx:Script>
> >         <mx:Canvas id="canvas" x="20" y="20" width="500" height="400">
> >                 <s:TextInput id="campo" x="20" y="20"/>
> >         </mx:Canvas>
> > </s:WindowedApplication>
> >
> > On Aug 22, 12:15 pm, Mário Júnior <[email protected]> wrote:
> >
> >
> >
> >
> >
> >
> >
> > > startDrag()method
> > > public function
> > > startDrag(lockCenter:Boolean<
> http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/Bo...>
> > > =
> > > false, bounds:Rectangle<
> http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/fl...>
> > > =
> > > null):void<
> http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/sp...>
> > > Parameters
> > > lockCenter:Boolean<
> http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/Bo...>
> > > (default
> > > = false) — Specifies whether the draggable sprite is locked to the
> center of
> > > the pointer position (true), or locked to the point where the user
> first
> > > clicked the sprite (false).
> > > bounds:Rectangle<
> http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/fl...>
> > > (default
> > > = null) — Value relative to the coordinates of the Sprite's parent that
> > > specify a constraint rectangle for the Sprite.
> >
> > > Oq vc precisará fazer é usar o parametro *bounds:Rectangle*.
> >
> > >  var areaRestrita:Rectangle = new Rectangle(seuCanvas.x, seuCanva.y,
> > > seucanvas.w, seucanvas.h);
> > >  seuElemento.startDrag(false, areaRestrita);
> >
> > > Pronto! Só ler a documentação.
> >
> > > []'s
> >
> > > Em 22 de agosto de 2011 12:00, Principe borodin
> > > <[email protected]>escreveu:
> >
> > > > nao entendi bem o q vc kis dizer nao
> >
> > > >
> http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/fl...
> >
> > > > ate procurei na documentacao e nao achei nada no caso estou usando um
> > > > canvas pra limitar o espaço de "trabalho" do usuario...
> >
> > > > On Aug 21, 10:19 pm, Mário Júnior <[email protected]> wrote:
> > > > > No próprio método startDrag vc pode passar um Rectangle como
> argumento
> > > > para
> > > > > determinar a área de constraints.
> > > > > Consulte a documentação oficial desse método q vc achará até código
> de
> > > > > exemplo.
> >
> > > > > Lembrando q 'startDrag()' e 'stopDrag()' sao herdados do Flash.
> Outra
> > > > forma
> > > > > (e talvez até melhor, se pretende usar validações) é usar a classe
> > > > > DragManager do Flex SDK.
> >
> > > > > []'s
> >
> > > > > Em 21 de agosto de 2011 21:37, Principe borodin
> > > > > <[email protected]>escreveu:
> >
> > > > > > Eu to querendo criar uma aplicacao onde eu possa usar
> determinados
> > > > > > objetos dentro de um canvas...mas ele nao pode sair do canvas,
> pois ao
> > > > > > lado tera uma "paleta" de ferramentas....eu tentei algo bem
> simples
> > > > > > mas nao foi...
> >
> > > > > > <?xml version="1.0" encoding="utf-8"?>
> > > > > > <s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009";
> > > > > >                                           xmlns:s="library://
> > > > > > ns.adobe.com/flex/spark"
> > > > > >                                           xmlns:mx="library://
> > > > > > ns.adobe.com/flex/mx"
> > > > > >                                           width="1000"
> height="600"
> > > > > > creationComplete="init()">
> > > > > >        <fx:Script>
> > > > > >                <![CDATA[
> > > > > >                        import mx.events.DragEvent;
> > > > > >                        import mx.controls.Alert;
> > > > > >                        protected function
> > > > > > campo_dragStartHandler(event:DragEvent):void
> > > > > >                        {
> > > > > >                                // TODO Auto-generated method stub
> >
> > > > > >                        }
> > > > > >                        private function init():void
> > > > > >                        {
> >
> > > > > >  campo.addEventListener(MouseEvent.MOUSE_DOWN,sg);
> >
> > > > > >  campo.addEventListener(MouseEvent.MOUSE_UP,sgu);
> > > > > >                        }
> > > > > >                        private function sg(event:MouseEvent):void
> > > > > >                        {
> > > > > >
>  //Alert.show(event.currentTarget.y);
> > > > > >                                var tam:int =
> event.currentTarget.width
> > > > +
> > > > > > event.currentTarget.x;
> >
> > > > > >                        if(campo.hitTestObject(canvas))
> > > > > >                        {
> > > > > >                                event.currentTarget.startDrag();
> > > > > >                        }
> > > > > >                        }
> > > > > >                        private function
> sgu(event:MouseEvent):void
> > > > > >                        {
> >
> > > > > >  //Alert.show(event.currentTarget.width+event.currentTarget.x);
> > > > > >                        event.currentTarget.stopDrag();
> > > > > >                        }
> >
> > > > > >                ]]>
> > > > > >        </fx:Script>
> > > > > >        <fx:Declarations>
> > > > > >                <!-- Place non-visual elements (e.g., services,
> value
> > > > > > objects) here
> > > > > > -->
> > > > > >        </fx:Declarations>
> > > > > > <mx:Canvas x="20" y="20"  id="canvas" borderVisible="true"
> > > > > > borderColor="0x000000" width="700" height="500" >
> > > > > >        <s:TextInput  id="campo"/>
> > > > > > </mx:Canvas>
> > > > > > </s:WindowedApplication>
> >
> > > > > > --
> > > > > > Você recebeu esta mensagem porque está inscrito na lista
> "flexdev"
> > > > > > Para enviar uma mensagem, envie um e-mail para
> > > > [email protected]
> > > > > > Para sair da lista, envie um email em branco para
> > > > > > [email protected]
> > > > > > Mais opções estão disponíveis emhttp://
> groups.google.com/group/flexdev
> >
> > > > > --
> > > > > Mario Juniorhttp://blog.mariojunior.com/
> > > > > @mariojunior
> >
> > > > --
> > > > Você recebeu esta mensagem porque está inscrito na lista "flexdev"
> > > > Para enviar uma mensagem, envie um e-mail para
> [email protected]
> > > > Para sair da lista, envie um email em branco para
> > > > [email protected]
> > > > Mais opções estão disponíveis emhttp://
> groups.google.com/group/flexdev
> >
> > > --
> > > Mario Juniorhttp://blog.mariojunior.com/
> > > @mariojunior
>
> --
> Você recebeu esta mensagem porque está inscrito na lista "flexdev"
> Para enviar uma mensagem, envie um e-mail para [email protected]
> Para sair da lista, envie um email em branco para
> [email protected]
> Mais opções estão disponíveis em http://groups.google.com/group/flexdev
>



-- 
Mario Junior
http://blog.mariojunior.com/
@mariojunior

-- 
Você recebeu esta mensagem porque está inscrito na lista "flexdev"
Para enviar uma mensagem, envie um e-mail para [email protected]
Para sair da lista, envie um email em branco para 
[email protected]
Mais opções estão disponíveis em http://groups.google.com/group/flexdev

Responder a