jondinham
jondinham

Reputation: 8511

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);

Upvotes: 0

Views: 2436

Answers (1)

Jude Fisher
Jude Fisher

Reputation: 11294

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.

Upvotes: 1

Related Questions