6 Replies Latest reply on Sep 1, 2011 1:20 PM by Francisc

    Condition appearance of actionContent

    Francisc Level 3

      Hello,

       

      I want to not have actionContent in most views (so empty array), but have it in some.

      How is this done?

       

      Currently I have it defined in the Main application file and the only button in is is set to visible=false.

      In the views where I want to show, I made a public method in the main application file that unhides it.

       

      I don't like that.

      How can it be done better?

       

      Thank you.

        • 1. Re: Condition appearance of actionContent
          Shongrunden Adobe Employee

          Are you looking for View.actionBarVisible?

          • 2. Re: Condition appearance of actionContent
            Francisc Level 3

            I'm not entirely sure, but I don't think so.

            I don't want to kill off the entire ActionBar but rather just the actionContent.

             

            I've changed the way I do this (because hiding the array children buttons did not show them, but still took up space) to this:

             

            Main Application File (the ViewNavigatorApplication):

             

            public function addActionContentButton():void
            {
                var icon:MultiDPIBitmapSource=new MultiDPIBitmapSource();
                icon.source160dpi=...file...;
                icon.source240dpi=...file...;
                icon.source320dpi=...file...;
                var button:Button=new Button();
                button.setStyle("icon",icon);
                button.addEventListener(MouseEvent.CLICK,actionContentClick);
                actionContent=[button];
            }
            private function actionContentClick(event:MouseEvent):void
            {
                var ev:Event=new Event('actionContentClick');
                dispatchEvent(ev);
            }
            public function clearActionContent():void
            {
                actionContent=[];
            }

             

            And the views that have a button in the actionContent, I call:

             

            FlexGlobals.topLevelApplication.addActionContentButton(); -> on creationComplete

            FlexGlobals.topLevelApplication.clearActionContent(); -> on viewDeactivate

             

             

            I was thinking there is a better way for something like this.

            • 3. Re: Condition appearance of actionContent
              Shongrunden Adobe Employee

              I'm not sure I follow, but you should be able to set an actionContent on your main application then override that in the View:

               

              Main.mxml:

               

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

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

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

                                          firstView="views.HomeView">

               

                  <s:actionContent>

                      <s:Button label="test" />

                  </s:actionContent>

              </s:ViewNavigatorApplication>

               

              HomeView.mxml:

               

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

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

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

               

                  <s:actionContent>

                      <!-- empty array -->

                  </s:actionContent>

              </s:View>

              • 4. Re: Condition appearance of actionContent
                Francisc Level 3

                Sorry for being unclear.

                What I am trying to achieve is condition the appearance (occurance) of an actionContent button.

                Some Views need it, others don't.

                 

                What I am doing now is in the viewActivate event handler I add the button and remove it on viewDeactivate event hander.

                 

                Is that how this is supposed to work?

                • 5. Re: Condition appearance of actionContent
                  Shongrunden Adobe Employee

                  Does my last post not work for you?  ViewA will have <s:actionContent></s:actionContent> (set to an empty array).  ViewB would not define any actionContent and the default from the main application would be used.  The main application would have actionContent defined with your Button.  This should mean that ViewA has no Button in its actionContent, but ViewB still does.

                  1 person found this helpful
                  • 6. Re: Condition appearance of actionContent
                    Francisc Level 3

                    It does, but I am looking for ActionScript solution.

                    In the event handlers I mentioned I am calling public methods from the ViewNavigatorApplication do add or remove buttons.