11 Replies Latest reply on May 21, 2009 6:33 AM by Paul Reilly

    [Urgent]  Data binding in mxml

    gienie87

      <mx:states>

       

       

       

           <mx:State name="BetPlacedState">

       

       

                <mx:SetEventHandler target="{table.btn.dealbtn}" name="click" handler="handleDealClicked(event)"/>  

           </mx:State>

      </mx:states>

       

      <local:ui

       

      id="table" width="770" height="600"/>

       

      error : 1118: Implicit coercion of a value with static type Object to a possibly unrelated type flash.events:MouseEvent.

       

       

      How to solve the problem? IS there anyway to bind the object without creating a bindable reference of the object in actionscript?

      'table' is a custom component from an external swc library. It has an mc named btn which holds several buttons and one of them is dealbtn.

       

      Thanks.

        • 1. Re: [Urgent]  Data binding in mxml
          gienie87 Level 1

          I changed the seteventhandler to

           

                    <mx:SetEventHandler target="{table.btn.dealbtn}" name="click" handler="handleDealClicked()"/> 

           

          and the error i get now is: Data binding will not be able to detect assignments to "btn".

          How do i detect the components in 'table'?

          • 2. Re: [Urgent]  Data binding in mxml
            Gregory Lafrance Level 6

            Where are your controls instantiated? If in MXML binding should already be available. If in ActionScript, use the [Bindable] metadata tag.

             

            If this post answers your question of helps, please mark it as such.

            • 3. Re: [Urgent]  Data binding in mxml
              Paul Reilly Level 1

              In addition to using Bindable metadata on the "btn" variable/property, you want to make sure that "table" is strongly typed.

              • 4. Re: [Urgent]  Data binding in mxml
                gienie87 Level 1

                Everything is instantiated in MXML, which is why I coudn't use the [Bindable] metadata. If I only pass in 'table' in the seteventhandler target, there is no error.

                 

                Please help. Thanks.

                • 5. Re: [Urgent]  Data binding in mxml
                  gienie87 Level 1

                  WHat do you mean by strongly typed? 'table' is a custom component from an external swc file. 'table' is instantiated in MXML so there is no way i can bind it in actionscript, isn't it?

                  • 6. Re: [Urgent]  Data binding in mxml
                    Michael Borbor Level 4

                    You can use <mx:Binding /> to bind using MXML. Coud you post your whole code I think you're making a few mistakes.

                    • 7. Re: [Urgent]  Data binding in mxml
                      gienie87 Level 1

                       

                       

                       

                       

                       

                       

                       

                       

                       

                       

                       

                       

                       

                       

                       

                       

                       

                      <?xml version="1.0" encoding="utf-8"?>

                      <mx:Canvas

                       

                      xmlns:mx=http://www.adobe.com/2006/mxml

                                          xmlns:local="

                      *" width="100%"

                                          xmlns:comp="

                      src.com.git.view.components.*"

                                          xmlns:sub="

                      src.com.git.view.components.subComponents.*"

                                          height="100%" creationComplete="Init()">

                       

                       

                       

                       

                       

                       

                       

                       

                       

                       

                       

                       

                      <mx:states>
                        <mx:State name="BetPlacedState">
                       
                         <mx:SetEventHandler id = "dealhandler" target="{table.btn.dealbtn}"
                              name="click"
                              handler="handleDealClicked()"/>
                             
                         <mx:SetEventHandler id = "clearhandler" target="{table.btn.clearbetbtn}"
                              name="click"
                              handler="handleClearBetClicked()"/>
                        </mx:State>
                        <mx:State name="StartGameState">
                       
                         <mx:SetEventHandler id = "hithandler" target="{table.btn.hitbtn}"
                              name="click"
                              handler="handleHitClicked()"/>
                             
                         <mx:SetEventHandler id = "standhandler" target="{table.btn.standbtn}"
                              name="click"
                              handler="handleStandClicked()"/>
                             
                         <mx:SetEventHandler id = "insurancehandler" target="{table.btn.insurancebtn}"
                              name="click"
                              handler="handleInsuranceClicked()"/>
                        </mx:State> 
                         </mx:states>

                       

                       

                      <mx:Script source="GameViewSource.as" />

                       

                       

                       

                       

                      <local:ui id="table" width="770" height="600"/>

                       

                       

                      <comp:InGameMenu id="menu" y="600"/>

                       

                       

                      <sub:Dealer id="dealer" x = "330" y = "50" >

                       

                       

                       

                      </mx:Canvas>

                      • 8. Re: [Urgent]  Data binding in mxml
                        Michael Borbor Level 4

                        Remove all the () in your handlers. Probably you're doing your app too complex unnecessarily. It seems to me that you're trying to add event listeners to the children of your child component, I'll add those listeners in your component ui, not in your main app.

                        • 9. Re: [Urgent]  Data binding in mxml
                          gienie87 Level 1

                          I removed all () and the error is the same.

                           

                          Data binding will not be able to detect assignments to "btn".

                           

                          This is my component ui. Not the main app.

                          You mean you will add those listeners inside the 'table' component? How?

                           

                          For each view states, only certain type of buttons are visible, and I only want those visible buttons to be able to handle click events.

                          • 10. Re: [Urgent]  Data binding in mxml
                            Michael Borbor Level 4

                            What you're getting is a warning not an error. Yes I meant that you add those listeners in the 'table' component.

                            • 11. Re: [Urgent]  Data binding in mxml
                              Paul Reilly Level 1

                              By strongly typed, I mean something like:

                               

                                var table:Table;

                               

                              as opposed to:

                               

                                var table:Object;

                               

                              Since your custom component is from an external SWC, the custom component author would need to put Bindable metadata on the btn variable/property.  Otherwise, changes won't be detected and this is what the compiler warning is trying to tell you.