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