10 Replies Latest reply on Sep 30, 2008 3:28 PM by Newsgroup_User

    Targetting a button in a component

    SiHoop Level 1
      I'm familiar with outerDocument as a way to get out of the scope of a Component, but how do I target a button that is embedded in a Component. For example, in the following function how do I change the label of the button?

      public function onButtonClick(event:Event, data):void{
      //simon.label="Selected"
      }
        • 1. Re: Targetting a button in a component
          Level 7

          "SiHoop" <webforumsuser@macromedia.com> wrote in message
          news:gbs3rn$8b7$1@forums.macromedia.com...
          > I'm familiar with outerDocument as a way to get out of the scope of a
          > Component, but how do I target a button that is embedded in a Component.
          > For
          > example, in the following function how do I change the label of the
          > button?
          >
          > public function onButtonClick(event:Event, data):void{
          > //simon.label="Selected"
          > }
          >
          > <mx:DataGridColumn width="170" dataField="name">
          > <mx:itemRenderer>
          > <mx:Component>
          > <mx:VBox>
          > <mx:Button id="simon" label="Push Me" click="outerDocument.onButtonClick(
          > event, data )"/>
          > </mx:VBox>
          > </mx:Component>
          > </mx:itemRenderer>
          > </mx:DataGridColumn>

          Please see the FAQ for why this is bad practice. There's not much of a way
          around this in a DataGrid unless you're willing to dig into the code and see
          what's going on in the background. By the time you do that, you're better
          off just learning how to do it in a better way.

          HTH;

          Amy


          • 2. Targetting a button in a component
            theLoggerGuy Level 1
            I agree, but try this (haven't tested it):
            public function onButtonClick( event: Event, data: Object ): void
            {
            event.target.label = "Selected";
            }
            • 3. Re: Targetting a button in a component
              flex2008 Level 3
              U can use an script tag in the component and write the handler method for button click there.So u can refer the button with its label....
              • 4. Re: Targetting a button in a component
                SiHoop Level 1
                Amy,
                Before I go too far down the wrong path-- is it the article titled "Graduating from hack to architected development" that you think would be most useful?

                Many thanks for your help again!
                • 5. Re: Targetting a button in a component
                  SiHoop Level 1
                  Amy,
                  Before I go too far down the wrong path-- is it the article titled "Graduating from hack to architected development" that you think would be most useful?

                  Many thanks for your help again!
                  • 6. Re: Targetting a button in a component
                    Level 7

                    "SiHoop" <webforumsuser@macromedia.com> wrote in message
                    news:gbtc85$sp6$1@forums.macromedia.com...
                    > Amy,
                    > Before I go too far down the wrong path-- is it the article titled
                    > "Graduating from hack to architected development" that you think would be
                    > most useful?

                    That's one of them ;-)


                    • 7. Re: Targetting a button in a component
                      SiHoop Level 1
                      I'm excited because I've finally figured out how to create a component that will give me a minimal level of interactivity (I can finally change the style of a button when it is selected), but now I suspect that I've painted myself into a corner by using parentDocument. I also have a reset button that sets several items to their original state, but when I select reset I must also set the buttons in the datagrid back their original style. I'm not sure that I can program the buttons as they appear to be 'unreachable' from outside the component. I read the document that Amy recommended on 'good programming techniques', and some of it works for me now, but other concepts are too advanced for me at the moment. Is there any way to reset all of the buttons in the datagrid back to their original style?
                      • 8. Re: Targetting a button in a component
                        ntsiii Level 3
                        Depending on what you really want, you could probably bind that label:
                        [Bindable]private var _btnLabel:String = "Push Me";
                        ...
                        <mx:Button id="simon" label="{outerDocument._btnLabel}" />

                        Or make the Button a toggle, or subclass Button, or .....

                        Tracy
                        • 9. Re: Targetting a button in a component
                          SiHoop Level 1
                          Do you mean something like the following:
                          Set the values of _styleName1 and _styleName in the component to be bindable (as in the code below) and then change the values of _styleName1 or _styleName in the main file when the buttons are to be refreshed? Please note also, that I'm changing the value of the style, not the label on the button.

                          If so, I assume I would have to declare the variables in the main file first-- is this correct? Am I following your line of thinking correctly?
                          Thanks again!
                          • 10. Re: Targetting a button in a component
                            Level 7

                            "SiHoop" <webforumsuser@macromedia.com> wrote in message
                            news:gbu297$t48$1@forums.macromedia.com...
                            > I'm excited because I've finally figured out how to create a component
                            > that
                            > will give me a minimal level of interactivity (I can finally change the
                            > style
                            > of a button when it is selected), but now I suspect that I've painted
                            > myself
                            > into a corner by using parentDocument. I also have a reset button that
                            > sets
                            > several items to their original state, but when I select reset I must also
                            > set
                            > the buttons in the datagrid back their original style. I'm not sure that I
                            > can
                            > program the buttons as they appear to be 'unreachable' from outside the
                            > component. I read the document that Amy recommended on 'good programming
                            > techniques', and some of it works for me now, but other concepts are too
                            > advanced for me at the moment. Is there any way to reset all of the
                            > buttons in
                            > the datagrid back to their original style?
                            >
                            > <?xml version="1.0" encoding="utf-8"?>
                            > <mx:Canvas xmlns:mx=" http://www.adobe.com/2006/mxml" >
                            > <mx:Script>
                            > <![CDATA[
                            > private var someVar:Boolean=true
                            > public function changeButtonStyle():void{
                            > parentDocument.hideMapMarker()
                            > if(someVar){
                            > button1.styleName='linkButton1'
                            > }else{
                            > button1.styleName='linkButton'
                            > }
                            > someVar= !someVar
                            > }
                            > ]]>
                            > </mx:Script>
                            > <mx:Button id="button1" click= "changeButtonStyle() " width="65"
                            > styleName="linkButton" />
                            > </mx:Canvas>

                            I'm on the way out the door so I can't get too much into detail, but I'd
                            associate the button styles with _listData as is done here:
                            http://blog.flexmonkeypatches.com/2007/09/10/flex-tilelist-with-togglebuttons/

                            Or, if you're using a TileList or DataGrid (and you can also make a TileList
                            work like List or HorizontalList), you can use the extended TileList and
                            DataGrid from my blog (http:flexdiary.blogspot.com).

                            HTH;

                            Amy