Skip to main content
annetteMymic
Participant
May 7, 2015
Question

duplicate function error message

  • May 7, 2015
  • 6 replies
  • 311 views

I am trying to create a game in which the user chooses between three images, then drags and drops that image to a set location at which point a second image loads from the library right underneath the first image.  Each image that is drag and dropped has a different image associated with it.  I got the code to work for the first image but the second and third I get a duplicate function error message.  Can anyone help?  Here is the code I am using.  Thanks in advance.

var offset:int = 50;

var artillery_mcStartX:int = 610;

var artillery_mcStartY:int = 105;

var artillery_mcEndX:int = 260.85;

var artillery_mcEndY:int = 151.45;

  artillery_mc.buttonMode = true;

  artillery_mc.addEventListener(MouseEvent.MOUSE_DOWN, startDragging);

  artillery_mc.addEventListener(MouseEvent.MOUSE_UP, stopDragging);

var tomahawk_mcStartX:int = 731;

var tomahawk_mcStartY:int = 105;

var tomahawk_mcEndX:int = 371.05;

var tomahawk_mcEndY:int = 151.45;

tomahawk_mc.buttonMode = true;

tomahawk_mc.addEventListener(MouseEvent.MOUSE_DOWN, startDragging);

tomahawk_mc.addEventListener(MouseEvent.MOUSE_UP, stopDragging);

  

var f16_mcStartX:int = 851.95;

var f16_mcStartY:int = 105;

var f16_mcEndX:int = 483;

var f16_mcEndY:int = 151.45

  f16_mc.buttonMode = true;

  f16_mc.addEventListener(MouseEvent.MOUSE_DOWN, startDragging);

  f16_mc.addEventListener(MouseEvent.MOUSE_UP, stopDragging);

  

function startDragging(e: MouseEvent):void {

    e.currentTarget.startDrag();

}

function stopDragging(e: MouseEvent):void {

    e.currentTarget.stopDrag();

    switch (e.currentTarget) {

        case artillery_mc:

        if (artillery_mc.x < artillery_mcEndX - offset || artillery_mc.x > artillery_mcEndX + offset || artillery_mc.y < artillery_mcEndY - offset || artillery_mc.y > artillery_mcEndY + offset) {

            artillery_mc.x = artillery_mcStartX;

            artillery_mc.y = artillery_mcStartY;

        } else {

            artillery_mc.x = artillery_mcEndX;

            artillery_mc.y = artillery_mcEndY;

            checkGame();

        }

        break;

case tomahawk_mc:

        if (tomahawk_mc.x < tomahawk_mcEndX - offset || tomahawk_mc.x > tomahawk_mcEndX + offset || tomahawk_mc.y < tomahawk_mcEndY - offset || tomahawk_mc.y > tomahawk_mcEndY + offset) {

            tomahawk_mc.x = tomahawk_mcStartX;

            tomahawk_mc.y = tomahawk_mcStartY;

        } else {

            tomahawk_mc.x = tomahawk_mcEndX;

            tomahawk_mc.y = tomahawk_mcEndY;

            checkGame();

        }

        break;

case f16_mc:

        if (f16_mc.x < f16_mcEndX - offset || f16_mc.x > f16_mcEndX + offset || f16_mc.y < f16_mcEndY - offset || f16_mc.y > f16_mcEndY + offset) {

            f16_mc.x = f16_mcStartX;

            f16_mc.y = f16_mcStartY;

        } else {

            f16_mc.x = f16_mcEndX;

            f16_mc.y = f16_mcEndY;

            checkGame();

        }

       

}

}

function checkGame():void {

}   

artillery_mc.addEventListener(MouseEvent.CLICK, fl_ClickToLoadImageFromLibrary);

       

function fl_ClickToLoadImageFromLibrary(event:MouseEvent):void

{

    // If you want to add a different image from the library,

    // enter a different name in the Class text field at step 4 above and in the code below.

    var libImage:laptop = new laptop();

    var holder:Bitmap = new Bitmap(libImage);

    holder.x = 226;

    holder.y = 210;

    addChild(holder);

}

tomahawk_mc.addEventListener(MouseEvent.CLICK, fl_ClickToLoadImageFromLibrary);

       

function fl_ClickToLoadImageFromLibrary(event:MouseEvent):void

{

    // If you want to add a different image from the library,

    // enter a different name in the Class text field at step 4 above and in the code below.

    var libImage:missile = new missile();

    var holder:Bitmap = new Bitmap(libImage);

    holder.x = 226;

    holder.y = 210;

    addChild(holder);

}

   

   

    f16_mc.addEventListener(MouseEvent.CLICK, fl_ClickToLoadImageFromLibrary);

       

function fl_ClickToLoadImageFromLibrary(event:MouseEvent):void

{

    // If you want to add a different image from the library,

    // enter a different name in the Class text field at step 4 above and in the code below.

    var libImage:radio = new radio();

    var holder:Bitmap = new Bitmap(libImage);

    holder.x = 226;

    holder.y = 210;

    addChild(holder);

This topic is closed to new replies. Start a new post to keep the conversation going.

6 replies

Ned Murphy
Legend
May 7, 2015

If you look at your code at the end you will see that you have three different functions that use the same name.  You cannot do that (which should the program choose???)   You will have to rename them so that they are all different. 

annetteMymic
Participant
May 7, 2015

Thank You. That did it. ☺

Ned Murphy
Legend
May 7, 2015

You're welcome