Star Orbit Demo
Flash 3D demo about objects orbiting stars
Flash 3D demo about objects orbiting stars
/**
* Panel.as
* Keith Peters
* version 0.97
*
* A rectangular panel. Can be used as a container for other components.
*
* Copyright (c) 2009 Keith Peters
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.bit101.components
{
import flash.display.DisplayObjectContainer;
import flash.display.Shape;
import flash.display.Sprite;
public class Panel extends Component
{
private var _mask:Sprite;
private var _background:Shape;
private var _color:int = -1;
private var _shadow:Boolean = true;
/**
* Container for content added to this panel. This is masked, so best to add children to content, rather than directly to the panel.
*/
public var content:Sprite;
/**
* Constructor
* @param parent The parent DisplayObjectContainer on which to add this Panel.
* @param xpos The x position to place this component.
* @param ypos The y position to place this component.
*/
public function Panel(parent:DisplayObjectContainer = null, xpos:Number = 0, ypos:Number = 0)
{
super(parent, xpos, ypos);
}
/**
* Initializes the component.
*/
override protected function init():void
{
super.init();
setSize(100, 100);
}
/**
* Creates and adds the child display objects of this component.
*/
override protected function addChildren():void
{
_background = new Shape();
addChild(_background);
_mask = new Sprite();
_mask.mouseEnabled = false;
addChild(_mask);
content = new Sprite();
addChild(content);
content.mask = _mask;
filters = [getShadow(2, true)];
}
///////////////////////////////////
// public methods
///////////////////////////////////
/**
* Draws the visual ui of the component.
*/
override public function draw():void
{
super.draw();
_background.graphics.clear();
if(_color == -1)
{
_background.graphics.beginFill(Style.PANEL);
}
else
{
_background.graphics.beginFill(_color);
}
_background.graphics.drawRect(0, 0, _width, _height);
_background.graphics.endFill();
_mask.graphics.clear();
_mask.graphics.beginFill(0xff0000);
_mask.graphics.drawRect(0, 0, _width, _height);
_mask.graphics.endFill();
}
///////////////////////////////////
// event handlers
///////////////////////////////////
///////////////////////////////////
// getter/setters
///////////////////////////////////
/**
* Gets / sets whether or not this Panel will have an inner shadow.
*/
public function set shadow(b:Boolean):void
{
_shadow = b;
if(_shadow)
{
filters = [getShadow(2, true)];
}
else
{
filters = [];
}
}
public function get shadow():Boolean
{
return _shadow;
}
/**
* Gets / sets the backgrond color of this panel.
*/
public function set color(c:int):void
{
_color = c;
invalidate();
}
public function get color():int
{
return _color;
}
}
}