3 Replies Latest reply on Jul 9, 2007 11:05 AM by csawall

    Passing var to popup - property not defined - even though it is.

    csawall Level 1
      I am having a problem passing a variable to a popup. I do this several other times with different popups in the same app and I can't figure out what I'm doing wrong this time. It's telling me a property is undefined, but as far as I can tell, I'm doing it correctly.

      The error:

      1120: Access of undefined property hscreen. helpinfo.mxml

      The code from the main app that calls the popup:

      main.as
      --------------------------
      import components.helpinfo;
      private function showHelp():void {
      var helpinfopop:helpinfo = helpinfo(PopUpManager.createPopUp(this, helpinfo, false));
      helpinfopop.title="Help";
      helpinfopop.showCloseButton=true;
      helpinfopop.hscreen = "main";
      PopUpManager.centerPopUp(helpinfopop);
      }


      The popup window, which for now, I'm just trying to get the variable passed. I have tried various ways, so for now, I'm just trying to do an alert window. The error is only showing in the alert.show below.

      helpinfo.mxml
      --------------------------
      <?xml version="1.0" encoding="utf-8"?>
      <mx:TitleWindow xmlns:mx=" http://www.adobe.com/2006/mxml" close="closeDialog()" layout="absolute" width="200" height="150" backgroundAlpha="0.5" alpha="0.5" cornerRadius="10" roundedBottomCorners="true" dropShadowEnabled="true">
      <mx:Script>
      <![CDATA[
      import mx.controls.Alert;
      import mx.managers.PopUpManager;

      [Bindable] public var hscreen:String;

      private function closeDialog():void {
      PopUpManager.removePopUp(this);
      }
      Alert.show(hscreen);
      ]]>
      </mx:Script>
      </mx:TitleWindow>


      For the alert, I have also tried hscreen.valueOf() without any luck. Even if I do simple if statements to see if "hscreen" equals some value, it fails.

      Any thoughts or ideas? Any suggestions would be greatly appreciated.

      Thanks,
      Chris
        • 1. Re: Passing var to popup - property not defined - even though it is.
          rotoole Level 1
          the problem might be that you are calling the the createPopUp and then the popUp is Alerting technically on init so the hscreen isn't getting set fast enough.
          try this:

          var helpinfopop:helpinfo;
          helpinfopop.hscreen = "main";
          //then create your popup
          helpinfopop = helpinfo(PopUpManager.createPopUp(this, helpinfo, false));

          or try setting hscreen to something initially on your component instead of not instantiating it at all.

          [Bindable] public var hscreen:String = "";
          or
          [Bindable] public var hscreen:String = new String();



          • 2. Re: Passing var to popup - property not defined - even though it is.
            Mitek17 Level 1
            Hi Chris,

            As far as I can see the following code does not belong to any function:
            Alert.show(hscreen);

            you should wrap it into the function and call it on some event like "creationComplete".

            Like this:

            <mx:TitleWindow
            creationComplete="fInit()">

            <mx:Script>
            <![CDATA[
            import mx.controls.Alert;
            import mx.managers.PopUpManager;

            [Bindable] public var hscreen:String;

            private function closeDialog():void {
            PopUpManager.removePopUp(this);
            }

            private function fInit()
            {
            Alert.show(hscreen);
            }

            ]]>
            </mx:Script>
            </mx:TitleWindow>



            Cheers,
            Dmitri.
            • 3. Re: Passing var to popup - property not defined - even though it is.
              csawall Level 1
              Mitek17 - Thanks. That was the problem. I wasn't even thinking about a function, I was just trying to verify the syntax was correct and get a variable passed. Thanks for taking the time to help.

              Chris