-
1. Re: Converting AS2 to AS3 and running into errors
Ned Murphy Apr 30, 2014 6:48 PM (in response to melaniesamazing)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.
-
2. Re: Converting AS2 to AS3 and running into errors
James22s22 May 1, 2014 2:15 PM (in response to melaniesamazing)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#currentLabelsEach 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[i] 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[i] 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.



