New MinimalComp component: Window

To celebrate my return to the world of Flash, here’s a new component to go into the Minimal Components set:
window_comp

Quite simple, just two panels and a label, made draggable. I created a simple version for a level editor I’m working on for a game, and decided to make it a permanent fixture.

Here’s the code used to make the above scene:

[as]Component.initStage(stage);
var window1:Window = new Window(this, 100, 100, “Slider Window”);
window1.width = 200;
window1.height = 160;
for(var i:int = 0; i < 10; i++) { var slider:HSlider = new HSlider(window1.content, 10, 10 + i * 12); slider.width = 180; slider.value = Math.random() * 100; } var window2:Window = new Window(this, 150, 150, "Button Window"); window2.width = 120; window2.height = 260; for(i = 0; i < 10; i++) { var btn:PushButton = new PushButton(window2.content, 10, 10 + i * 22, "Button " + i); } var scw:SubclassedWindow = new SubclassedWindow(this, 200, 300, "Subclassed Window");[/as] See? Simple. But I like how it looks. Fits in well with the other components. As with the Panel, just remember that it's best to add subcomponents or other items to the content property, rather than the window or panel itself, as the content is masked. I suppose I could override addChild to do that for you, but... whatever. Also, you notice there that I created an instance of SubClassedWindow. That's just a class I made for this example so you can see how you might want to do that: [as]package { import com.bit101.components.RadioButton; import com.bit101.components.Window; import flash.display.DisplayObjectContainer; public class SubclassedWindow extends Window { public function SubclassedWindow(parent:DisplayObjectContainer=null, xpos:Number=0, ypos:Number=0, title:String="Window") { super(parent, xpos, ypos, title); } override protected function init() : void { super.init(); height = 180; for(var i:int = 0; i < 10; i++) { var rb:RadioButton = new RadioButton(content, 10, 10 + i * 15, "Radio " + i); } } } }[/as] Technically, I probably should have added the radio buttons in an overridden addChildren method, but init works too. Anyway, from here, you could add event listeners and other stuff to the content of the window and have it all neatly packaged up in one class. Anyway, get the source or the SWC here: http://code.google.com/p/minimalcomps/

0.97 is the current version.

This entry was posted in ActionScript, Components, Flash. Bookmark the permalink.

8 Responses to New MinimalComp component: Window

  1. Macaca says:

    Are these still code only components? I couldn’t get IDE positioniong to work.

  2. It’s nice to have a container for the comps, instead of rolling your own. How hard would it be to have a toggle button to show/hide the content, leaving only the header?

  3. kp says:

    David. Good idea. It would be very simple. In fact, it’s now checked into svn. Just set myWindow.hasMinimizeButton = true. 🙂

    Also, in svn is a draggable boolean property, which you can set to false if you want a fixed window. And the shadow property only affects the dropshadow, not the internal panel shadows.

  4. iGman says:

    I’m so happy to see you blogging about flash again. Thanks for the great component!

  5. Og2t says:

    Hey Keith, good to see that you haven’t abandoned MinimalComps! I am using it very extensively with my HiSlope framework and everything works great so far.

    Also, thanks for the hasMinimizeButton, it’s exactly what I needed for hiding the panels (need to try it out, how about drawing a triangle to indicate a state?)

    I’ve found a few bugs, ie. clear() medtod in RadioButton.as clears all radiobuttons, I think they should be grouped by panel they sit on: if (buttons[i] != rb && buttons[i].parent == rb.parent) works fine.
    I’ve also extended ColorChooser class so you can sample the color from anywhere on the stage or color palette.

    Would you be interested in merging the changes?

    Thanks, Tomek

  6. Og2t says:

    Oh sorry haven’t linked to the demo directly! Just scroll the panel on the right to see tons of components working 🙂

Leave a Reply