2 Replies Latest reply on Jun 18, 2010 2:52 PM by Warentester

    Button enabled="false" & moving Objects.

    Warentester

      Hello everyone,

       

      I want a button, which is ,

      enabled="false"

      to only change to

      enabled="true"

      if i move an object to a special location on the screen.

       

      For simplicity in the example I sayed the special location should be the location of the button.

      When i move my object (an unlabeled button) to the button "Test1" then the button should be enabled="true".

       

      However, in my broken programming code, whenever i move the unlabeld button, the "Test1" Button becomes enabled="true".

      I have no idea why ?

       

      It would be great if anyone could help me

       

      Thanks

       

      Markus

       

      Here is the Code.

       

      <?xml version="1.0" encoding="utf-8"?>
      <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
                     xmlns:s="library://ns.adobe.com/flex/spark"
                     xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" creationComplete="application1_creationCompleteHandler(event)">
          <fx:Declarations>
              <!-- Platzieren Sie nichtvisuelle Elemente (z. B. Dienste, Wertobjekte) hier -->
          </fx:Declarations>
         
          <fx:Script>
              <![CDATA[
                 
                  import mx.events.FlexEvent;
                 
                  protected function application1_creationCompleteHandler(event:FlexEvent):void
                  {
                      area1.addEventListener(KeyboardEvent.KEY_DOWN, moveTextArea);
                     
                      var timer:Timer = new Timer(50);
                      timer.delay=100;
                      timer.repeatCount=0;
                      timer.addEventListener(TimerEvent.TIMER, timeListener);
                     
                     
                     
                     
                     
                      timer.start();
                     
                  }
                 
                  public function timeListener(e:TimerEvent):void
                  {
                     
                  }
                 
                  public function dummy()
                  {
                      if((area1.x == test1.x) && (area1.y == test1.y))
                          {
                              test1.enabled="true";   
                          }
                          else
                          {
                              test1.enabled="false";
                          }
                  }
                 
                  public function moveTextArea(e:KeyboardEvent):void
                  {
                      if(e.keyCode == Keyboard.RIGHT)
                      {
                          area1.x += 20;
                      }
                     
                      if(e.keyCode == Keyboard.LEFT)
                      {
                          area1.x -= 20;
                      }
                     
                      if(e.keyCode == Keyboard.UP)
                      {
                          area1.y -= 20;
                      }
                     
                      if(e.keyCode == Keyboard.DOWN)
                      {
                          area1.y += 20;
                      }
                     
                     
                      dummy();
                     
                  }
                 
              ]]>
          </fx:Script>
         
          <s:Button x="20" y="20" label="Test1" id="test1" enabled="false"/>
         
          <s:Button x="60" y="60" id="area1" />
         
      </s:Application>