4

I am trying to create a class called LinkButton, which is a simple class that loads a URL on a click (im doing this to simpify my designers' transition to AS3). Even though I am importing the button definition, the AS file gets a compile error: 1046: Type was not found or was not a compile-time constant: Button. and 1172: Definition fl.controls:Button could not be found. I created the button by making a simple shape converting it to a symbol (F8) of type 'Button'. In my FLA file i have this code:

import AS3classes.mouse.LinkButton;
var link1:LinkButton = new LinkButton(testLink, "http://www.example.com");

Simple right? In my AS file I am importing the button definition, declaring the constructor and 'linkTo' Behaviour. Here is my code in the AS file:

package AS3classes.mouse
{
 import fl.controls.Button;
 import flash.events.*;
    import flash.net.*;

 public class LinkButton 
 {
  private var _pageURL:String;
  private var _button:Button;

  public function LinkButton(button, pageURL) : void
  {
   _button = button;
   _pageURL = pageURL;
   _button.addEventListener(MouseEvent.MOUSE_UP, LinkTo);
  }

  private function LinkTo(e:Event) : void
  {
   var request:URLRequest = new URLRequest(_pageURL);
  }
 }
}

When I Google this, I see people getting this error because they don't have a button in their library. I do have a button I created from a simple shape. Am I importing the right definition? I have no problem importing the movieClip definition in a different script with the same method. I don't understand the difference, and I'm pretty sure I'm not stupid.

3 Answers 3

6

You are using the wrong type of button. As you describe it, you want

flash.display.SimpleButton

fl.controls.Button is a Button component, not a button defined in the library. Make sense? Try importing flash.display.SimpleButton and setting _button to be a SimpleButton instead.

1
  • THANK YOU!! This is the exact info I needed. Jan 21, 2010 at 23:26
6

You need to go to the "Components" window and drag a "Button" onto your "Library" window.

To use the component, simply import it using the import fl.controls.Button; instruction. You can now use the "Button" with its label and so on.

0

Matt Dales - is right. I just now had the exact problem. The "Button" fooled me. In ctrl+f7 = components panel, I looked in the Video group and tried a button from there. Doesn't work as a "Button". Look in the "User Interface" group. Get the "Button" from there and drag into the Library. Then fl.controls.Button and Button() work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.