5 Replies Latest reply on Dec 11, 2011 10:40 PM by AlastairJMoore

    Custom components and the navigator object

    AlastairJMoore

      Hi all,

       

      I'm starting on a mobile project which is a ViewNavigator based application. I've created a custom component which contains a button. I'd like the button to be able to use the pushView method however as it's a custom component, it doesn't appear to recognise the navigator object. If anyone has any advice/tips on how I might go about this, it'd be greatly appreciated!

        • 1. Re: Custom components and the navigator object
          Flex harUI Adobe Employee

          The button is a custom component or the view is?  What line of code causes and error and what is the error?

          • 2. Re: Custom components and the navigator object
            AlastairJMoore Level 1

            The button sits in a custom component - actually in a datarenderer. Code looks like:

             

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

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

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

             

              <fx:Script>

                                <![CDATA[

                                          import mx.utils.ObjectUtil;

             

                                          protected function button1_clickHandler(event:MouseEvent):void

                                          {

                                          }

             

                                ]]>

              </fx:Script>

              <fx:Declarations>

              </fx:Declarations>

                      <s:Button label="{data.firstName}" click="button1_clickHandler(event)" width="150" height="150" />

            </s:DataRenderer>

            which is being called from a View. There's no error, I'm simply unable to/unsure how to access the navigator object so I can push a new view onto the stack from within that component.

             

            Cheers!

            • 3. Re: Custom components and the navigator object
              Flex harUI Adobe Employee

              One of the reasons it isn’t obvious is because it isn’t recommended.

               

              The clickHandler should probably just dispatch a custom event from the owner, which should be the containing component.

                  owner.dispatchEvent(new Event(“buttonInRendererClick”));

               

              Then the document containing the component, which is more likely to be a navigator, determines what to do.

              1 person found this helpful
              • 4. Re: Custom components and the navigator object
                AlastairJMoore Level 1

                Ah great stuff. That's even more useful! Thanks very much! I'll try it out.

                 

                Ok, that's not quite working although I guess it's because I'm having the incorrect "owner" try and fire off an event. When I do a trace('owner'), the console reports:

                 

                Main0.ViewNavigatorApplicationSkin2.navigator.ViewNavigatorSkin4.contentGroup.Friends115.S kinnableContainerSkin118.contentGroup._Friends_DataGroup1

                 

                Is there a quick method to get to the view rather than something like owner.parent.parent.parent (etc.)?

                • 5. Re: Custom components and the navigator object
                  AlastairJMoore Level 1

                  It could well be the case I'm going about this the wrong way But apart from this issue, it appears to be working.