-
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
}
}
-
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);a
-
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);
}}
-
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.
-
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
-
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.
-
1 Attachment(s)
Attachment 73911
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
-
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);a
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.
-
Mmmm i have Flash CS6, it doesn't support Slides and forms...let me open Macromedia Flash 2004...i mean Flash 8
-
Wow! Flash CS6, Flash 8, Flash CS5, none of them opens your file hehe. NOw i'm trying to open it in Flash CS3.
-
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
-
Please, go to File> Save As, and save it to CS3 or other, i have all the flash versions but CS4.
-
1 Attachment(s)
Attachment 73913 Here you go CS3 thanks
-
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.
-
So put the code on every slide and name the slide rather than gotoNextSlide(); ie screen.roostSlide.gotoSlide(Slide2);
-
I don't know why, but gotoNextSlide(); and gotoPreviousSlide(); are not working for me. I tried removing the brackets...no success.
-
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 :)
-
You are a star!! I think I love you lol thanks for all your help it is very much appreciated
-
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.