AS3 Error: '1172: Definition fl.controls:Button could not be found.'

余生颓废 提交于 2020-01-13 11:50:52

问题


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.


回答1:


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.




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/2113575/as3-error-1172-definition-fl-controlsbutton-could-not-be-found

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!