Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

duplicate function error message

New Here ,
May 07, 2015 May 07, 2015

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);

TOPICS
ActionScript
274
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 07, 2015 May 07, 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. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 07, 2015 May 07, 2015

Thank You. That did it. ☺

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 07, 2015 May 07, 2015

You're welcome

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 08, 2015 May 08, 2015

Would it be alright to ask a follow on question, here in this email?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 08, 2015 May 08, 2015

It is better if you post in the forums where you can mark helpful/correct answers.  But you can certainly ask here if the new question relates to the original issue.  If it is different you should start a new posting.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 08, 2015 May 08, 2015
LATEST

It relates but I will go ahead and post it on the forum in case others have the same issue. Thank you for your help.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines