views:

1391

answers:

3

Are there any good resources for starting Flex 3 UI programming in ActionScript? I am having some issues with the following if anyone has any ideas. It gets the right size, but my buttons are not showing up. Anyone have any ideas?

package 
{
    import flash.display.*;

    import mx.controls.Button;
    import mx.controls.TileList;
    import mx.controls.sliderClasses.Slider;
    import mx.controls.ProgressBar;

    import flash.net.FileReferenceList;

    [SWF(width="720", height="480", backgroundColor="#ffffff", framerate="30")]

    public class PhotoUploader extends Sprite
    {
     var AddPhotosButton:Button;
     var RemovePhotoButton:Button;
     var UploadPhotosButton:Button;

     public function PhotoUploader():void
     {
      stage.scaleMode = StageScaleMode.NO_SCALE;
      stage.align = StageAlign.TOP_LEFT;

      AddPhotosButton = new Button();
      AddPhotosButton.x = 10;
      AddPhotosButton.y = 10;
      AddPhotosButton.width = 100;
      AddPhotosButton.height = 20;

      RemovePhotoButton = new Button();
      UploadPhotosButton = new Button();

      addChild(AddPhotosButton);
      addChild(RemovePhotoButton);
      addChild(UploadPhotosButton);
     }
    }
}
+1  A: 

For a true Flex application, I think you need to start with a top level mx.core.Application (often defined in MXML rather than ActionScript), to which you would add mx.core.UIComponents. I think your PhotoUploader would be a good example of a custom UIComponent.

The Flex help/tutorial pages are quite good. I'd recommend starting there. Custom components are covered explicitly, but you might want to start earlier in the stream.

Michael Brewer-Davis
A: 
facildelembrar
The import statements are perfectly valid for flex components. The components you are talking about are flash components, not flex
James Hay
What is wrong with importing the entire display package? There is no performance overhead (compile time or runtime) and it will only cause an issue if there is a naming conflict.
Richard Szalay
A: 

Try overriding your component's createChildren() method (don't forget to call super.createChildren() inside of it) and moving the three calls to addChild() to it. Don't call your own createChildren method; the Flex framework will ensure that it is called when your component is added to the display list.

Writing a component in MXML spares you from having to know a lot about the Flex Component Lifecycle, because mxmlc will generate the proper AS3 source code for you, but when you want to write your custom component in AS3 yourself, you really need to become familiar with it.

erikprice