3 Replies Latest reply on Sep 25, 2010 7:41 AM by laxmidi

    Problem setting the ViewStack.selectedChild=

    laxmidi Level 1

      Hi,

       

      I'm using deep linking on my Flex 3 website.

       

      In the parseUrl function I'm taking the browserfragment:

      a) converting it to a string

      b) replacing a hyphen with a dash

      c) then casting it back to an object in order to be able to use it to select the ViewStack's child.

       

      So, I'm converting for example, the fragment my-stuff to my_stuff and then using it to change the viewStack.

       

      my_stuff is the child of mainViewStack, but for some reason it's not working. If I leave off the "as Container" in the last line, then I get error 1118:Implicit coercion of a value with static type Object to a possibly unrelated type mx.core:Container

       

       

       

      private function parseUrl(e:BrowserChangeEvent = null):void {

       

         var o:Object = URLUtil.stringToObject(browserManager.fragment);

       

        var j:Object = o.view;

       

        var f:String = String(j);

       

        var c:String = f.replace(/-/g,"_");

       

        var t:Object = c as Object;

       

       

        mainViewStack.selectedChild = t as Container;

       

       

      }

       

       

       

      What am I doing wrong? Lots of time poured into solving this problem but without any luck.

       

      -Laxmidi

        • 1. Re: Problem setting the ViewStack.selectedChild=
          BhaskerChari Level 4

          Hi Laxmi,

           

          You are doing wrong the way you are trying to set the selected Child of the ViewStack. You cannot convert an Object to Container class and then assign to the viewstack selectedChild property.

           

          For the selectedChild property you can directly assign the id of your container(mind you not the string id of the child - but the reference to the child).

           

          If I am right In your code I think my_stuff refers to the id of the ViewStack....If so then you can do the following ...

           

           

          private function parseUrl(e:BrowserChangeEvent = null):void {

           

             var o:Object = URLUtil.stringToObject(browserManager.fragment);

           

            var j:Object = o.view;

           

            var f:String = String(j);

           

            var c:String = f.replace(/-/g,"_");

           

            var t:Container = mainViewStack.getChildByName(c) as Container;

            

            mainViewStack.selectedChild = t;

           

          }

           

          Please try this and let me know.

           

          Thanks,

          Bhasker Chari

          • 2. Re: Problem setting the ViewStack.selectedChild=
            laxmidi Level 1

            Hi Bhasker Chari,

             

            Thank you so much for the help! I spent 5 hours working on this problem without any result.. Your reply was extremely helpful.

             

            We're very close to solving this nightmare bug. 

             

            I'm getting one error on start up. If I dismiss the error, then the deeplinking and browser bar work perfectly.

             

            TypeError: Error #2007: Parameter child must be non-null.

            at flash.display::DisplayObjectContainer/getChildIndex()

            at mx.core::Container/getChildIndex()[C:\autobuild\3.2.0\frameworks\projects\framework\src\m x\core\Container.as:2411]

            at mx.containers::ViewStack/set selectedChild()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\containers\ViewSt ack.as:557]

            at property/parseUrl()[/Users/myname/Documents/Flex Builder 3/property/src/property.mxml:8803]

            at property/initBrowserManager()[/Users/myname/Documents/Flex Builder 3/property/src/property.mxml:8749]

            at property/___property_Application1_creationComplete()[/Users/myname/Documents/Flex Builder 3/property/src/property.mxml:19]

            at flash.events::EventDispatcher/dispatchEventFunction()

            at flash.events::EventDispatcher/dispatchEvent()

             

            If you have any suggestions, please let me know. Thank you.

             

            -Laxmidi

            • 3. Re: Problem setting the ViewStack.selectedChild=
              laxmidi Level 1

              Hi,

               

               

              I figured it out. I need to add:

               

              if(t!=null){mainViewStack.selectedChild = t}

                else{mainViewStack.selectedIndex = 0}

               

              The children hadn't been created, yet.

               

              Thank you.

               

              -Laxmidi