A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: [RESOLVED] Using Frame Labels as Variables

  1. #1
    Junior Member
    Join Date
    Mar 2010
    Posts
    16

    resolved [RESOLVED] Using Frame Labels as Variables

    I have a Flash project with several labeled frames. The user will be doing a lot of moving about those frames, so I wanted to simplify my navigational interface code-wise. There are six buttons, I have attached functions to them like so:

    Actionscript Code:
    topnavbt.addEventListener(MouseEvent.MOUSE_DOWN,lookUp);
    function lookUp(event:MouseEvent):void
    {
        gotoAndStop(FrameLabel(uparea));
    }
    ritnavbt.addEventListener(MouseEvent.MOUSE_DOWN,lookRight);
    function lookRight(event:MouseEvent):void
    {
        gotoAndStop(FrameLabel(rightarea));
       
    }
    botnavbt.addEventListener(MouseEvent.MOUSE_DOWN,lookDown);
    function lookDown(event:MouseEvent):void
    {
        gotoAndStop(FrameLabel(downarea));
       
    }
    lftnavbt.addEventListener(MouseEvent.MOUSE_DOWN,lookLeft);
    function lookLeft(event:MouseEvent):void
    {
        gotoAndStop(FrameLabel(leftarea));
       
    }
    fornavbt.addEventListener(MouseEvent.MOUSE_DOWN,walkForward);
    function walkForward(event:MouseEvent):void
    {
        gotoAndStop(FrameLabel(forwardarea));
    }
    baknavbt.addEventListener(MouseEvent.MOUSE_DOWN,walkBack);
    function walkBack(event:MouseEvent):void

    {
        gotoAndStop(FrameLabel(backarea));
       
    }

    So then I needed to define variables on the first frame that hold the frame label data:

    Code:
    var uparea: FrameLabel;
    var downarea: FrameLabel;
    var leftarea: FrameLabel;
    var rightarea: FrameLabel;
    var forwardarea: FrameLabel;
    var backarea: FrameLabel;
    Now, on each frame, I want to define which frames (or frame labels in this case) are around the user's current position. I tried this:

    Actionscript Code:
    uparea = 'skylights';
    downarea = 'frontdoor';
    leftarea = 'leftdoor';
    rightarea = 'rightdoor';
    //There is no forwardarea, the button won't be there on this frame anyway
    //There is no backarea, the button won't be there on this frame anyway

    However, Flash tells me "1067: Implicit coercion of a value of type String to an unrelated type flash.display:FrameLabel."

    If I try to use:
    Actionscript Code:
    uparea = FrameLabel('skylights');
    downarea = FrameLabel('frontdoor');
    leftarea = FrameLabel('leftdoor');
    rightarea = FrameLabel('rightdoor');
    //There is no forwardarea, the button won't be there on this frame anyway
    //There is no backarea, the button won't be there on this frame anyway

    ...instead, I get "TypeError: Error #1034: Type Coercion failed: cannot convert "skylights" to flash.display.FrameLabel."

    I can't seem to wrap my head around what these errors are saying, but I'm sure there's a simple solution I'm missing. I think I just don't know how to define the frame label correctly. Any help would be appreciated.

  2. #2
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    From looking at the docs, it looks like you cannot create an instance of a FrameLabel. They are returned in the labels property of a Scene object. But you don't need FrameLabels anyway. Just use the strings.

  3. #3
    Junior Member
    Join Date
    Mar 2010
    Posts
    16
    Huh, so that's weird, I assumed you'd have to convert it to a frame label, but using just a string works. I don't know WHY it works, but it does. XD Thanks.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center