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)"/>