8 Replies Latest reply: Nov 29, 2011 8:49 AM by nikolaig RSS

    Button access inside a scroll pane???

    nikolaig Community Member

      I have implemented a scroll pane component and content of it is a layout of images which are buttons.

      Scroll pane name is "mc_pane2"

      Content class is "MyContent"

      And the button's instance name is "FloraLytell_btn" (It is essensially an mc with TweenLite code in it for roll over and roll out effects)

       

      I am not able to figure out what would be a code to access a button inside the scroll pane. Below is what I have tried and it doesn't work.

       

       

      mc_pane2.MyContent.FloraLytell_btn.addEventListener(MouseEvent.CLICK, onClick_floralytellPopUp);

       

       

      function onClick_floralytellPopUp(event:MouseEvent) :void {

                gotoAndPlay("floralyte2pp");

       

       

      }

        • 1. Re: Button access inside a scroll pane???
          Ned Murphy CommunityMVP

          To target the content of the scrollpane you would use mc_pane2.content

           

          What are you trying to tell to gotoAndPlay with that button?

          • 2. Re: Button access inside a scroll pane???
            nikolaig Community Member

            Thanks,

            That button is supposed to access a labeled section on the main time frame

             

            I also implemented the TweenLite inside the scrollable content I had to put

            the code in the content mc, otherwise it did not work

            Should it be located on the main mc on the AS3 layer?

            • 3. Re: Button access inside a scroll pane???
              Ned Murphy CommunityMVP

              It is more often easier to manage code when it is all in one location, and can usually be done that way, but it is not a requirement.

              • 4. Re: Button access inside a scroll pane???
                nikolaig Community Member

                I can not figure out what is wrong with my code.

                 

                Here is my set up:

                1. I have a scroll pane which calls the mc named "content_mc" and is

                exported for action script with class "MyContent"

                2. I have a button which I need to make work located on the "content_mc"

                and is named "FloraLytell_btn"

                 

                I made a simple sample TweenLite code which animated the button movement on

                the stage.

                 

                All of the above works and functions as long as I have my code located on

                the "content_mc" I wanted to keep it all nice and clean and locate my code

                on the main time line.

                As soon as I move it there it does not work. I tried many different things

                but none of them produced successful results.

                My code is pasted below. I surmise that the problem is in the line

                "mc_pane2.source.FloraLytell_btn" and what needs to be specified in order

                to get to my button.

                So I specify that it is located in "mc_pane2" then I specify the "source"

                and then the button "FloraLytell_btn"

                Is something wrong in the preceding code arrangement for "mc_pane2"?

                 

                 

                stop();

                 

                import flash.display.StageScaleMode;

                import flash.events.MouseEvent;

                 

                stage.scaleMode = StageScaleMode.NO_SCALE;

                 

                 

                 

                mc_pane2.source = MyContent;

                mc_pane2.horizontalScrollPolicy = "off";

                mc_pane2.update();

                 

                 

                stage.addEventListener(MouseEvent.MOUSE_WHEEL, mouseWheelHandler);

                 

                function mouseWheelHandler(event:MouseEvent):void {

                mc_pane2.verticalScrollPosition -= event.delta;

                }

                 

                ////////////////////////////////////////////////////////////////////////////////////////// /////////////////////

                 

                import com.greensock.*;

                import com.greensock.easing.*;

                 

                        TweenLite.to(mc_pane2.source.FloraLytell_btn, 1, );

                • 5. Re: Button access inside a scroll pane???
                  Ned Murphy CommunityMVP

                  You seem to have missed my first response because you keep targeting the 'source' whereas I indicated you need to target the 'content'

                  • 6. Re: Button access inside a scroll pane???
                    nikolaig Community Member

                    I tried that too. That was my first effort and it did not work for me.

                    The reason why I changed for "source" is because in my code for the scroll

                    pane it is scripted:

                    mc_pane2.source = MyContent;

                     

                     

                    Here is the code how I changed first time around based on your original

                    suggestion (I am also giving the code I am using for scroll pane just to

                    make sure that this doesn't cause any errors):

                     

                    import flash.display.StageScaleMode;

                    import flash.events.MouseEvent;

                     

                    stage.scaleMode = StageScaleMode.NO_SCALE;

                     

                     

                    mc_pane2.source = MyContent;

                    mc_pane2.horizontalScrollPolicy = "off";

                    mc_pane2.update();

                     

                     

                    stage.addEventListener(MouseEvent.MOUSE_WHEEL, mouseWheelHandler);

                     

                    function mouseWheelHandler(event:MouseEvent):void {

                    mc_pane2.verticalScrollPosition -= event.delta;

                    }

                     

                    ////////////////////////////////////////////////////////////////////////////////////////// /////////////////////

                     

                    import com.greensock.*;

                    import com.greensock.easing.*;

                     

                     

                            TweenLite.to(mc_pane2.content.FloraLytell_btn, 1, );

                     

                     

                    Here is the error message I am getting with it:

                     

                    1119: Access of possibly undefined property FloraLytell_btn through a

                    reference with static type flash.display:DisplayObject.

                    • 7. Re: Button access inside a scroll pane???
                      Ned Murphy CommunityMVP

                      Try casting the content as a MovieClip (the compiler is refusing to accept that the content is a DisplayObject without you explicitly saying so)...

                       

                      TweenLite.to(MovieClip(mc_pane2.content).FloraLytell_btn, 1, {x: 200});

                      • 8. Re: Button access inside a scroll pane???
                        nikolaig Community Member

                        As always, thank for your help, it is all working now.

                        I am new to the whole coding thing, I arranged a few lines of code for this button and was hoping you can take a look and give me feedback if they look appropriate or should be arranged somehow differently.

                        I will have up to 20 buttons like this in this section.

                         

                         

                        import flash.display.StageScaleMode;

                        import flash.events.MouseEvent;

                         

                         

                        stage.scaleMode = StageScaleMode.NO_SCALE;

                         

                         

                         

                         

                        mc_pane2.source = MyContent;

                        mc_pane2.horizontalScrollPolicy = "off";

                        mc_pane2.update();

                         

                         

                         

                        stage.addEventListener(MouseEvent.MOUSE_WHEEL, mouseWheelHandler);

                         

                         

                        function mouseWheelHandler(event:MouseEvent):void {

                                  mc_pane2.verticalScrollPosition -= event.delta;

                        }

                         

                         

                        ////////////////////////////////////////////////////////////////////////////////////////// /////////////////////

                         

                         

                        import com.greensock.*;

                        import com.greensock.easing.*;

                         

                         

                         

                         

                        MovieClip(mc_pane2.content).FloraLytell_btn.buttonMode = true;

                        MovieClip(mc_pane2.content).FloraLytell_btn.useHandCursor = true;

                         

                         

                         

                         

                                  MovieClip(mc_pane2.content).FloraLytell_btn.FloraLytell_ON.alpha = 0;

                                            var  myTween:TweenLite = TweenLite.to(MovieClip(mc_pane2.content).FloraLytell_btn.FloraLytell_ON, .5, {alpha:1, paused:true});

                                

                                            MovieClip(mc_pane2.content).FloraLytell_btn.addEventListener(MouseEvent.ROLL_OV ER, overHandler);

                                            MovieClip(mc_pane2.content).FloraLytell_btn.addEventListener(MouseEvent.ROLL_OU T, outHandler);

                         

                                MovieClip(mc_pane2.content).FloraLytell_btn.addEventListener(MouseEvent.CLICK, onClick_floralytellPopUp);

                         

                                          function onClick_floralytellPopUp(event:MouseEvent) :void {

                                                                gotoAndPlay("floralyte2pp");

                         

                                             }