views:

221

answers:

2

I am using the Flex SDK within visual studio and trying to dynamically add a button to the stage. Here is a quick example of what I am doing.

public class Test extends Sprite
{      
 public function Test()
 {
  init();     
 }                                                    

 private function init():void
 {

  var btnBrowse:Button = new Button();          
  btnBrowse.label = "Browse";
  btnBrowse.x = 0;
  btnBrowse.y = 0;
  btnBrowse.width=100;
  btnBrowse.height=100;   
  addChild(btnBrowse);
 }
}

Nothing seems to show up and the screen is still empty. I am importing mx.controls.* for the button. Could that create an issue since I am not using mxml only as3?

+1  A: 

You can't use Flex framework controls in an AS3 Only project. If you are trying to avoid MXML then just create a new Flex Project where the root tag is like:

<FooApplication xmlns="*"/>

And create a new AS3 Class like:

package {

import mx.core.Application;

public class FooApplication extends Application {

// now override something like createChildren to add a button.

}
}
James Ward
If I understand you right then my options for as3 only are I have to either create a sprite and draw my own button or create the controls in flash and export a .swc.
Mike
There are many ways to create buttons with AS3 only. But most are painful - thus the reason that most people just use Flex. There are some lightweight AS3 only frameworks out there that you could also look into like Reflex.
James Ward
A: 

Try changing the base class from Sprite to Canvas.

susichan