简体   繁体   中英

Add mx.controls.Button to Flash Professional CS6 document

I'm using Flash Professional CS6. It allows adding SWC files of Flex SDK. What I'm trying to do is adding the mx.controls.Button to stage. The code runs well, but the button doesn't appear on stage. Am I doing anything wrong in this code:

//f9 to open action editor
//in scene 1:
import mx.controls.Button;

var b:Button = new Button();
b.label = "My button";
b.width = 100;
b.height = 30; 
b.visible = true;

stage.addChild(b);

The [mx.controls] package contains controls for use in Flex / FlashBuilder. The fl.controls package contains similar, but not necessarily equivalent, controls for use in the Flash IDE. If you just want to use a button, you should do what @Moorthy says and drag the button from the components library, then reference fl.controls.Button .

If you absolutely have to use Flex components in Flash, it is possible, you can do it like this:

  1. Load the Flex swf into your flash
  2. Wait until the loaded Flex component reaches frames 2 (all Flex swf's have 2 frames indeed)
  3. Add the eventlistener (for the event defined in the flex) on the application property of the loaded object. This property is actually a property of the SystemManager class. Remeber the SystemManager class does not exist in Flash. It's a Flex thing.

It's worth saying that this makes sense for advanced Flex components, where you don't want to recode a lot of complex behaviour, but it is hard to imagine why you would need mx.controls.Buttton instead of fl.controls.Button , or your own MovieClip , as the behaviour is really quite common and straightforward.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM