3 Replies Latest reply on Oct 25, 2011 2:45 PM by Jason Szeto

    setting properties of a new view using pushView()?

    JAXIMFLASH Level 1

      I am creating a new view when I use the ViewNavigator's pushView() method.

      How do I set the properties of the new view?

       

      For example, let's say the new view has a "color" property. Is there a way to set the property before the view has been created? Can I somehow set the property in pushView()'s conext property? If so, how?

       

      I am also okay with setting the property after the view has veen created. What is the event the viewNavigator should listen for to know that the view has been created and the navigator can then set the "color" property?

        • 1. Re: setting properties of a new view using pushView()?
          JAXIMFLASH Level 1

          Found more info about this:

          The context object can be set in the pushView() method. I read somewhere that the context object would be a property of the View: i.e. View.context. However that is not true. The context object is part of the viewNavigator. So when the View has been Added, then the view can ckeck it's navigator's context object.

           

          "context specifies an arbitrary object written to the ViewNavigator.context property. When the new view is created, it can reference this property and perform an action based on this value. For example, the view could display data in different ways based on the value of context."

           

          But I still have a question as to what event that a viewNavigator can listen for that is dispatched when a pushed view has finally been added or made active. Anyone know?

          • 2. Re: setting properties of a new view using pushView()?
            JAXIMFLASH Level 1

            I found the event that the viewNavigator dispatches when a View is changed. You can either have the ViewNavigator listen when it dispatches the spark.events.ElementExistenceEvent.ELEMENT_ADD event type.

            Or if you are using MXML, you can add the "elementAdd" event handler property onto the ViewNavigator xml node: <s:ViewNavigator elementAdd="onViewAdded(event)"/>

            • 3. Re: setting properties of a new view using pushView()?
              Jason Szeto Level 3

              The recommended way to pass data into a View is to use the data parameter of the pushView function.

               

              navigator.pushView(myView, myData);

               

              On the View, listen for the "dataChange" event and then access the data through the "data" property. Context is used in a slightly different way. Read the section on context in the spec: http://opensource.adobe.com/wiki/display/flexsdk/View+and+ViewNavigator

               

              To listen for when a view has been activated or deactivated, listen for the viewActivate and viewDeactivate events on the View itself.

               

              Jason