PDA

View Full Version : If the user clicks on a slide, it takes him into a different page on the website.


Baldur2630
01-26-2009, 08:49 PM
I've got the fundamentals of Flash (just about) now time to start looking at action scripts but I have a job I have to do for my Boss and I'm stuck!

I have 4 Slides. Thet are created in PowerPoint and I converted them to a swf file using the ppt timings. Each slide shows for 5 secs. On the last slide it goes back to the first and loops.

Now what I want to do is -

If the user clicks on a slide, it takes him into a different page on the website. It would be nice if I could set it so that each slide, if clicked on, goes to a different page, but this isn't SO important.

I don't want to start adding buttons and controls, it's inside the Index page and there is a panel of buttons but at the ver least I want to either stop the loop or better take me to a different page or the very best take me to a page depending on which slide they click on.

I have converted the swf to a ,fla and it works fine inside Adobe Flash CS3

Can anyone please give me a method of doinfg this?

T24
01-31-2009, 08:55 PM
Alright, so you have 4 slides, each in their own frame all on one layer. Just add this code (action-script 3.0) on each frame:

stage.addEventListener(MouseEvent.CLICK, clickHandler);
function clickHandler (event:MouseEvent):void
{
navigateToURL(new URLRequest ("http://www.actionscript.org"));
}

Just change the URL ("http://www.actionscript.org") to the URL you want on each frame. When the movie plays and you click anywhere on the stage/ slide then the browser will navigate to the specified URL.

Baldur2630
02-01-2009, 05:03 PM
Sorry, I tried it, but now I get 3 compile errors

Page 1, layer 'scripts5' frame 2, 1021 Duplicate function definition function. clickHandler (event:MouseEvent):void

I get this on frames 2, 3 and 4.

T24
02-01-2009, 09:44 PM
Sorry, I forgot to tell you to change the names of the functions and event listeners on each frame.

Go to frame 2 and replace the code I gave you with this:
stage.addEventListener(MouseEvent.CLICK, clickHandler2);
function clickHandler2 (event:MouseEvent):void {
navigateToURL(new URLRequest ("http://www.actionscript.org"));
}

Then go to frame 3 and put this there instead:
stage.addEventListener(MouseEvent.CLICK, clickHandler3);
function clickHandler3 (event:MouseEvent):void {
navigateToURL(new URLRequest ("http://www.actionscript.org"));
}

And on frame 4:
stage.addEventListener(MouseEvent.CLICK, clickHandler4);
function clickHandler4 (event:MouseEvent):void {
navigateToURL(new URLRequest ("http://www.actionscript.org"));
}

The error was telling you that you had duplicate functions on frames 2, 3, and 4.

Baldur2630
02-01-2009, 11:13 PM
Thanks a stack, works like a dream.

Baldur2630
02-09-2009, 06:09 PM
I feel like banging my head on the wall!

The code you gave me worked BEAUTIFULLY. I created exactly the same slides in the same way, in a different language.

I copied the code from the working slides to the new slides and I get a compiler error.

I go to the original (working) Slides, hit CTRL-ENTER to test the movie and it WORKS. Now I go to the Action Script Code and it also gives me a compiler error.

What IS the problem?

Here is the Code - It's what you gave me but now it doesn't seem to work anymore.

stage.addEventListener(MouseEvent.CLICK, clickHandler);
function clickHandler (event:MouseEvent):void
{
navigateToURL(new URLRequest ("http://www.actionscript.org"));
}


Compiler Error - 1 reported

Scene=Page1,layer=Scripts1,frame=1,line=2 '{' expected function clickHandler(event:MouseEvent):void

T24
03-24-2009, 10:15 PM
Sorry if this is a late reply. Try uploading the file with the error so I can download it and check what is wrong. There doesn't seem to be anything wrong with the code you posted.

Baldur2630
03-24-2009, 11:57 PM
It's OK, I'm busy learning Action Script! Sorted it out myself - works fine now.

Thanks anyway. I'm sure I'll be back when I screw something else up! Nice to know there's a place that you can turn to for help.