Select to view content in your preferred language

Flex Mobile Help - navigator.pushView from PopUp

3659
10
04-02-2014 03:52 PM
KomanDiabate
Deactivated User
Hi All,
I am working on a flex mobile app with popup box. Insisde the popup I have button and I am trying to click the button and push/open a specific view. I am using this code it runs without errors but as I click the button I get the infamous error 1009
TypeError: Error #1009: Cannot access a property or method of a null object reference.

protected function button1_clickHandler(event:MouseEvent):void
   {   
    (owner as spark.components.View).navigator.pushView(PersonalForm);

   }


Does anybody knows how to push a view from titleWindow popup window?

Thanks All
Tags (2)
0 Kudos
10 Replies
AaronNash1
Frequent Contributor
try this.navigator.pushView(PersonalForm);
0 Kudos
KomanDiabate
Deactivated User
Hi Aaron,
that didn't work, I got an error 1119: Access of possible undefined property of navigator through a reference with static ........
The challenge is that the popup doesn't have direct access the the navigator.
below is the only way I was able to access the navigator but it's giving me error 1009 runtime error.
(owner as spark.components.View).navigator.pushView(PersonalForm);
0 Kudos
AaronNash1
Frequent Contributor
Add an eventlistener into your main application that listens for the close event on the titlewindow, that way you can add your button1_clickHandler code into the main application and push the view from there.
0 Kudos
KomanDiabate
Deactivated User
Ok, I will try that.
Basically close the popup and pushView. That maybe the ticket. Will keep you posted.
Thanks.
0 Kudos
AaronNash1
Frequent Contributor
this works in the main application


public var win : Window = new Window()

private function launchPopUp():void
{
      PopUpManager.addPopUp(win,this,true);
      PopUpManager.centerPopUp(win);
      win.addEventListener(CloseEvent.CLOSE, pushviewTest);
}
  
private function pushviewTest(event:CloseEvent):void
{
       navigator.pushView(test);
       win.removeEventListener(CloseEvent.CLOSE, pushviewTest);   
}

this is for the titlewindow

<s:TitleWindow xmlns:fx="http://ns.adobe.com/mxml/2009"
      xmlns:s="library://ns.adobe.com/flex/spark"
      xmlns:mx="library://ns.adobe.com/flex/mx"
      width="340" close="closeWindow()"
      height="130">

<fx:Script>
  <![CDATA[
  
   import mx.core.IFlexDisplayObject;
   import mx.managers.PopUpManager;
  
   private function closeWindow():void
   {
    PopUpManager.removePopUp(this as IFlexDisplayObject);
   }
  ]]>
</fx:Script>
<s:Button label="Close" click="dispatchEvent(new CloseEvent(CloseEvent.CLOSE))"/>
</s:TitleWindow>
0 Kudos
KomanDiabate
Deactivated User
Thanks Aaron, your help is greatly appreciated.
Your code sample help quite a bit and it works. But now I have another small complication:
The CloseEvent and the listener on the main view works wonderfully, however there maybe case when users just want to view the data on the popup without pushing the detailView (PersonalForm), meaning just x-ing out. I am looking into this but just wanted to let you know that with your help, I am on the right track here. if you think of a suggestions for me to differentiate these two tasks: closing  the popup versus closing and pushing the view, please let me know.
Thanks a million, I am getting closer.


[ATTACH=CONFIG]32783[/ATTACH]
0 Kudos
AaronNash1
Frequent Contributor
create a second button and instead of dispatching a close event just call the function directly

<s:Button label="Change View" click="dispatchEvent(new CloseEvent(CloseEvent.CLOSE))"/>
<s:Button label="Close Window" click="closeWindow()"/>
0 Kudos
KomanDiabate
Deactivated User
OK, I see what you are saying, and I think it will work.
I wanted X button on the popup window to only perform: PopUpManager.removePopUp(this);
But it looks like the X button when clicked is automatically is dispatching the CloseEvent which is turn is changing the view.
I guess I can hide the close button on the titleWindon and use two additonal custom buttons which will give me more flexibility in term on of doing exactly what I need. 
Thanks a bunch..
0 Kudos
AaronNash1
Frequent Contributor
I turn off the x button on the pop-ups, when using a mobile device the button can be a little small. That way I can create mobile friendly buttons that the user can interact with. To get rid of the X button I created a new mxml skin for a spark titlewindow and just commented out the code which was on line 257

                <!--s:Button id="closeButton" skinClass="spark.skins.spark.TitleWindowCloseButtonSkin"
                          width="15" height="15" right="7" top="7" /-->
0 Kudos