2 Replies Latest reply on Feb 5, 2007 10:04 AM by shotbyshawn

    Hello World: Components and States talking to each other through button events

    shotbyshawn
      Hi, I've tried various ways of asking this, gone through the documentation as much as I can, but am still left with what would be a simple problem to fix in Flash (with LoadMovie and empty clips):

      How do I get a button in one Canvas component on the screen to affect something in another Canvas component? For example, Canvas 1 is called rightside, has a button. I want clicking that button to affect Canvas 2, which is called leftside, and has a textbox inside it. Clicking on the button housed in rightside should allow leftside's text box to display 'hello world'.

      More importantly, say the canvas with the textbox has 2 states, how can I get a button in rightside (the other canvas) to cause leftside canvas to change from one state named 'state one' and go to a 'state two'? In other words, how does a button housed in one canvas (in a component) cause a component loaded into another canvas get that component to go from one of it's states to another of its states?

      Thanks for any help.

        • 1. Re: Hello World: Components and States talking to each other through button events
          djwglpuppy Level 1
          I might be oversimplyfying this. All you have to do is explicitely set IDs of the components you want to effect. And then use Bindable information to communicate with eachother (curleybraces): Here is your helloworld example to insert in your MXML file:

          <?xml version="1.0" encoding="utf-8"?>
          <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute" backgroundGradientColors="[#CCCCCC, #FFFFFF]">
          <mx:Canvas x="10" y="10" width="200" height="200">
          <mx:Button x="10" y="10" label="Button" click="{textboxeffect.text = 'Hello World';}"/>
          </mx:Canvas>
          <mx:Canvas x="218" y="10" width="200" height="200">
          <mx:Text x="10" y="10" id="textboxeffect"/>
          </mx:Canvas>


          </mx:Application>

          Hope that helps.
          • 2. Re: Hello World: Components and States talking to each other through button events
            shotbyshawn Level 1
            Yeah that definitely helps. OK, so I figured it was currentState then for the method in the button (i.e., the usual thing for changing the state). But it doesn't seem to work, and throws me an error. For example, if in one component is the button, and in the other component you have 2 states, and you want to tell the button to go to 'statetwo', using currentstate='statetwo' in the button doesn't work (I do have everything IDed).

            In Flash, you'd use something like "_root.statetwo" to get around this sort of thing, because you go from your button, down to the Application level, and then back up to another component, if that makes sense.

            I have all the documentation for Flex being printed this week, indexed and bound. I hope it helps LOL.

            Shawn