A Flash Developer Resource Site

+ Reply to Thread
Results 1 to 19 of 19
  1. #1
    Junior Member
    Join Date
    Nov 2012
    Posts
    8

    Next slide on keypress

    I'm fairly new to actionscript but I've created a flash presentation and it works great however I need to modify it slightly.

    As default if you press the right arrow it goes to the next slide and if you press the left arrow it goes to the previous slide.

    I need to change this function to work on pageup and pagedown key press.

    I've had a go at doing this myself but the function just repeats over and over and therefore when I press page up it goes rapidly flicks though all the slides until it gets to the end.

    Please can someone help. Heres my code:

    Code:
    onClipEvent(enterFrame){
     
        if (Key.getCode() == Key.PGDN) { 
           
    	   // GoTo Next Screen behavior
          var screen = null;
          var target = this;
          while((screen == null) && (target != undefined) && (target != null))
          {
            if(target instanceof mx.screens.Screen)
            {
              screen = target;
            }
            else
            {
              target = target._parent;
            }
          }
          if(screen instanceof mx.screens.Slide)
          {
            screen.rootSlide.currentSlide.gotoNextSlide();
          }
    	  // End GoTo Next Screen behavior
    	  
        }   
        else if (Key.getCode() == Key.PGUP) { 
           
    	    // GoTo Last Screen behavior
          var screen = null;
          var target = this;
          while((screen == null) && (target != undefined) && (target != null))
          {
            if(target instanceof mx.screens.Screen)
            {
              screen = target;
            }
            else
            {
              target = target._parent;
            }
          }
          if(screen instanceof mx.screens.Slide)
          {
            screen.rootSlide.gotoLastSlide();
          }
    	  // End GoTo Last Screen behavior
    	   
        }   
    
    }

  2. #2
    AS2 Coder
    Join Date
    Mar 2010
    Posts
    607
    Try this
    PHP Code:
        var keyListener:Object = new Object();
        
    keyListener.onKeyDown = function() {
       
     
        if (
    Key.isDown Key.PGDN)) { 
           
    trace("down");
           
    // GoTo Next Screen behavior
          
    var screen null;
          var 
    target this;
          while((
    screen == null) && (target != undefined) && (target != null))
          {
            if(
    target instanceof mx.screens.Screen)
            {
              
    screen target;
            }
            else
            {
              
    target target._parent;
            }
          }
          if(
    screen instanceof mx.screens.Slide)
          {
            
    screen.rootSlide.currentSlide.gotoNextSlide();
          }
          
    // End GoTo Next Screen behavior
          
        
    }   
     if (
    Key.isDown Key.PGUP)) { 
             
    trace("up");
            
    // GoTo Last Screen behavior
          
    var screen null;
          var 
    target this;
          while((
    screen == null) && (target != undefined) && (target != null))
          {
            if(
    target instanceof mx.screens.Screen)
            {
              
    screen target;
            }
            else
            {
              
    target target._parent;
            }
          }
          if(
    screen instanceof mx.screens.Slide)
          {
            
    screen.rootSlide.gotoLastSlide();
          }
          
    // End GoTo Last Screen behavior
           
           

    }
        };
        
    Key.addListener(keyListener);
    - Something better now, let's code! )

  3. #3
    Junior Member
    Join Date
    Nov 2012
    Posts
    8
    Hi thanks for the reply I have place the code on the Presentation frame as below, it works with the left and right arrows but not with pageup page down any ideas any help much appreciated:

    onClipEvent (enterFrame) {

    var keyListener:Object = new Object();
    keyListener.onKeyUp = function() {

    if (Key.isDown ( Key.PGDN)) {
    trace("down");
    // GoTo Next Screen behavior
    var screen = null;
    var target = this;
    while((screen == null) && (target != undefined) && (target != null))
    {
    if(target instanceof mx.screens.Screen)
    {
    screen = target;
    }
    else
    {
    target = target._parent;
    }
    }
    if(screen instanceof mx.screens.Slide)
    {
    screen.rootSlide.currentSlide.gotoNextSlide();
    }
    // End GoTo Next Screen behavior

    }

    if (Key.isDown ( Key.PGUP)) {
    trace("up");
    // GoTo Last Screen behavior
    var screen = null;
    var target = this;
    while((screen == null) && (target != undefined) && (target != null))
    {
    if(target instanceof mx.screens.Screen)
    {
    screen = target;
    }
    else
    {
    target = target._parent;
    }
    }
    if(screen instanceof mx.screens.Slide)
    {
    screen.rootSlide.gotoLastSlide();
    }
    // End GoTo Last Screen behavior



    }
    key.addListener(keyListener);

    }}

  4. #4
    AS2 Coder
    Join Date
    Mar 2010
    Posts
    607
    Sorry, i forgot to tell you, when you Test the movie, go to Control and click on Disable Keyboard shorcuts. If you use the script I gave to you, it should work now.
    - Something better now, let's code! )

  5. #5
    Junior Member
    Join Date
    Nov 2012
    Posts
    8
    Ok yes that works, in the sense that in the output window is shows Down or Up when the keys are pressed which is great its further than I have got before, but it dosent move the slides on when I export the swf file any more help is appreciated thanks again

  6. #6
    AS2 Coder
    Join Date
    Mar 2010
    Posts
    607
    May you post .fla to help you further? The script i gave you works on my side. Instead of going to a slide, i used a trace and it works. The important thing here is that the page up and page down buttons now works. If you can not go to any slide, is not the pageup/pagedown buttons fault. Please post the fla to see how your slide engine works.
    - Something better now, let's code! )

  7. #7
    Junior Member
    Join Date
    Nov 2012
    Posts
    8
    slidesTest.zip

    Original to large to upload but if we can get it working on this then It will work on the original thank you once again

  8. #8
    AS2 Coder
    Join Date
    Mar 2010
    Posts
    607
    I did this to test

    PHP Code:
    stop();

    var 
    keyListener:Object = new Object();
        
    keyListener.onKeyDown = function() {
       
     
        if (
    Key.isDown Key.PGDN)) { 
           
    trace("down");
           
    // GoTo Next Screen behavior
                
    gotoAndStop(2);
          var 
    screen null;
          var 
    target this;
          while((
    screen == null) && (target != undefined) && (target != null))
          {
            if(
    target instanceof mx.screens.Screen)
            {
              
    screen target;
              
            }
            else
            {
              
    target target._parent;
            }
          }
          if(
    screen instanceof mx.screens.Slide)
          {
            
    screen.rootSlide.currentSlide.gotoNextSlide();
            
            
          }
          
    // End GoTo Next Screen behavior
          
        
    }   
     if (
    Key.isDown Key.PGUP)) { 
             
    trace("up");
                  
    gotoAndStop(1);
            
    // GoTo Last Screen behavior
          
    var screen null;
          var 
    target this;
          while((
    screen == null) && (target != undefined) && (target != null))
          {
            if(
    target instanceof mx.screens.Screen)
            {
              
    screen target;
                   
            }
            else
            {
              
    target target._parent;
            }
          }
          if(
    screen instanceof mx.screens.Slide)
          {
        
            
    screen.rootSlide.gotoLastSlide();
          }
          
    // End GoTo Last Screen behavior
           
           

    }
        };
        
    Key.addListener(keyListener);
    I created 2 frames, put a stop(); on each one, and created a text on stage that reads Slide 1, Slide 2, then in the script i added
    if (Key.isDown ( Key.PGDN)) { gotoAndStop(2); } and if (Key.isDown ( Key.PGUP)) { gotoAndStop(1); }

    And it works. If you press the page down, it goes to frame 2. If you press page up, it goes back to frame 1. That is in the case of using the frames as slides. I don't know how you are creating the slides.
    - Something better now, let's code! )

  9. #9
    AS2 Coder
    Join Date
    Mar 2010
    Posts
    607
    Mmmm i have Flash CS6, it doesn't support Slides and forms...let me open Macromedia Flash 2004...i mean Flash 8
    - Something better now, let's code! )

  10. #10
    AS2 Coder
    Join Date
    Mar 2010
    Posts
    607
    Wow! Flash CS6, Flash 8, Flash CS5, none of them opens your file hehe. NOw i'm trying to open it in Flash CS3.
    - Something better now, let's code! )

  11. #11
    Junior Member
    Join Date
    Nov 2012
    Posts
    8
    It was done in CS4 on a mac and created: File new > Flash Slide Presentation, I should have done it all on a timeline instead of a presentation but if I can fix it its better than doing the whole thing again as there are about 100 slides
    Last edited by Ordog; 11-26-2012 at 06:56 AM.

  12. #12
    AS2 Coder
    Join Date
    Mar 2010
    Posts
    607
    Please, go to File> Save As, and save it to CS3 or other, i have all the flash versions but CS4.
    - Something better now, let's code! )

  13. #13
    Junior Member
    Join Date
    Nov 2012
    Posts
    8
    slidesTestCS3.zip Here you go CS3 thanks

  14. #14
    AS2 Coder
    Join Date
    Mar 2010
    Posts
    607
    PHP Code:
    onClipEvent(load){
    var 
    keyListener:Object = new Object();
        
    keyListener.onKeyDown = function() {
       
     
        if (
    Key.isDown Key.PGDN)) { 
           
    trace("down");
           
    // GoTo Next Screen behavior
                
    gotoSlide(slide1);
          var 
    screen null;
          var 
    target this;
          while((
    screen == null) && (target != undefined) && (target != null))
          {
            if(
    target instanceof mx.screens.Screen)
            {
              
    screen target;
              
            }
            else
            {
              
    target target._parent;
            }
          }
          if(
    screen instanceof mx.screens.Slide)
          {
            
    screen.rootSlide.currentSlide.gotoNextSlide();
            
            
          }
          
    // End GoTo Next Screen behavior
          
        
    }   
     if (
    Key.isDown Key.PGUP)) { 
             
    trace("up");
                 
    gotoSlide(slide2);
            
    // GoTo Last Screen behavior
          
    var screen null;
          var 
    target this;
          while((
    screen == null) && (target != undefined) && (target != null))
          {
            if(
    target instanceof mx.screens.Screen)
            {
              
    screen target;
                   
            }
            else
            {
              
    target target._parent;
            }
          }
          if(
    screen instanceof mx.screens.Slide)
          {
        
            
    screen.rootSlide.gotoLastSlide();
          }
          
    // End GoTo Last Screen behavior
           
           

    }
        };
        
    Key.addListener(keyListener);a  

    The way to navigate your slides is gotoSlide(slide2); where slide2 is the name of the slide you want to go.
    - Something better now, let's code! )

  15. #15
    Junior Member
    Join Date
    Nov 2012
    Posts
    8
    So put the code on every slide and name the slide rather than gotoNextSlide(); ie screen.roostSlide.gotoSlide(Slide2);

  16. #16
    AS2 Coder
    Join Date
    Mar 2010
    Posts
    607
    I don't know why, but gotoNextSlide(); and gotoPreviousSlide(); are not working for me. I tried removing the brackets...no success.
    - Something better now, let's code! )

  17. #17
    AS2 Coder
    Join Date
    Mar 2010
    Posts
    607
    ALRIGHT! Did it!

    PHP Code:
    onClipEvent(load){
    var 
    keyListener:Object = new Object();
        
    keyListener.onKeyDown = function() {
       
     
        if (
    Key.isDown Key.PGDN)) { 
           
    trace("down");
           
    // GoTo Next Screen behavior
                
    rootSlide.currentSlide.gotoPreviousSlide();
          var 
    screen null;
          var 
    target this;
          while((
    screen == null) && (target != undefined) && (target != null))
          {
            if(
    target instanceof mx.screens.Screen)
            {
              
    screen target;
              
            }
            else
            {
              
    target target._parent;
            }
          }
          if(
    screen instanceof mx.screens.Slide)
          {
            
    screen.rootSlide.currentSlide.gotoNextSlide();
            
            
          }
          
    // End GoTo Next Screen behavior
          
        
    }   
     if (
    Key.isDown Key.PGUP)) { 
             
    trace("up");
       
    rootSlide.currentSlide.gotoNextSlide();
            
    // GoTo Last Screen behavior
          
    var screen null;
          var 
    target this;
          while((
    screen == null) && (target != undefined) && (target != null))
          {
            if(
    target instanceof mx.screens.Screen)
            {
              
    screen target;
                   
            }
            else
            {
              
    target target._parent;
            }
          }
          if(
    screen instanceof mx.screens.Slide)
          {
        
            
    screen.rootSlide.gotoLastSlide();
          }
          
    // End GoTo Last Screen behavior
           
           

    }
        };
        
    Key.addListener(keyListener);a  

    rootSlide.currentSlide.gotoPreviousSlide(); and rootSlide.currentSlide.gotoNextSlide(); did the trick
    - Something better now, let's code! )

  18. #18
    Junior Member
    Join Date
    Nov 2012
    Posts
    8
    You are a star!! I think I love you lol thanks for all your help it is very much appreciated

  19. #19
    AS2 Coder
    Join Date
    Mar 2010
    Posts
    607
    No problem! ^_^ Anything else you want to do with that presentation thing, don't hesistate, inbox me, or just post it here. I never have used the presentation prototype before, i'm just experimenting with it.
    - Something better now, let's code! )

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