Thanks Sean!

I've only just started playing with your suggestion - it seems to work
fine but there are some things I'm going to need to dig into before I
fully understand what's going on:

1. Not only do my components drag around fine, but the components
*within* those components now also drag around. Interesting, but not
what I expected. I'm going to have to figure out how to lock those
internal parts of the component.

2. There is some text that I'm displaying within the components. It
appears that this text is not allowed to be dragged, and when I click
on the text to drag it an error is thrown.

3. I now need to add an additional line of code "import
flash.display.*". I didn't need that before - presumably I need it now
to cast the component into a Sprite. Not sure which part of
flash.display.* I actually need.

All the best!

Ted.

--- In [email protected], "Sean Clark Hess" <[EMAIL PROTECTED]> wrote:
>
> Yes, use event.target.
> 
> private function onMouseDown(event:MouseEvent):void
> {
>     (event.target as Spirte).startDrag();
> }
> 
> The reason why your last two things don't work is because, unlike
> javascript, "this" and "id" would refer to the parent component
(e.g. the
> file you are currently editing).  So, if you want to pass "id" you
have to
> pass "ComponentCId.id" (like you did in #2).  Or, if you want to
pass "this"
> you have to pass "ComponentDId"
> 
> This way is very consistent... this always just refers to the file your
> working in.  It's always easy to drill down anyway.
> 
> 
> 
> On Wed, Jul 2, 2008 at 1:18 PM, edlueze <[EMAIL PROTECTED]> wrote:
> 
> >   I am trying to refer to the id field for an mxml component from
within
> > that component so I can pass it back to some actionscript.
> >
> > Consider this example: I want to be able to drag components around a
> > panel by calling mouseDown/mouseUp from within the mxml component
> > definition. The first two components work (ComponentA and ComponentB)
> > but the second two components don't work (ComponentC and ComponentD).
> >
> > Being able to reference the component id from within the mxml
> > component provides a little more scalability. Perhaps there is a
> > better way altogether?
> >
> > <mx:Script>
> > <![CDATA[
> >
> > private function onMouseDown(event:MouseEvent, myid:String ):void
> > {
> > this[myid].startDrag();
> > }
> >
> > private function onMouseUp(event:MouseEvent, myid:String ):void
> > {
> > this[myid].stopDrag();
> > }
> > ]]>
> > </mx:Script>
> >
> > <!-- This works -->
> > <component:ComponentA
> > id="ComponentAId"
> > mouseDown="onMouseDown(event,'ComponentAId')"
> > mouseUp="onMouseUp(event,'ComponentAId')"/>
> >
> > <!-- And this works -->
> > <component:ComponentB
> > id="ComponentBId"
> > mouseDown="onMouseDown(event,ComponentBId.id)"
> > mouseUp="onMouseUp(event,ComponentBId.id)"/>
> >
> > <!-- But this doesn't work -->
> > <component:ComponentC
> > id="ComponentCId"
> > mouseDown="onMouseDown(event,id)"
> > mouseUp="onMouseUp(event,id)"/>
> >
> > <!-- And this doesn't work -->
> > <component:ComponentD
> > id="ComponentDId"
> > mouseDown="onMouseDown(event,this)"
> > mouseUp="onMouseUp(event,this)"/>
> >
> >  
> >
>


Reply via email to