A Flash Developer Resource Site

Results 1 to 13 of 13

Thread: Navigating through slideshow

  1. #1
    Member
    Join Date
    Sep 2009
    Posts
    72

    Navigating through slideshow

    I have two movieclips this is based off of. work_mc and workss_mc

    Work_mc is a collection of thumbnails on one frame.

    Workss_mc is a collection of larger images with descriptions that has to ability to scroll through each slide

    The way you navigate this is you click in work_mc, whatever thumbnail you choose and it will open workss_mc.
    Once you are inside of work_mc you can view the image, go back(which takes you back to work_mc) or you have prev and next

    Workss_mc consistants of multiple frames and each frame has a different image on it.


    Here is the code for a button in work_mc:

    Actionscript Code:
    twentythreemographthmb_mc.addEventListener(MouseEvent.CLICK, clickHandler2);
    twentythreemographthmb_mc.buttonMode=true;

    function clickHandler2(event:MouseEvent):void {

         var workss_mc = new mc_workss();
         newClassRoot.showModalContent(workss_mc);
         workss_mc.x=225;
         workss_mc.y=200;
         workss_mc.gotoAndStop("twentythreemotion");
         workss_mc.addEventListener("closeButtonClick10", onCloseClick10);


    }

    function onCloseClick10(e:Event):void {
         var work_mc = new mc_work();
         newClassRoot.showModalContent(work_mc);
         work_mc.x=225;
         work_mc.y=130;
    }

    So this should go to twentythreemotion and stop, which it does and it works correctly.

    However, once you are in workss_mc the prev and next button are not functioning properly.

    If you click on the first thumbnail and start the show from the beginning: This is on frame 1 of workss_mc..

    Actionscript Code:
    var a:Array=["urban","twentythree","citibrochure","csccard","rokroom","hiphop","metal","vangogh"];
    var currentIndex:int=0;
    worknextbtn_mc.addEventListener(MouseEvent.CLICK, worknextClicked);
    function worknextClicked(event:MouseEvent) {
         currentIndex++;
         if (currentIndex>=a.length) {
              currentIndex=0;
         }
         gotoAndStop(a[currentIndex]);
    }

    workprevbtn_mc.addEventListener(MouseEvent.CLICK, workprevClicked);
    function workprevClicked(event:MouseEvent) {
         currentIndex--;
         if (currentIndex>=a.length) {
              currentIndex=0;
         }
         gotoAndStop(a[currentIndex]);
    }

    This works correctly if I choose the first thumbnail that goes to frame one but if I choose another thumbnail on work_mc that will go to a different frame label in workss_mc the prev/next buttons won't function properly..

  2. #2
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    I immediately see one error, but I don't think it's the one you're talking about. Since you are checking for currentIndex>=a.length in workprevClicked, it won't loop around when going backwards. That code actually needs to test whether it is <0 and if so set it to a.length -1.

    What is probably happening with workss_mc is that if you don't go to the first frame, the code on that frame isn't executed and the buttons don't get set up.

    If you have a class for workss_mc, then you could move that code into the class and call it from the constructor, ensuring that it will always have been executed. Be sure to set currentIndex correctly on each frame though. You could change the currentIndex stuff to calculate from the current frame label.

    Code:
          var a:Array=["urban","twentythree","citibrochure","csccard","rokroom","hiphop","metal","vangogh"];
          worknextbtn_mc.addEventListener(MouseEvent.CLICK, worknextClicked);
          function worknextClicked(event:MouseEvent) {
               var currentIndex:int = a.indexOf(currentFrameLabel);
               currentIndex++;
               if (currentIndex>=a.length) {
                    currentIndex=0;
               }
               gotoAndStop(a[currentIndex]);
          }
           
          workprevbtn_mc.addEventListener(MouseEvent.CLICK, workprevClicked);
          function workprevClicked(event:MouseEvent) {
               var currentIndex:int = a.indexOf(currentFrameLabel);
               currentIndex--;
               if (currentIndex>=a.length) {
                    currentIndex=0;
               }
               gotoAndStop(a[currentIndex]);
          }

  3. #3
    Member
    Join Date
    Sep 2009
    Posts
    72
    Yes, that is the exact problem. It's skipping frame 1 and the code isnt being executed. I don't have a class set up for it

  4. #4
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Then you've got two options:
    1. make the mc_workss class. shouldn't be too difficult.
    or
    2. make mc_workss a container which has a movieclip inside it which is the current mc_workss. That out clip will set up the buttons and listeners, and will have a method to advance the inner clip to the correct frame. Use that method instead of gotoAndStop from work_mc.

  5. #5
    Member
    Join Date
    Sep 2009
    Posts
    72
    Alright, I'd be interested in setting up a mc_workss class. Could you give me some pointers about what to include and it and setting it up?

  6. #6
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    I don't usually use the IDE, so I'm not 100% on how to properly get the class to refer to ide-placed children. I think this should work, though:
    Code:
    package {
       //add imports here
    
      public class mc_workss extends MovieClip{
          private var a:Array;
          public var worknextbtn_mc:MovieClip;
          public var workprevbtn_mc:MovieClip;
    
          public function mc_workss(){
            a = ["urban","twentythree","citibrochure","csccard","rokroom","hiphop","metal","vangogh"];
            init();
          }
    
          private function init():void{
            worknextbtn_mc.addEventListener(MouseEvent.CLICK, worknextClicked);
            workprevbtn_mc.addEventListener(MouseEvent.CLICK, workprevClicked);
          }
    
          private function worknextClicked(event:MouseEvent):void {
               var currentIndex:int = a.indexOf(currentFrameLabel);
               currentIndex++;
               if (currentIndex>=a.length) {
                    currentIndex=0;
               }
               gotoAndStop(a[currentIndex]);
          }
           
          private function workprevClicked(event:MouseEvent) {
               var currentIndex:int = a.indexOf(currentFrameLabel);
               currentIndex--;
               if (currentIndex<0) {
                    currentIndex=a.length - 1;
               }
               gotoAndStop(a[currentIndex]);
          }    
      }
    }
    If you get errors about worknextbtn_mc is null, let me know. We might have to get them by name in the init.

  7. #7
    Member
    Join Date
    Sep 2009
    Posts
    72
    Something like this?

    Actionscript Code:
    private var a:Array=["urban","twentythree","citibrochure","csccard","rokroom","hiphop","metal","vangogh"];
         
         public function worknextClicked() {
               var currentIndex:int = a.indexOf(currentFrameLabel);
               currentIndex++;
               if (currentIndex>=a.length) {
                    currentIndex=0;
               }
               gotoAndStop(a[currentIndex]);
          }
           
         
         public function workprevClicked() {
               var currentIndex:int = a.indexOf(currentFrameLabel);
               currentIndex--;
               if (currentIndex>=a.length) {
                    currentIndex=0;
               }
               gotoAndStop(a[currentIndex]);
          }

  8. #8
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    More or less. It's important to set up the buttons in the class as well, since the whole reason stuff wasn't working was that they weren't getting listeners added when you skip frame 1.

  9. #9
    Member
    Join Date
    Sep 2009
    Posts
    72
    looks like alot less than yours ha. I'm testing your code out right now..

    Actionscript Code:
    package {

        import flash.display.*;
        import FluidLayout.*;
        import flash.display.Sprite;
        import flash.display.StageAlign;
        import flash.display.StageScaleMode;
        import flash.events.Event;
        import gs.*;
        import gs.easing.*;
        import fl.motion.easing.*;
        import com.greensock.*;
        import flash.text.AntiAliasType;
        import flash.text.TextField;
        import flash.text.TextFieldAutoSize;
        import flash.events.MouseEvent;
        import flash.display.*;
        import flash.events.*;
        import flash.net.URLRequest;

        public class Website extends MovieClip {
           
          private var a:Array;
          public var worknextbtn_mc:MovieClip;
          public var workprevbtn_mc:MovieClip;

          public function mc_workss(){
            a = ["urban","twentythree","citibrochure","csccard","rokroom","hiphop","metal","vangogh"];
            init();
          }

          private function init():void{
            worknextbtn_mc.addEventListener(MouseEvent.CLICK, worknextClicked);
            workprevbtn_mc.addEventListener(MouseEvent.CLICK, workprevClicked);
          }

          private function worknextClicked(event:MouseEvent):void {
               var currentIndex:int = a.indexOf(currentFrameLabel);
               currentIndex++;
               if (currentIndex>=a.length) {
                    currentIndex=0;
               }
               gotoAndStop(a[currentIndex]);
          }
           
          private function workprevClicked(event:MouseEvent) {
               var currentIndex:int = a.indexOf(currentFrameLabel);
               currentIndex--;
               if (currentIndex<0) {
                    currentIndex=a.length - 1;
               }
               gotoAndStop(a[currentIndex]);
          }    
      }
     

            public function Website() {this.addEventListener("addedToStage", initVar); }
               
                private function initVar(e:Event){
    ******** this.removeEventListener("addedToStage", initVar);
                stage.scaleMode=StageScaleMode.NO_SCALE;
                stage.align=StageAlign.TOP_LEFT;

            }

        private var currentlyShowing:MovieClip=null;

            public function showModalContent(clip:MovieClip):void {
                if (currentlyShowing!=null) {
                    removeChild(currentlyShowing);
                }
                currentlyShowing=clip;
                addChild(currentlyShowing);
            }

            public function removeModalContent():void {
                if (currentlyShowing!=null) {
                    removeChild(currentlyShowing);
                    currentlyShowing=null;
                }

            }
       

        }

    }

    Line 59 1013: The private attribute may be used only on class property definitions.
    Line 66 1013: The private attribute may be used only on class property definitions.

  10. #10
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    mc_workss must be defined in its own file called mc_workss.as

    You can't just throw code for another class into Website.as.

  11. #11
    Member
    Join Date
    Sep 2009
    Posts
    72
    bastards. Alright, I thought I could.

  12. #12
    Member
    Join Date
    Sep 2009
    Posts
    72
    Actionscript Code:
    var currentIndex:int = a.indexOf(currentFrameLabel);

    In that, is currentFrameLabel supposed to be changed?

    1120: Access of undefined property currentFrameLabel.

  13. #13
    Member
    Join Date
    Sep 2009
    Posts
    72
    Actionscript Code:
    package {
        import flash.display.*;
        import FluidLayout.*;
        import flash.display.Sprite;
        import flash.display.StageAlign;
        import flash.display.StageScaleMode;
        import flash.events.Event;
        import gs.*;
        import gs.easing.*;
        import fl.motion.easing.*;
        import com.greensock.*;
        import flash.text.AntiAliasType;
        import flash.text.TextField;
        import flash.text.TextFieldAutoSize;
        //import flash.text.TextFormat;
        //import greensock.*;
        import flash.events.MouseEvent;
        import flash.display.*;
        import flash.events.*;
        import flash.net.URLRequest;


        public class mc_workss extends MovieClip {
            private var a:Array;
            private var currentIndex:int=0;
            public var worknextbtn_mc:MovieClip;
            public var workprevbtn_mc:MovieClip;

            public function mc_workss() {
                a=["urban","twentythree","citibrochure","csccard","rokroom","hiphop","metal","vangogh"];
                init();
            }

            private function init():void {
                worknextbtn_mc.addEventListener(MouseEvent.CLICK, worknextClicked);
                workprevbtn_mc.addEventListener(MouseEvent.CLICK, workprevClicked);
            }

            private function worknextClicked(event:MouseEvent):void {
                currentIndex++;
                if (currentIndex>=a.length) {
                    currentIndex=0;
                }
                gotoAndStop(a[currentIndex]);
            }

            private function workprevClicked(event:MouseEvent) {
                //   var currentIndex:int = a.indexOf(currentFrameLabel);
                currentIndex--;
                if (currentIndex<0) {
                    currentIndex=a.length-1;
                }
                gotoAndStop(a[currentIndex]);
            }
        }
    }

    Flax, I got it to work like this. I'm amazed on how much faster it loads this way! Even just clicking through it is SO much smoother!

    Thanks alot

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center