1 Reply Latest reply on Oct 5, 2011 4:53 AM by alvaroqp85

    Problem with SkinnablePopUpContainer

    alvaroqp85

      My problem is my textoUsuario variable from main view => 'onTextSet' isn't visible to my aplication...

      I'm not sure what I have to do, can you help? I need this variable in main view...

       

      view main:

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

      <s:View xmlns:fx="http://ns.adobe.com/mxml/2009"

              xmlns:s="library://ns.adobe.com/flex/spark"

              title="Introducir Texto por el usuario"

              viewActivate="view1_viewActivateHandler(event)">

       

          <fx:Script>

              <![CDATA[

                  import components.MyPopupComponent;

                  import components.TextPickerEvent;

                  import spark.components.SkinnablePopUpContainer;

                  import spark.events.ViewNavigatorEvent;

       

                  protected var popup:MyPopupComponent;

                  protected var textoUsuario:String;

       

                  protected function view1_viewActivateHandler(event:ViewNavigatorEvent):void

                  {

                      popup = new MyPopupComponent();

                  }

       

                  public function getText():void{

                      var textVar: MyPopupComponent = new MyPopupComponent();

                      textVar.addEventListener(TextPickerEvent.TEXT_PICKER_SET, onTextSet);

                      textVar.addEventListener(TextPickerEvent.TEXT_PICKER_CANCEL, onTextCancel);

                      popup.open(this);

                  }

       

                  private function onTextSet(event:TextPickerEvent): void

                  {   // NO ENTRA!!!

                      textoUsuario = event.textValue;

                      trace ("VISTA GENERAL. Valor: " + textoUsuario);

                      onTextCancel(event);

                  }

       

                  private function onTextCancel(event:TextPickerEvent): void

                  {

                      var comboItemVar:MyPopupComponent = event.target as MyPopupComponent;

                      comboItemVar.removeEventListener(TextPickerEvent.TEXT_PICKER_SET, onTextSet);

                      comboItemVar.removeEventListener(TextPickerEvent.TEXT_PICKER_CANCEL, onTextCancel);

                  }

              ]]>

          </fx:Script>

       

          <s:layout>

              <s:VerticalLayout paddingTop="5" paddingBottom="5" paddingLeft="5" paddingRight="5" gap="10"

                                horizontalAlign="center" verticalAlign="top"/>

          </s:layout>

       

          <s:TextArea width="98%" text="Skinnable pop-up."/>

       

          <s:HGroup>

              <s:Button label="Open Popup" click="getText()"/>

          </s:HGroup>

      </s:View>

       

      MyPopUpComponent.mxml

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

      <s:SkinnablePopUpContainer xmlns:fx="http://ns.adobe.com/mxml/2009"

                                 xmlns:s="library://ns.adobe.com/flex/spark"

                                 height="94">

       

          <fx:Script>

              <![CDATA[

                  public var textUser:String;

       

                  private function setText():void {

                      var dpe1:TextPickerEvent = new TextPickerEvent(TextPickerEvent.TEXT_PICKER_SET);

                      dpe1.textValue = userTextId.text;

                      dispatchEvent(dpe1);

       

                      textUser = userTextId.text;

                      this.close();

                      trace("Valor introducido: " + textUser);

                  }

       

                  private function cancelText():void {

                      this.close();

                  }

              ]]>

          </fx:Script>

                  <s:Label width="100%" height="57" fontSize="20" text="Introduce tu valor:"/>

                  <s:TextInput id="userTextId" width="100%" enabled="true"/>

                  <s:HGroup x="0" y="42" width="100%" height="47">

                      <s:Button width="100%" label="Set" click="setText()" fontSize="20"/>

                      <s:Button width="100%" label="Cancel" click="cancelText()" fontSize="20"/>

                  </s:HGroup>

      </s:SkinnablePopUpContainer>

       

       

      TextPickerEvent.as

      package components

      {

          import flash.events.Event;

         

          public class TextPickerEvent extends Event

          {

              public static const TEXT_PICKER_SET: String = 'textPickerSet';

              public static const TEXT_PICKER_CANCEL: String = 'textPickerCancel';

             

              public var textValue: String;

             

              public function TextPickerEvent(type:String, bubbles:Boolean=false, cancelable:Boolean=false)

              {

                  super(type, bubbles, cancelable);

              }

          }

      }

       

      thanks

      Alvaro