[flexcoders] Re: Reference to mxml id from within mxml component
Hi Sean: Yep. Three-up - three-down. You nailed them all. Thanks! Ted. --- In flexcoders@yahoogroups.com, "Sean Clark Hess" <[EMAIL PROTECTED]> wrote: > > Hi Ted. > > 1. Oh, right... the mouse events bubble, so they are fired not only for your > components, but for whatever you actually clicked on underneath it. It > looks like I used event.currentTarget instead of event.target. Can you > trace (event.target) and see if it is actually the component you wanted? > > 2. Try fixing 1 and seeing if that fixes > > 3. You needed to import flash.display.Spirte; Google "flex 3 language > reference". you can find everything there. The only reason I used sprite > was because that was the class that defines startDrag. Normally, if all the > components were the same (all of type ComponentA), I would do > event.currentTarget as ComponentA, since that's more specific. Since all > flex components are UIComponents, which are sprites, they all have the > startDrag event. you would have to import your ComponentA though. You > could have done event.currentTarget as UIComponent just as easily (import > mx.core.UIComponent). > > > > On Wed, Jul 2, 2008 at 2:36 PM, edlueze <[EMAIL PROTECTED]> wrote: > > > 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 flexcoders@yahoogroups.com , "Sean > > Clark Hess" 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 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? > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > id="ComponentAId" > > > > mouseDown="onMouseDown(event,'ComponentAId')" > > > > mouseUp="onMouseUp(event,'ComponentAId')"/> > > > > > > > > > > > > > > > id="ComponentBId" > > > > mouseDown="onMouseDown(event,ComponentBId.id)" > > > > mouseUp="onMouseUp(event,ComponentBId.id)"/> > > > > > > > > > > > > > > > id="ComponentCId" > > > > mouseDown="onMouseDown(event,id)" > > > > mouseUp="onMouseUp(event,id)"/> > > > > > > > > > > > > > > > id="ComponentDId" > > > > mouseDown="onMouseDown(event,this)" > > > > mouseUp="onMouseUp(event,this)"/> > > > > > > > > > > > > > > > > > > > > > >
Re: [flexcoders] Re: Reference to mxml id from within mxml component
Hi Ted. 1. Oh, right... the mouse events bubble, so they are fired not only for your components, but for whatever you actually clicked on underneath it. It looks like I used event.currentTarget instead of event.target. Can you trace (event.target) and see if it is actually the component you wanted? 2. Try fixing 1 and seeing if that fixes 3. You needed to import flash.display.Spirte; Google "flex 3 language reference". you can find everything there. The only reason I used sprite was because that was the class that defines startDrag. Normally, if all the components were the same (all of type ComponentA), I would do event.currentTarget as ComponentA, since that's more specific. Since all flex components are UIComponents, which are sprites, they all have the startDrag event. you would have to import your ComponentA though. You could have done event.currentTarget as UIComponent just as easily (import mx.core.UIComponent). On Wed, Jul 2, 2008 at 2:36 PM, edlueze <[EMAIL PROTECTED]> wrote: > 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 flexcoders@yahoogroups.com , "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? > > > > > > > > > > > > > > > > > > > > > > > id="ComponentAId" > > > mouseDown="onMouseDown(event,'ComponentAId')" > > > mouseUp="onMouseUp(event,'ComponentAId')"/> > > > > > > > > > > > id="ComponentBId" > > > mouseDown="onMouseDown(event,ComponentBId.id)" > > > mouseUp="onMouseUp(event,ComponentBId.id)"/> > > > > > > > > > > > id="ComponentCId" > > > mouseDown="onMouseDown(event,id)" > > > mouseUp="onMouseUp(event,id)"/> > > > > > > > > > > > id="ComponentDId" > > > mouseDown="onMouseDown(event,this)" > > > mouseUp="onMouseUp(event,this)"/> > > > > > > > > > > > > > >
[flexcoders] Re: Reference to mxml id from within mxml component
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 flexcoders@yahoogroups.com, "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? > > > > > > > > > > > > > > > id="ComponentAId" > > mouseDown="onMouseDown(event,'ComponentAId')" > > mouseUp="onMouseUp(event,'ComponentAId')"/> > > > > > > > id="ComponentBId" > > mouseDown="onMouseDown(event,ComponentBId.id)" > > mouseUp="onMouseUp(event,ComponentBId.id)"/> > > > > > > > id="ComponentCId" > > mouseDown="onMouseDown(event,id)" > > mouseUp="onMouseUp(event,id)"/> > > > > > > > id="ComponentDId" > > mouseDown="onMouseDown(event,this)" > > mouseUp="onMouseUp(event,this)"/> > > > > > > >