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

Converting AS2 to AS3 and running into errors

New Here ,
Apr 30, 2014 Apr 30, 2014

I am working on a project for work and I don't have anyone to go to with this issue that would actually know. I am currently converting a clients file from AS2 to AS3 in order to run in our specific platform and template. I have gotten pretty far but I am stuck here. I am getting an "Error 1152: A conflict exists with inherited definition flash.display.MovieClip.currentLabel in namespace public. (referring to "var currentLabel:Number = 0;" And if you see any other errors below please let me know! Thank you so much for your help and time in advance. I can use anything I can get!

var labelArr:Array = ["un","deux","trois","quatre"];

var currentLabel:Number = 0;

function NEXT(event:MouseEvent):void

{

     if (currentLabel < labelArr.length - 1) {

        currentLabel++;

        gotoAndPlay(labelArr[currentLabel]);

    }

    else{

        //whatever you want .. like jump back to the the beginning

        currentLabel = 0;

         gotoAndPlay(labelArr[currentLabel]);

    }

}

next_btn.addEventListener(MouseEvent.CLICK, NEXT);

function PREV(event:MouseEvent):void

{

     if (currentLabel > 0) {

        currentLabel--;

         gotoAndPlay(labelArr[currentLabel]);

    }

    else{

        //whatever you want .. like jump to the end.

        currentLabel = labelArr.length - 1;

         gotoAndPlay(labelArr[currentLabel]);

    }

}

prev_btn.addEventListener(MouseEvent.CLICK, PREV);

TOPICS
ActionScript
330
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 ,
Apr 30, 2014 Apr 30, 2014

You can probably just rename that variable to something else to solve the error issue.  AS3 has a currentLabel property for the MovieClip class, so anything with a timeline essentially has that proiperty.  IF you rename it to something else the error should go away.

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
Explorer ,
May 01, 2014 May 01, 2014
LATEST

In addition to the currentLabel property, the AS3 MovieClip class already keeps an Array of all timeline labels for you in the currentLabels property:
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/MovieClip.html#curr...

Each item in the array is of type flash.display.FrameLabel, which has properties frame:int and name:String.

The code could be updated and reduced to this:

import flash.display.FrameLabel;

function NEXT(event:MouseEvent):void

{

    for (var i:int = 0; i < currentLabels.length; i++) //get index of current label by matching current label name

        if ((currentLabels as FrameLabel).name == currentLabel)

            break;

    if (i < currentLabels.length - 1)

        gotoAndPlay((currentLabels[i+1] as FrameLabel).frame)

    else //whatever you want .. like jump back to the the beginning

        gotoAndPlay((currentLabels[0] as FrameLabel).frame)

}

next_btn.addEventListener(MouseEvent.CLICK, NEXT);

function PREV(event:MouseEvent):void

{

    for (var i:int = 0; i < currentLabels.length; i++) //get index of current label by matching current label name

        if ((currentLabels as FrameLabel).name == currentLabel)

            break;

    if (i > 0)

        gotoAndPlay((currentLabels[i-1] as FrameLabel).frame)

    else //whatever you want .. like jump to the end.

        gotoAndPlay((currentLabels[currentLabels.length - 1] as FrameLabel).frame)

}

prev_btn.addEventListener(MouseEvent.CLICK, PREV);


Also worthy of mention is the difference between the currentLabel and currentFrameLabel properties, which are slightly different.  I've paraphrased/corrected the documentation to clarify it.


currentFrameLabel: The label, if one is present, on exactly the current frame.  If the current frame has no label, currentFrameLabel is null.

vs

currentLabel: The label, if one is present, on exactly the current frame OR, if one is not present on the current frame, the next earlier frame that happens to include a label.  currentLabel returns null only if neither the current nor any previous frames include a label.

More than likely, you want to use currentLabel to avoid null values when the playhead is on an unlabeled frame between your labeled frames.

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