Skip to main content
Inspiring
June 21, 2009
Question

Super amateur question follow-up (URL help needed)

  • June 21, 2009
  • 3 replies
  • 1080 views

I neglected to say in a previous post that I actually have five images in the flash animation that need to link to web pages.

I duplicated the code that worked on one image. Now I get an error saying there are duplicate function definitions. Here is the code I have added which I hoped would work for three images. It doesn't. Your help is greatly appreciated.

bfcSyringe_mc.addEventListener(MouseEvent.CLICK,onClick);

function onClick(evt:Event):void {

    var targetURL:URLRequest = new URLRequest("http://hodentalcompany.com/pages/syringe.html");

    navigateToURL(targetURL, "_self");

}

fpr_mc.addEventListener(MouseEvent.CLICK,onClick);

function onClick(evt:Event):void {

    var targetURL:URLRequest = new URLRequest("http://hodentalcompany.com/pages/fpr.html");

    navigateToURL(targetURL, "_self");

}

sandTrap_mc.addEventListener(MouseEvent.CLICK,onClick);

function onClick(evt:Event):void {

    var targetURL:URLRequest = new URLRequest("http://hodentalcompany.com/pages/sand.html");

    navigateToURL(targetURL, "_self");

}

This topic has been closed for replies.

3 replies

JustBobAuthor
Inspiring
June 23, 2009

Well, here's what I did.

I converted the Flash file to Action Script 2. Then attached the getURL code to each image. Works like a charm. So much easier than AS3 for a non-programmer like me.

Thank you all for your help!

funkysoul
Inspiring
June 21, 2009

you can also a use a simple switch case statement so you only use one single function:

you just need to assign a name to your "buttons"

bfcSyringe_mc.addEventListener(MouseEvent.CLICK,onClick);

bfcSyringe_mc.name = "bfc";

fpr_mc.addEventListener(MouseEvent.CLICK,onClick);

fpr_mc.name = "fpr";

sandTrap_mc.addEventListener(MouseEvent.CLICK,onClick);

sandTrap_mc.name = "sand";

function onClick(evt:Event):void {

switch(e.target.name)

{

case "bfc":

    navigateToURL(new URLRequest("http://hodentalcompany.com/pages/syringe.html"), "_blank");

    break;

case "fpr":

    navigateToURL(new URLRequest("http://hodentalcompany.com/pages/fpr.html"), "_blank");

    break;

case "sand":

    navigateToURL(new URLRequest("http://hodentalcompany.com/pages/sand.html"). "_blank");

    break;

}

}

JustBobAuthor
Inspiring
June 22, 2009

And, for Funky Soul's solution, I used this code:

bfcSyringe_mc.addEventListener(MouseEvent.CLICK,onClick);

bfcSyringe_mc.name = "bfc";

fpr_mc.addEventListener(MouseEvent.CLICK,onClick);

fpr_mc.name = "fpr";

sandTrap_mc.addEventListener(MouseEvent.CLICK,onClick);

sandTrap_mc.name = "sand";

function onClick(evt:Event):void {

switch(e.target.name)

{

case "bfc":

    navigateToURL(new URLRequest("http://hodentalcompany.com/pages/syringe.html"), "_blank");

    break;

case "fpr":

    navigateToURL(new URLRequest("http://hodentalcompany.com/pages/fpr.html"), "_blank");

    break;

case "sand":

    navigateToURL(new URLRequest("http://hodentalcompany.com/pages/sand.html"). "_blank");

    break;

}

}



And got this error:

1084: Syntax error: expecting identifier before _blank.

June 21, 2009

The error is telling you exactly your problem... you have three onClick functions. You can only have one. Try something like so:

bfcSyringe_mc.addEventListener(MouseEvent.CLICK,onClickSyringe);

function onClickSyringe(evt:MouseEvent):void {

fpr_mc.addEventListener(MouseEvent.CLICK,onClickFpr);

function onClickFpr(evt:MouseEvent):void {

etc...

JustBobAuthor
Inspiring
June 22, 2009

Hello. I don't know how much patience you will have with me, but...

I replaced the action script with these lines of code to try to get the first two links working:

bfcSyringe_mc.addEventListener(MouseEvent.CLICK,onClickSyringe);

function onClickSyringe(evt:MouseEvent):void {

var targetURL:URLRequest = new URLRequest("http://hodentalcompany.com/pages/syringe.html");

    navigateToURL(targetURL, "_self");

}

fpr_mc.addEventListener(MouseEvent.CLICK,onClickFpr);

function onClickFpr(evt:MouseEvent):void {

var targetURL:URLRequest = new URLRequest("http://hodentalcompany.com/pages/fpr.html");

    navigateToURL(targetURL, "_self");

}



Did I mess up? The error I get mow is:

Line 8:

1120: Access of undefined property fpr_mc.

Ned Murphy
Legend
June 22, 2009

Don't sweat the patience side of things.

Regarding the first version... Your code looks okay, so there are generally only a few reasons it won't work at this stage.  First check to make sure that all the instance names agree with the names you use in the actionscript.  If that's okay, then you need to be sure to have the buttons in the same frame where the code is being assigned to them (different layer preferably, just same frame number).  I'll save the remaining possibility that I can think of for you to check if missing either of those two conditions might be the cause.

For Tiago's version, it has a period where a comma should be before the "_blank" in the last one.