package aerys.minko.type
{
	public final class Signal
	{
		private var _name			: String	= null;

		private var _callbacks		: Array		= [];
		private var _numCallbacks	: uint		= 0;

		private var _executed		: Boolean	= false;
		private var _numAdded		: uint		= 0;
		private var _toAdd			: Array		= null;
		private var _numRemoved		: uint		= 0;
		private var _toRemove		: Array		= null;

		public function get numCallbacks() : uint
		{
			return _numCallbacks;
		}

		public function Signal(name : String)
		{
			_name = name;
		}

		public function add(callback : Function) : void
		{
            if (_callbacks.indexOf(callback) >= 0)
                throw new Error('The same callback cannot be added twice.');

			if (_executed)
			{
				if (_toAdd)
					_toAdd.push(callback);
				else
					_toAdd = [callback];
				++_numAdded;

				return ;
			}

			_callbacks[_numCallbacks] = callback;
			++_numCallbacks;
		}

		public function remove(callback : Function) : void
		{
			var index : int = _callbacks.indexOf(callback);

			if (index < 0)
				throw new Error('This callback does not exist.');

			if (_executed)
			{
				if (_toRemove)
					_toRemove.push(callback);
				else
					_toRemove = [callback];
				++_numRemoved;

				return ;
			}

			--_numCallbacks;
			_callbacks[index] = _callbacks[_numCallbacks];
			_callbacks.length = _numCallbacks;
		}

		public function hasCallback(callback : Function) : Boolean
		{
			return _callbacks.indexOf(callback) >= 0;
		}

		public function execute(...params) : void
		{
			if (_numCallbacks)
			{
				_executed = true;
				for (var i : uint = 0; i < _numCallbacks; ++i)
					(_callbacks[i] as Function).apply(null, params);
				_executed = false;

				for (i = 0; i < _numAdded; ++i)
					add(_toAdd[i]);
				_numAdded = 0;
				_toAdd = null;

				for (i = 0; i < _numRemoved; ++i)
					remove(_toRemove[i]);
				_numRemoved = 0;
				_toRemove = null;
			}
		}
	}
}

package aerys.minko.type
{
	public final class Signal
	{
		private var _name			: String;

		private var _callbacks		: Vector.<Function>;
		private var _numCallbacks	: uint;

		private var _executed		: Boolean;
		private var _numAdded		: uint;
		private var _toAdd			: Vector.<Function>;
		private var _numRemoved		: uint;
		private var _toRemove		: Vector.<Function>;

		public function get numCallbacks() : uint
		{
			return _numCallbacks;
		}

		public function Signal(name : String)
		{
			_name = name;
            _callbacks = new <Function>[];
		}

		public function add(callback : Function) : void
		{
            if (_callbacks.indexOf(callback) >= 0)
                throw new Error('The same callback cannot be added twice.');

			if (_executed)
			{
				if (_toAdd)
					_toAdd.push(callback);
				else
					_toAdd = new <Function>[callback];
				++_numAdded;

				return ;
			}

			_callbacks[_numCallbacks] = callback;
			++_numCallbacks;
		}

		public function remove(callback : Function) : void
		{
			var index : int = _callbacks.indexOf(callback);

			if (index < 0)
				throw new Error('This callback does not exist.');

			if (_executed)
			{
				if (_toRemove)
					_toRemove.push(callback);
				else
					_toRemove = new <Function>[callback];
				++_numRemoved;

				return ;
			}

			--_numCallbacks;
			_callbacks[index] = _callbacks[_numCallbacks];
			_callbacks.length = _numCallbacks;
		}

		public function hasCallback(callback : Function) : Boolean
		{
			return _callbacks.indexOf(callback) >= 0;
		}

		public function execute(...params) : void
		{
			if (_numCallbacks)
			{
				_executed = true;
				for (var i : uint = 0; i < _numCallbacks; ++i)
					_callbacks[i].apply(null, params);
				_executed = false;

				for (i = 0; i < _numAdded; ++i)
					add(_toAdd[i]);
				_numAdded = 0;
				_toAdd = null;

				for (i = 0; i < _numRemoved; ++i)
					remove(_toRemove[i]);
				_numRemoved = 0;
				_toRemove = null;
			}
		}
	}
}

use Vector.<Function> instead of Array in Signal to get a ~10% performance boost


////////////////////////////////////////////////////////////////////////////////
//
//  Licensed to the Apache Software Foundation (ASF) under one or more
//  contributor license agreements.  See the NOTICE file distributed with
//  this work for additional information regarding copyright ownership.
//  The ASF licenses this file to You under the Apache License, Version 2.0
//  (the "License"); you may not use this file except in compliance with
//  the License.  You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
//  Unless required by applicable law or agreed to in writing, software
//  distributed under the License is distributed on an "AS IS" BASIS,
//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//  See the License for the specific language governing permissions and
//  limitations under the License.
//
////////////////////////////////////////////////////////////////////////////////
package org.apache.flex.core
{
    import flash.display.DisplayObject;
    import flash.display.Sprite;
    import flash.display.StageAlign;
    import flash.display.StageQuality;
    import flash.display.StageScaleMode;
    import flash.events.Event;
    import flash.events.IOErrorEvent;
    import flash.events.MouseEvent;
    import flash.system.ApplicationDomain;
    import flash.utils.getQualifiedClassName;

    import org.apache.flex.events.Event;
    import org.apache.flex.events.IEventDispatcher;
    import org.apache.flex.events.MouseEvent;
    import org.apache.flex.events.utils.MouseEventConverter;
    import org.apache.flex.utils.MXMLDataInterpreter;

    //--------------------------------------
    //  Events
    //--------------------------------------

    /**
     *  Dispatched at startup. Attributes and sub-instances of
     *  the MXML document have been created and assigned.
     *  The component lifecycle is different
     *  than the Flex SDK.  There is no creationComplete event.
     *
     *  @langversion 3.0
     *  @playerversion Flash 10.2
     *  @playerversion AIR 2.6
     *  @productversion FlexJS 0.0
     */
    [Event(name="initialize", type="org.apache.flex.events.Event")]

    /**
     *  Dispatched at startup after the initial view has been
     *  put on the display list.
     *
     *  @langversion 3.0
     *  @playerversion Flash 10.2
     *  @playerversion AIR 2.6
     *  @productversion FlexJS 0.0
     */
    [Event(name="viewChanged", type="org.apache.flex.events.Event")]

    /**
     *  Dispatched at startup after the initial view has been
     *  put on the display list.
     *
     *  @langversion 3.0
     *  @playerversion Flash 10.2
     *  @playerversion AIR 2.6
     *  @productversion FlexJS 0.0
     */
    [Event(name="applicationComplete", type="org.apache.flex.events.Event")]

    /**
     *  The Application class is the main class and entry point for a FlexJS
     *  application.  This Application class is different than the
     *  Flex SDK's mx:Application or spark:Application in that it does not contain
     *  user interface elements.  Those UI elements go in the views.  This
     *  Application class expects there to be a main model, a controller, and
     *  an initial view.
     *
     *  @langversion 3.0
     *  @playerversion Flash 10.2
     *  @playerversion AIR 2.6
     *  @productversion FlexJS 0.0
     */
    public class Application extends Sprite implements IStrand, IFlexInfo, IParent, IEventDispatcher
    {
        /**
         *  Constructor.
         *
         *  @langversion 3.0
         *  @playerversion Flash 10.2
         *  @playerversion AIR 2.6
         *  @productversion FlexJS 0.0
         */
        public function Application()
        {
            super();
			if (stage)
			{
				stage.align = StageAlign.TOP_LEFT;
				stage.scaleMode = StageScaleMode.NO_SCALE;
                // should be opt-in
				//stage.quality = StageQuality.HIGH_16X16_LINEAR;
			}

            loaderInfo.addEventListener(flash.events.Event.INIT, initHandler);
        }

        /**
         *  The document property is used to provide
         *  a property lookup context for non-display objects.
         *  For Application, it points to itself.
         *
         *  @langversion 3.0
         *  @playerversion Flash 10.2
         *  @playerversion AIR 2.6
         *  @productversion FlexJS 0.0
         */
        public var document:Object = this;

        private function initHandler(event:flash.events.Event):void
        {
			if (model is IBead) addBead(model as IBead);
			if (controller is IBead) addBead(controller as IBead);

            MouseEventConverter.setupAllConverters(stage);

            for each (var bead:IBead in beads)
                addBead(bead);

            dispatchEvent(new org.apache.flex.events.Event("beadsAdded"));

            MXMLDataInterpreter.generateMXMLInstances(this, null, MXMLDescriptor);

            dispatchEvent(new org.apache.flex.events.Event("initialize"));

            if (initialView)
            {
                initialView.applicationModel =  model;
                if (isNaN(initialView.explicitWidth))
                    initialView.setWidth(stage.stageWidth);
                if (isNaN(initialView.explicitHeight))
                    initialView.setHeight(stage.stageHeight);
        	    this.addElement(initialView);
                var bgColor:Object = ValuesManager.valuesImpl.getValue(this, "background-color");
                if (bgColor != null)
                {
                    var backgroundColor:uint = ValuesManager.valuesImpl.convertColor(bgColor);
                    graphics.beginFill(backgroundColor);
                    graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight);
                    graphics.endFill();
                }
                dispatchEvent(new org.apache.flex.events.Event("viewChanged"));
            }
            dispatchEvent(new org.apache.flex.events.Event("applicationComplete"));
        }

        /**
         *  The org.apache.flex.core.IValuesImpl that will
         *  determine the default values and other values
         *  for the application.  The most common choice
         *  is org.apache.flex.core.SimpleCSSValuesImpl.
         *
         *  @see org.apache.flex.core.SimpleCSSValuesImpl
         *
         *  @langversion 3.0
         *  @playerversion Flash 10.2
         *  @playerversion AIR 2.6
         *  @productversion FlexJS 0.0
         */
        public function set valuesImpl(value:IValuesImpl):void
        {
            ValuesManager.valuesImpl = value;
            ValuesManager.valuesImpl.init(this);
        }

        /**
         *  The initial view.
         *
         *  @see org.apache.flex.core.ViewBase
         *
         *  @langversion 3.0
         *  @playerversion Flash 10.2
         *  @playerversion AIR 2.6
         *  @productversion FlexJS 0.0
         */
        public var initialView:ViewBase;

        /**
         *  The data model (for the initial view).
         *
         *  @langversion 3.0
         *  @playerversion Flash 10.2
         *  @playerversion AIR 2.6
         *  @productversion FlexJS 0.0
         */
        public var model:Object;

        /**
         *  The controller.  The controller typically watches
         *  the UI for events and updates the model accordingly.
         *
         *  @langversion 3.0
         *  @playerversion Flash 10.2
         *  @playerversion AIR 2.6
         *  @productversion FlexJS 0.0
         */
        public var controller:Object;

        /**
         *  An array of data that describes the MXML attributes
         *  and tags in an MXML document.  This data is usually
         *  decoded by an MXMLDataInterpreter
         *
         *  @see org.apache.flex.utils.MXMLDataInterpreter
         *
         *  @langversion 3.0
         *  @playerversion Flash 10.2
         *  @playerversion AIR 2.6
         *  @productversion FlexJS 0.0
         */
        public function get MXMLDescriptor():Array
        {
            return null;
        }

        /**
         *  An method called by the compiler's generated
         *  code to kick off the setting of MXML attribute
         *  values and instantiation of child tags.
         *
         *  The call has to be made in the generated code
         *  in order to ensure that the constructors have
         *  completed first.
         *
         *  @param data The encoded data representing the
         *  MXML attributes.
         *
         *  @see org.apache.flex.utils.MXMLDataInterpreter
         *
         *  @langversion 3.0
         *  @playerversion Flash 10.2
         *  @playerversion AIR 2.6
         *  @productversion FlexJS 0.0
         */
    	public function generateMXMLAttributes(data:Array):void
        {
			MXMLDataInterpreter.generateMXMLProperties(this, data);
        }

        /**
         *  The array property that is used to add additional
         *  beads to an MXML tag.  From ActionScript, just
         *  call addBead directly.
         *
         *  @langversion 3.0
         *  @playerversion Flash 10.2
         *  @playerversion AIR 2.6
         *  @productversion FlexJS 0.0
         */
        public var beads:Array;

        private var _beads:Vector.<IBead>;

        /**
         *  @copy org.apache.flex.core.IStrand#addBead()
         *
         *  @langversion 3.0
         *  @playerversion Flash 10.2
         *  @playerversion AIR 2.6
         *  @productversion FlexJS 0.0
         */
        public function addBead(bead:IBead):void
        {
            if (!_beads)
                _beads = new Vector.<IBead>;
            _beads.push(bead);
            bead.strand = this;
        }

        /**
         *  @copy org.apache.flex.core.IStrand#getBeadByType()
         *
         *  @langversion 3.0
         *  @playerversion Flash 10.2
         *  @playerversion AIR 2.6
         *  @productversion FlexJS 0.0
         */
        public function getBeadByType(classOrInterface:Class):IBead
        {
            for each (var bead:IBead in _beads)
            {
                if (bead is classOrInterface)
                    return bead;
            }
            return null;
        }

        /**
         *  @copy org.apache.flex.core.IStrand#removeBead()
         *
         *  @langversion 3.0
         *  @playerversion Flash 10.2
         *  @playerversion AIR 2.6
         *  @productversion FlexJS 0.0
         */
        public function removeBead(value:IBead):IBead
        {
            var n:int = _beads.length;
            for (var i:int = 0; i < n; i++)
            {
                var bead:IBead = _beads[i];
                if (bead == value)
                {
                    _beads.splice(i, 1);
                    return bead;
                }
            }
            return null;
        }

        private var _info:Object;

        /**
         *  An Object containing information generated
         *  by the compiler that is useful at startup time.
         *
         *  @langversion 3.0
         *  @playerversion Flash 10.2
         *  @playerversion AIR 2.6
         *  @productversion FlexJS 0.0
         */
        public function info():Object
        {
            if (!_info)
            {
                var mainClassName:String = getQualifiedClassName(this);
                var initClassName:String = "_" + mainClassName + "_FlexInit";
                var c:Class = ApplicationDomain.currentDomain.getDefinition(initClassName) as Class;
                _info = c.info();
            }
            return _info;
        }

        /**
         *  @copy org.apache.flex.core.IParent#addElement()
         *
         *  @langversion 3.0
         *  @playerversion Flash 10.2
         *  @playerversion AIR 2.6
         *  @productversion FlexJS 0.0
         */
        public function addElement(c:Object, dispatchEvent:Boolean = true):void
        {
            if (c is IUIBase)
            {
                addChild(IUIBase(c).element as DisplayObject);
                IUIBase(c).addedToParent();
            }
            else
                addChild(c as DisplayObject);
        }

        /**
         *  @copy org.apache.flex.core.IParent#addElementAt()
         *
         *  @langversion 3.0
         *  @playerversion Flash 10.2
         *  @playerversion AIR 2.6
         *  @productversion FlexJS 0.0
         */
        public function addElementAt(c:Object, index:int, dispatchEvent:Boolean = true):void
        {
            if (c is IUIBase)
            {
                addChildAt(IUIBase(c).element as DisplayObject, index);
                IUIBase(c).addedToParent();
            }
            else
                addChildAt(c as DisplayObject, index);
        }

        /**
         *  @copy org.apache.flex.core.IParent#getElementAt()
         *
         *  @langversion 3.0
         *  @playerversion Flash 10.2
         *  @playerversion AIR 2.6
         *  @productversion FlexJS 0.0
         */
        public function getElementAt(index:int):Object
        {
            return getChildAt(index);
        }

        /**
         *  @copy org.apache.flex.core.IParent#getElementIndex()
         *
         *  @langversion 3.0
         *  @playerversion Flash 10.2
         *  @playerversion AIR 2.6
         *  @productversion FlexJS 0.0
         */
        public function getElementIndex(c:Object):int
        {
            if (c is IUIBase)
                return getChildIndex(IUIBase(c).element as DisplayObject);

            return getChildIndex(c as DisplayObject);
        }

        /**
         *  @copy org.apache.flex.core.IParent#removeElement()
         *
         *  @langversion 3.0
         *  @playerversion Flash 10.2
         *  @playerversion AIR 2.6
         *  @productversion FlexJS 0.0
         */
        public function removeElement(c:Object, dispatchEvent:Boolean = true):void
        {
            if (c is IUIBase)
            {
                removeChild(IUIBase(c).element as DisplayObject);
            }
            else
                removeChild(c as DisplayObject);
        }

        /**
         *  @copy org.apache.flex.core.IParent#numElements
         *
         *  @langversion 3.0
         *  @playerversion Flash 10.2
         *  @playerversion AIR 2.6
         *  @productversion FlexJS 0.0
         */
        public function get numElements():int
        {
            return numChildren;
        }
    }
}

////////////////////////////////////////////////////////////////////////////////
//
//  Licensed to the Apache Software Foundation (ASF) under one or more
//  contributor license agreements.  See the NOTICE file distributed with
//  this work for additional information regarding copyright ownership.
//  The ASF licenses this file to You under the Apache License, Version 2.0
//  (the "License"); you may not use this file except in compliance with
//  the License.  You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
//  Unless required by applicable law or agreed to in writing, software
//  distributed under the License is distributed on an "AS IS" BASIS,
//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//  See the License for the specific language governing permissions and
//  limitations under the License.
//
////////////////////////////////////////////////////////////////////////////////
package org.apache.flex.core
{
    import flash.display.DisplayObject;
    import flash.display.Sprite;
    import flash.display.StageAlign;
    import flash.display.StageQuality;
    import flash.display.StageScaleMode;
    import flash.events.Event;
    import flash.events.IOErrorEvent;
    import flash.events.MouseEvent;
    import flash.system.ApplicationDomain;
    import flash.utils.getQualifiedClassName;

    import org.apache.flex.events.Event;
    import org.apache.flex.events.IEventDispatcher;
    import org.apache.flex.events.MouseEvent;
    import org.apache.flex.events.utils.MouseEventConverter;
    import org.apache.flex.utils.MXMLDataInterpreter;

    //--------------------------------------
    //  Events
    //--------------------------------------

    /**
     *  Dispatched at startup. Attributes and sub-instances of
     *  the MXML document have been created and assigned.
     *  The component lifecycle is different
     *  than the Flex SDK.  There is no creationComplete event.
     *
     *  @langversion 3.0
     *  @playerversion Flash 10.2
     *  @playerversion AIR 2.6
     *  @productversion FlexJS 0.0
     */
    [Event(name="initialize", type="org.apache.flex.events.Event")]

    /**
     *  Dispatched at startup after the initial view has been
     *  put on the display list.
     *
     *  @langversion 3.0
     *  @playerversion Flash 10.2
     *  @playerversion AIR 2.6
     *  @productversion FlexJS 0.0
     */
    [Event(name="viewChanged", type="org.apache.flex.events.Event")]

    /**
     *  Dispatched at startup after the initial view has been
     *  put on the display list.
     *
     *  @langversion 3.0
     *  @playerversion Flash 10.2
     *  @playerversion AIR 2.6
     *  @productversion FlexJS 0.0
     */
    [Event(name="applicationComplete", type="org.apache.flex.events.Event")]

    /**
     *  The Application class is the main class and entry point for a FlexJS
     *  application.  This Application class is different than the
     *  Flex SDK's mx:Application or spark:Application in that it does not contain
     *  user interface elements.  Those UI elements go in the views.  This
     *  Application class expects there to be a main model, a controller, and
     *  an initial view.
     *
     *  @langversion 3.0
     *  @playerversion Flash 10.2
     *  @playerversion AIR 2.6
     *  @productversion FlexJS 0.0
     */
    public class Application extends Sprite implements IStrand, IFlexInfo, IParent, IEventDispatcher
    {
        /**
         *  Constructor.
         *
         *  @langversion 3.0
         *  @playerversion Flash 10.2
         *  @playerversion AIR 2.6
         *  @productversion FlexJS 0.0
         */
        public function Application()
        {
            super();
			if (stage)
			{
				stage.align = StageAlign.TOP_LEFT;
				stage.scaleMode = StageScaleMode.NO_SCALE;
                // should be opt-in
				//stage.quality = StageQuality.HIGH_16X16_LINEAR;
			}

            loaderInfo.addEventListener(flash.events.Event.INIT, initHandler);
        }

        /**
         *  The document property is used to provide
         *  a property lookup context for non-display objects.
         *  For Application, it points to itself.
         *
         *  @langversion 3.0
         *  @playerversion Flash 10.2
         *  @playerversion AIR 2.6
         *  @productversion FlexJS 0.0
         */
        public var document:Object = this;

        private function initHandler(event:flash.events.Event):void
        {
			if (model is IBead) addBead(model as IBead);
			if (controller is IBead) addBead(controller as IBead);

            MouseEventConverter.setupAllConverters(stage);

            for each (var bead:IBead in beads)
                addBead(bead);

            dispatchEvent(new org.apache.flex.events.Event("beadsAdded"));

            MXMLDataInterpreter.generateMXMLInstances(this, null, MXMLDescriptor);

            dispatchEvent(new org.apache.flex.events.Event("initialize"));

            if (initialView)
            {
                initialView.applicationModel =  model;
                if (isNaN(initialView.explicitWidth))
                    initialView.width = stage.stageWidth;
                if (isNaN(initialView.explicitHeight))
                    initialView.height = stage.stageHeight;
        	    this.addElement(initialView);
                var bgColor:Object = ValuesManager.valuesImpl.getValue(this, "background-color");
                if (bgColor != null)
                {
                    var backgroundColor:uint = ValuesManager.valuesImpl.convertColor(bgColor);
                    graphics.beginFill(backgroundColor);
                    graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight);
                    graphics.endFill();
                }
                dispatchEvent(new org.apache.flex.events.Event("viewChanged"));
            }
            dispatchEvent(new org.apache.flex.events.Event("applicationComplete"));
        }

        /**
         *  The org.apache.flex.core.IValuesImpl that will
         *  determine the default values and other values
         *  for the application.  The most common choice
         *  is org.apache.flex.core.SimpleCSSValuesImpl.
         *
         *  @see org.apache.flex.core.SimpleCSSValuesImpl
         *
         *  @langversion 3.0
         *  @playerversion Flash 10.2
         *  @playerversion AIR 2.6
         *  @productversion FlexJS 0.0
         */
        public function set valuesImpl(value:IValuesImpl):void
        {
            ValuesManager.valuesImpl = value;
            ValuesManager.valuesImpl.init(this);
        }

        /**
         *  The initial view.
         *
         *  @see org.apache.flex.core.ViewBase
         *
         *  @langversion 3.0
         *  @playerversion Flash 10.2
         *  @playerversion AIR 2.6
         *  @productversion FlexJS 0.0
         */
        public var initialView:ViewBase;

        /**
         *  The data model (for the initial view).
         *
         *  @langversion 3.0
         *  @playerversion Flash 10.2
         *  @playerversion AIR 2.6
         *  @productversion FlexJS 0.0
         */
        public var model:Object;

        /**
         *  The controller.  The controller typically watches
         *  the UI for events and updates the model accordingly.
         *
         *  @langversion 3.0
         *  @playerversion Flash 10.2
         *  @playerversion AIR 2.6
         *  @productversion FlexJS 0.0
         */
        public var controller:Object;

        /**
         *  An array of data that describes the MXML attributes
         *  and tags in an MXML document.  This data is usually
         *  decoded by an MXMLDataInterpreter
         *
         *  @see org.apache.flex.utils.MXMLDataInterpreter
         *
         *  @langversion 3.0
         *  @playerversion Flash 10.2
         *  @playerversion AIR 2.6
         *  @productversion FlexJS 0.0
         */
        public function get MXMLDescriptor():Array
        {
            return null;
        }

        /**
         *  An method called by the compiler's generated
         *  code to kick off the setting of MXML attribute
         *  values and instantiation of child tags.
         *
         *  The call has to be made in the generated code
         *  in order to ensure that the constructors have
         *  completed first.
         *
         *  @param data The encoded data representing the
         *  MXML attributes.
         *
         *  @see org.apache.flex.utils.MXMLDataInterpreter
         *
         *  @langversion 3.0
         *  @playerversion Flash 10.2
         *  @playerversion AIR 2.6
         *  @productversion FlexJS 0.0
         */
    	public function generateMXMLAttributes(data:Array):void
        {
			MXMLDataInterpreter.generateMXMLProperties(this, data);
        }

        /**
         *  The array property that is used to add additional
         *  beads to an MXML tag.  From ActionScript, just
         *  call addBead directly.
         *
         *  @langversion 3.0
         *  @playerversion Flash 10.2
         *  @playerversion AIR 2.6
         *  @productversion FlexJS 0.0
         */
        public var beads:Array;

        private var _beads:Vector.<IBead>;

        /**
         *  @copy org.apache.flex.core.IStrand#addBead()
         *
         *  @langversion 3.0
         *  @playerversion Flash 10.2
         *  @playerversion AIR 2.6
         *  @productversion FlexJS 0.0
         */
        public function addBead(bead:IBead):void
        {
            if (!_beads)
                _beads = new Vector.<IBead>;
            _beads.push(bead);
            bead.strand = this;
        }

        /**
         *  @copy org.apache.flex.core.IStrand#getBeadByType()
         *
         *  @langversion 3.0
         *  @playerversion Flash 10.2
         *  @playerversion AIR 2.6
         *  @productversion FlexJS 0.0
         */
        public function getBeadByType(classOrInterface:Class):IBead
        {
            for each (var bead:IBead in _beads)
            {
                if (bead is classOrInterface)
                    return bead;
            }
            return null;
        }

        /**
         *  @copy org.apache.flex.core.IStrand#removeBead()
         *
         *  @langversion 3.0
         *  @playerversion Flash 10.2
         *  @playerversion AIR 2.6
         *  @productversion FlexJS 0.0
         */
        public function removeBead(value:IBead):IBead
        {
            var n:int = _beads.length;
            for (var i:int = 0; i < n; i++)
            {
                var bead:IBead = _beads[i];
                if (bead == value)
                {
                    _beads.splice(i, 1);
                    return bead;
                }
            }
            return null;
        }

        private var _info:Object;

        /**
         *  An Object containing information generated
         *  by the compiler that is useful at startup time.
         *
         *  @langversion 3.0
         *  @playerversion Flash 10.2
         *  @playerversion AIR 2.6
         *  @productversion FlexJS 0.0
         */
        public function info():Object
        {
            if (!_info)
            {
                var mainClassName:String = getQualifiedClassName(this);
                var initClassName:String = "_" + mainClassName + "_FlexInit";
                var c:Class = ApplicationDomain.currentDomain.getDefinition(initClassName) as Class;
                _info = c.info();
            }
            return _info;
        }

        /**
         *  @copy org.apache.flex.core.IParent#addElement()
         *
         *  @langversion 3.0
         *  @playerversion Flash 10.2
         *  @playerversion AIR 2.6
         *  @productversion FlexJS 0.0
         */
        public function addElement(c:Object, dispatchEvent:Boolean = true):void
        {
            if (c is IUIBase)
            {
                addChild(IUIBase(c).element as DisplayObject);
                IUIBase(c).addedToParent();
            }
            else
                addChild(c as DisplayObject);
        }

        /**
         *  @copy org.apache.flex.core.IParent#addElementAt()
         *
         *  @langversion 3.0
         *  @playerversion Flash 10.2
         *  @playerversion AIR 2.6
         *  @productversion FlexJS 0.0
         */
        public function addElementAt(c:Object, index:int, dispatchEvent:Boolean = true):void
        {
            if (c is IUIBase)
            {
                addChildAt(IUIBase(c).element as DisplayObject, index);
                IUIBase(c).addedToParent();
            }
            else
                addChildAt(c as DisplayObject, index);
        }

        /**
         *  @copy org.apache.flex.core.IParent#getElementAt()
         *
         *  @langversion 3.0
         *  @playerversion Flash 10.2
         *  @playerversion AIR 2.6
         *  @productversion FlexJS 0.0
         */
        public function getElementAt(index:int):Object
        {
            return getChildAt(index);
        }

        /**
         *  @copy org.apache.flex.core.IParent#getElementIndex()
         *
         *  @langversion 3.0
         *  @playerversion Flash 10.2
         *  @playerversion AIR 2.6
         *  @productversion FlexJS 0.0
         */
        public function getElementIndex(c:Object):int
        {
            if (c is IUIBase)
                return getChildIndex(IUIBase(c).element as DisplayObject);

            return getChildIndex(c as DisplayObject);
        }

        /**
         *  @copy org.apache.flex.core.IParent#removeElement()
         *
         *  @langversion 3.0
         *  @playerversion Flash 10.2
         *  @playerversion AIR 2.6
         *  @productversion FlexJS 0.0
         */
        public function removeElement(c:Object, dispatchEvent:Boolean = true):void
        {
            if (c is IUIBase)
            {
                removeChild(IUIBase(c).element as DisplayObject);
            }
            else
                removeChild(c as DisplayObject);
        }

        /**
         *  @copy org.apache.flex.core.IParent#numElements
         *
         *  @langversion 3.0
         *  @playerversion Flash 10.2
         *  @playerversion AIR 2.6
         *  @productversion FlexJS 0.0
         */
        public function get numElements():int
        {
            return numChildren;
        }
    }
}

set explicitWidth/Height so that initial view doesn't think it is sized to content


////////////////////////////////////////////////////////////////////////////////
//
//  Licensed to the Apache Software Foundation (ASF) under one or more
//  contributor license agreements.  See the NOTICE file distributed with
//  this work for additional information regarding copyright ownership.
//  The ASF licenses this file to You under the Apache License, Version 2.0
//  (the "License"); you may not use this file except in compliance with
//  the License.  You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
//  Unless required by applicable law or agreed to in writing, software
//  distributed under the License is distributed on an "AS IS" BASIS,
//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//  See the License for the specific language governing permissions and
//  limitations under the License.
//
////////////////////////////////////////////////////////////////////////////////
package org.apache.flex.core
{
	import mx.states.State;

	import org.apache.flex.core.ValuesManager;
	import org.apache.flex.events.Event;
	import org.apache.flex.events.ValueChangeEvent;
	import org.apache.flex.utils.MXMLDataInterpreter;

    /**
     *  Indicates that the state change has completed.  All properties
     *  that need to change have been changed, and all transitinos
     *  that need to run have completed.  However, any deferred work
     *  may not be completed, and the screen may not be updated until
     *  code stops executing.
     *
     *  @langversion 3.0
     *  @playerversion Flash 10.2
     *  @playerversion AIR 2.6
     *  @productversion FlexJS 0.0
     */
    [Event(name="stateChangeComplete", type="org.apache.flex.events.Event")]

	[DefaultProperty("mxmlContent")]

    /**
     *  The ContainerBase class is the base class for most containers
     *  in FlexJS.  It is usable as the root tag of MXML
     *  documents and UI controls and containers are added to it.
     *
     *  @langversion 3.0
     *  @playerversion Flash 10.2
     *  @playerversion AIR 2.6
     *  @productversion FlexJS 0.0
     */
	public class ContainerBase extends UIBase
	{
        /**
         *  Constructor.
         *
         *  @langversion 3.0
         *  @playerversion Flash 10.2
         *  @playerversion AIR 2.6
         *  @productversion FlexJS 0.0
         */
		public function ContainerBase()
		{
			super();
		}

        /**
         *  A ContainerBase doesn't create its children until it is added to
         *  a parent.
         *
         *  @langversion 3.0
         *  @playerversion Flash 10.2
         *  @playerversion AIR 2.6
         *  @productversion FlexJS 0.0
         */
		override public function addedToParent():void
		{
			// each MXML file can also have styles in fx:Style block
			ValuesManager.valuesImpl.init(this);

			MXMLDataInterpreter.generateMXMLProperties(this, mxmlProperties);

			super.addedToParent();

			MXMLDataInterpreter.generateMXMLInstances(this, this, MXMLDescriptor);

			dispatchEvent(new Event("initComplete"))
			dispatchEvent(new Event("childrenAdded"));
		}

        /**
         *  @copy org.apache.flex.core.Application#MXMLDescriptor
         *
         *  @langversion 3.0
         *  @playerversion Flash 10.2
         *  @playerversion AIR 2.6
         *  @productversion FlexJS 0.0
         */
		public function get MXMLDescriptor():Array
		{
			return null;
		}

		private var mxmlProperties:Array ;

        /**
         *  @copy org.apache.flex.core.Application#generateMXMLAttributes()
         *
         *  @langversion 3.0
         *  @playerversion Flash 10.2
         *  @playerversion AIR 2.6
         *  @productversion FlexJS 0.0
         */
		public function generateMXMLAttributes(data:Array):void
		{
			mxmlProperties = data;
		}

        /**
         *  @copy org.apache.flex.core.ItemRendererClassFactory#mxmlContent
         *
         *  @langversion 3.0
         *  @playerversion Flash 10.2
         *  @playerversion AIR 2.6
         *  @productversion FlexJS 0.0
         */
		public var mxmlContent:Array;

        private var _states:Array;

        /**
         *  The array of view states. These should
         *  be instances of mx.states.State.
         *
         *  @langversion 3.0
         *  @playerversion Flash 10.2
         *  @playerversion AIR 2.6
         *  @productversion FlexJS 0.0
         */
        public function get states():Array
        {
            return _states;
        }

        /**
         *  @private
         */
        public function set states(value:Array):void
        {
            _states = value;
            _currentState = _states[0].name;

			try{
				if (getBeadByType(IStatesImpl) == null)
					addBead(new (ValuesManager.valuesImpl.getValue(this, "iStatesImpl")) as IBead);
			}
			//TODO:  Need to handle this case more gracefully
			catch(e:Error)
			{
				trace(e.message);
			}

        }

        /**
         *  true if the array of states
         *  contains a state with this name.
         *
         *  @param state The state namem.
         *  @return True if state in state array
         *
         *  @langversion 3.0
         *  @playerversion Flash 10.2
         *  @playerversion AIR 2.6
         *  @productversion FlexJS 0.0
         */
        public function hasState(state:String):Boolean
        {
            for each (var s:State in _states)
            {
                if (s.name == state)
                    return true;
            }
            return false;
        }

        private var _currentState:String;

        /**
         *  The name of the current state.
         *
         *  @langversion 3.0
         *  @playerversion Flash 10.2
         *  @playerversion AIR 2.6
         *  @productversion FlexJS 0.0
         */
        public function get currentState():String
        {
            return _currentState;
        }

        /**
         *  @private
         */
        public function set currentState(value:String):void
        {
            var event:ValueChangeEvent = new ValueChangeEvent("currentStateChanged", false, false, _currentState, value)
            _currentState = value;
            dispatchEvent(event);
        }

        private var _transitions:Array;

        /**
         *  The array of transitions.
         *
         *  @langversion 3.0
         *  @playerversion Flash 10.2
         *  @playerversion AIR 2.6
         *  @productversion FlexJS 0.0
         */
        public function get transitions():Array
        {
            return _transitions;
        }

        /**
         *  @private
         */
        public function set transitions(value:Array):void
        {
            _transitions = value;
        }

    }
}

////////////////////////////////////////////////////////////////////////////////
//
//  Licensed to the Apache Software Foundation (ASF) under one or more
//  contributor license agreements.  See the NOTICE file distributed with
//  this work for additional information regarding copyright ownership.
//  The ASF licenses this file to You under the Apache License, Version 2.0
//  (the "License"); you may not use this file except in compliance with
//  the License.  You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
//  Unless required by applicable law or agreed to in writing, software
//  distributed under the License is distributed on an "AS IS" BASIS,
//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//  See the License for the specific language governing permissions and
//  limitations under the License.
//
////////////////////////////////////////////////////////////////////////////////
package org.apache.flex.core
{
	import mx.states.State;

	import org.apache.flex.core.ValuesManager;
	import org.apache.flex.events.Event;
	import org.apache.flex.events.ValueChangeEvent;
	import org.apache.flex.utils.MXMLDataInterpreter;

    /**
     *  Indicates that the state change has completed.  All properties
     *  that need to change have been changed, and all transitinos
     *  that need to run have completed.  However, any deferred work
     *  may not be completed, and the screen may not be updated until
     *  code stops executing.
     *
     *  @langversion 3.0
     *  @playerversion Flash 10.2
     *  @playerversion AIR 2.6
     *  @productversion FlexJS 0.0
     */
    [Event(name="stateChangeComplete", type="org.apache.flex.events.Event")]

    /**
     *  Indicates that the initialization of the container is complete.
     *
     *  @langversion 3.0
     *  @playerversion Flash 10.2
     *  @playerversion AIR 2.6
     *  @productversion FlexJS 0.0
     */
    [Event(name="initComplete", type="org.apache.flex.events.Event")]

    /**
     *  Indicates that the children of the container is have been added.
     *
     *  @langversion 3.0
     *  @playerversion Flash 10.2
     *  @playerversion AIR 2.6
     *  @productversion FlexJS 0.0
     */
    [Event(name="childrenAdded", type="org.apache.flex.events.Event")]

	[DefaultProperty("mxmlContent")]

    /**
     *  The ContainerBase class is the base class for most containers
     *  in FlexJS.  It is usable as the root tag of MXML
     *  documents and UI controls and containers are added to it.
     *
     *  @langversion 3.0
     *  @playerversion Flash 10.2
     *  @playerversion AIR 2.6
     *  @productversion FlexJS 0.0
     */
	public class ContainerBase extends UIBase
	{
        /**
         *  Constructor.
         *
         *  @langversion 3.0
         *  @playerversion Flash 10.2
         *  @playerversion AIR 2.6
         *  @productversion FlexJS 0.0
         */
		public function ContainerBase()
		{
			super();
		}

        /**
         *  A ContainerBase doesn't create its children until it is added to
         *  a parent.
         *
         *  @langversion 3.0
         *  @playerversion Flash 10.2
         *  @playerversion AIR 2.6
         *  @productversion FlexJS 0.0
         */
		override public function addedToParent():void
		{
			// each MXML file can also have styles in fx:Style block
			ValuesManager.valuesImpl.init(this);

			MXMLDataInterpreter.generateMXMLProperties(this, mxmlProperties);

			super.addedToParent();

			MXMLDataInterpreter.generateMXMLInstances(this, this, MXMLDescriptor);

			dispatchEvent(new Event("initComplete"))
			dispatchEvent(new Event("childrenAdded"));
		}

        /**
         *  @copy org.apache.flex.core.Application#MXMLDescriptor
         *
         *  @langversion 3.0
         *  @playerversion Flash 10.2
         *  @playerversion AIR 2.6
         *  @productversion FlexJS 0.0
         */
		public function get MXMLDescriptor():Array
		{
			return null;
		}

		private var mxmlProperties:Array ;

        /**
         *  @copy org.apache.flex.core.Application#generateMXMLAttributes()
         *
         *  @langversion 3.0
         *  @playerversion Flash 10.2
         *  @playerversion AIR 2.6
         *  @productversion FlexJS 0.0
         */
		public function generateMXMLAttributes(data:Array):void
		{
			mxmlProperties = data;
		}

        /**
         *  @copy org.apache.flex.core.ItemRendererClassFactory#mxmlContent
         *
         *  @langversion 3.0
         *  @playerversion Flash 10.2
         *  @playerversion AIR 2.6
         *  @productversion FlexJS 0.0
         */
		public var mxmlContent:Array;

        private var _states:Array;

        /**
         *  The array of view states. These should
         *  be instances of mx.states.State.
         *
         *  @langversion 3.0
         *  @playerversion Flash 10.2
         *  @playerversion AIR 2.6
         *  @productversion FlexJS 0.0
         */
        public function get states():Array
        {
            return _states;
        }

        /**
         *  @private
         */
        public function set states(value:Array):void
        {
            _states = value;
            _currentState = _states[0].name;

			try{
				if (getBeadByType(IStatesImpl) == null)
					addBead(new (ValuesManager.valuesImpl.getValue(this, "iStatesImpl")) as IBead);
			}
			//TODO:  Need to handle this case more gracefully
			catch(e:Error)
			{
				trace(e.message);
			}

        }

        /**
         *  true if the array of states
         *  contains a state with this name.
         *
         *  @param state The state namem.
         *  @return True if state in state array
         *
         *  @langversion 3.0
         *  @playerversion Flash 10.2
         *  @playerversion AIR 2.6
         *  @productversion FlexJS 0.0
         */
        public function hasState(state:String):Boolean
        {
            for each (var s:State in _states)
            {
                if (s.name == state)
                    return true;
            }
            return false;
        }

        private var _currentState:String;

        /**
         *  The name of the current state.
         *
         *  @langversion 3.0
         *  @playerversion Flash 10.2
         *  @playerversion AIR 2.6
         *  @productversion FlexJS 0.0
         */
        public function get currentState():String
        {
            return _currentState;
        }

        /**
         *  @private
         */
        public function set currentState(value:String):void
        {
            var event:ValueChangeEvent = new ValueChangeEvent("currentStateChanged", false, false, _currentState, value)
            _currentState = value;
            dispatchEvent(event);
        }

        private var _transitions:Array;

        /**
         *  The array of transitions.
         *
         *  @langversion 3.0
         *  @playerversion Flash 10.2
         *  @playerversion AIR 2.6
         *  @productversion FlexJS 0.0
         */
        public function get transitions():Array
        {
            return _transitions;
        }

        /**
         *  @private
         */
        public function set transitions(value:Array):void
        {
            _transitions = value;
        }

    }
}

add container events

add container events


package aerys.minko.render.material.basic
{
	import aerys.minko.render.Effect;
	import aerys.minko.render.material.Material;
	import aerys.minko.render.resource.texture.TextureResource;
	import aerys.minko.type.binding.IDataProvider;
	import aerys.minko.type.math.Matrix4x4;
	import aerys.minko.type.math.Vector4;

	public class BasicMaterial extends Material
	{
		public static const DEFAULT_NAME			: String		= 'BasicMaterial';
		public static const DEFAULT_BASIC_SHADER	: BasicShader	= new BasicShader();
		public static const DEFAULT_EFFECT			: Effect		= new Effect(DEFAULT_BASIC_SHADER);

		public function get diffuseMapFormat() : uint
		{
			return getProperty(BasicProperties.DIFFUSE_MAP_FORMAT);
		}

		public function set diffuseMapFormat(value : uint) : void
		{
			setProperty(BasicProperties.DIFFUSE_MAP_FORMAT, value);
		}

		public function get blending() : uint
		{
			return getProperty(BasicProperties.BLENDING);
		}
		public function set blending(value : uint) : void
		{
			setProperty(BasicProperties.BLENDING, value);
		}

		public function get triangleCulling() : uint
		{
			return getProperty(BasicProperties.TRIANGLE_CULLING);
		}
		public function set triangleCulling(value : uint) : void
		{
			setProperty(BasicProperties.TRIANGLE_CULLING, value);
		}

		public function get diffuseColor() : Object
		{
			return getProperty(BasicProperties.DIFFUSE_COLOR);
		}
		public function set diffuseColor(value : Object) : void
		{
			setProperty(BasicProperties.DIFFUSE_COLOR, value);
		}

		public function get diffuseMap() : TextureResource
		{
			return getProperty(BasicProperties.DIFFUSE_MAP);
		}
		public function set diffuseMap(value : TextureResource) : void
		{
			setProperty(BasicProperties.DIFFUSE_MAP, value);
		}

		public function get alphaMap() : TextureResource
		{
			return getProperty(BasicProperties.ALPHA_MAP) as TextureResource;
		}
		public function set alphaMap(value : TextureResource) : void
		{
			setProperty(BasicProperties.ALPHA_MAP, value);
		}

		public function get alphaThreshold() : Number
		{
			return getProperty(BasicProperties.ALPHA_THRESHOLD);
		}
		public function set alphaThreshold(value : Number) : void
		{
			setProperty(BasicProperties.ALPHA_THRESHOLD, value);
		}

		public function get depthTest() : uint
		{
			return getProperty(BasicProperties.DEPTH_TEST);
		}
		public function set depthTest(value : uint) : void
		{
			setProperty(BasicProperties.DEPTH_TEST, value);
		}

		public function get depthWriteEnabled() : Boolean
		{
			return getProperty(BasicProperties.DEPTH_WRITE_ENABLED);
		}
		public function set depthWriteEnabled(value : Boolean) : void
		{
			setProperty(BasicProperties.DEPTH_WRITE_ENABLED, value);
		}

		public function get stencilTriangleFace() : uint
		{
			return getProperty(BasicProperties.STENCIL_TRIANGLE_FACE);
		}
		public function set stencilTriangleFace(value : uint) : void
		{
			setProperty(BasicProperties.STENCIL_TRIANGLE_FACE, value);
		}

		public function get stencilCompareMode() : uint
		{
			return getProperty(BasicProperties.STENCIL_COMPARE_MODE);
		}
		public function set stencilCompareMode(value : uint) : void
		{
			setProperty(BasicProperties.STENCIL_COMPARE_MODE, value);
		}

		public function get stencilActionBothPass() : uint
		{
			return getProperty(BasicProperties.STENCIL_ACTION_BOTH_PASS);
		}
		public function set stencilActionBothPass(value : uint) : void
		{
			setProperty(BasicProperties.STENCIL_ACTION_BOTH_PASS, value);
		}

		public function get stencilActionDepthFail() : uint
		{
			return getProperty(BasicProperties.STENCIL_ACTION_DEPTH_FAIL);
		}
		public function set stencilActionDepthFail(value : uint) : void
		{
			setProperty(BasicProperties.STENCIL_ACTION_DEPTH_FAIL, value);
		}

		public function get stencilActionDepthPassStencilFail() : uint
		{
			return getProperty(BasicProperties.STENCIL_ACTION_DEPTH_PASS_STENCIL_FAIL);
		}
		public function set stencilActionDepthPassStencilFail(value : uint) : void
		{
			setProperty(BasicProperties.STENCIL_ACTION_DEPTH_PASS_STENCIL_FAIL, value);
		}

		public function get stencilReferenceValue() : Number
		{
			return getProperty(BasicProperties.STENCIL_REFERENCE_VALUE);
		}
		public function set stencilReferenceValue(value : Number) : void
		{
			setProperty(BasicProperties.STENCIL_REFERENCE_VALUE, value);
		}

		public function get stencilReadMask() : uint
		{
			return getProperty(BasicProperties.STENCIL_READ_MASK);
		}
		public function set stencilReadMask(value : uint) : void
		{
			setProperty(BasicProperties.STENCIL_READ_MASK, value);
		}

		public function get stencilWriteMask() : uint
		{
			return getProperty(BasicProperties.STENCIL_WRITE_MASK);
		}
		public function set stencilWriteMask(value : uint) : void
		{
			setProperty(BasicProperties.STENCIL_WRITE_MASK, value);
		}

		public function get diffuseTransform() : Matrix4x4
		{
			return getProperty(BasicProperties.DIFFUSE_TRANSFORM);
		}
		public function set diffuseTransform(value : Matrix4x4) : void
		{
			setProperty(BasicProperties.DIFFUSE_TRANSFORM, value);
		}

        public function get uvOffset() : Vector4
        {
            return getProperty(BasicProperties.UV_OFFSET);
        }
        public function set uvOffset(value : Vector4) : void
        {
            setProperty(BasicProperties.UV_OFFSET, value);
        }

        public function get uvScale() : Vector4
        {
            return getProperty(BasicProperties.UV_SCALE);
        }
        public function set uvScale(value : Vector4) : void
        {
            setProperty(BasicProperties.UV_SCALE, value);
        }

		public function BasicMaterial(properties : Object = null, effect : Effect = null, name : String = DEFAULT_NAME)
		{
			super(effect || DEFAULT_EFFECT, properties, name);
		}

		override public function clone() : IDataProvider
		{
			var mat : BasicMaterial	= new BasicMaterial(this, effect, name);

			return mat;
		}
	}
}

package aerys.minko.render.material.basic
{
	import aerys.minko.render.Effect;
	import aerys.minko.render.material.Material;
	import aerys.minko.render.resource.texture.TextureResource;
	import aerys.minko.type.binding.IDataProvider;
	import aerys.minko.type.math.Matrix4x4;
	import aerys.minko.type.math.Vector4;

	public class BasicMaterial extends Material
	{
		public static const DEFAULT_NAME			: String		= 'BasicMaterial';
		public static const DEFAULT_BASIC_SHADER	: BasicShader	= new BasicShader();
		public static const DEFAULT_EFFECT			: Effect		= new Effect(DEFAULT_BASIC_SHADER);

		public function get blending() : uint
		{
			return getProperty(BasicProperties.BLENDING);
		}
		public function set blending(value : uint) : void
		{
			setProperty(BasicProperties.BLENDING, value);
		}

		public function get triangleCulling() : uint
		{
			return getProperty(BasicProperties.TRIANGLE_CULLING);
		}
		public function set triangleCulling(value : uint) : void
		{
			setProperty(BasicProperties.TRIANGLE_CULLING, value);
		}

		public function get diffuseColor() : Object
		{
			return getProperty(BasicProperties.DIFFUSE_COLOR);
		}
		public function set diffuseColor(value : Object) : void
		{
			setProperty(BasicProperties.DIFFUSE_COLOR, value);
		}

		public function get diffuseMap() : TextureResource
		{
			return getProperty(BasicProperties.DIFFUSE_MAP);
		}
		public function set diffuseMap(value : TextureResource) : void
		{
			setProperty(BasicProperties.DIFFUSE_MAP, value);
		}

        public function get diffuseMapFiltering() : uint
        {
            return getProperty(BasicProperties.DIFFUSE_MAP_FILTERING);
        }
        public function set diffuseMapFiltering(value : uint) : void
        {
            setProperty(BasicProperties.DIFFUSE_MAP_FILTERING, value);
        }

        public function get diffuseMapFormat() : uint
        {
            return getProperty(BasicProperties.DIFFUSE_MAP_FORMAT);
        }
        public function set diffuseMapFormat(value : uint) : void
        {
            setProperty(BasicProperties.DIFFUSE_MAP_FORMAT, value);
        }

		public function get alphaMap() : TextureResource
		{
			return getProperty(BasicProperties.ALPHA_MAP) as TextureResource;
		}
		public function set alphaMap(value : TextureResource) : void
		{
			setProperty(BasicProperties.ALPHA_MAP, value);
		}

		public function get alphaThreshold() : Number
		{
			return getProperty(BasicProperties.ALPHA_THRESHOLD);
		}
		public function set alphaThreshold(value : Number) : void
		{
			setProperty(BasicProperties.ALPHA_THRESHOLD, value);
		}

		public function get depthTest() : uint
		{
			return getProperty(BasicProperties.DEPTH_TEST);
		}
		public function set depthTest(value : uint) : void
		{
			setProperty(BasicProperties.DEPTH_TEST, value);
		}

		public function get depthWriteEnabled() : Boolean
		{
			return getProperty(BasicProperties.DEPTH_WRITE_ENABLED);
		}
		public function set depthWriteEnabled(value : Boolean) : void
		{
			setProperty(BasicProperties.DEPTH_WRITE_ENABLED, value);
		}

		public function get stencilTriangleFace() : uint
		{
			return getProperty(BasicProperties.STENCIL_TRIANGLE_FACE);
		}
		public function set stencilTriangleFace(value : uint) : void
		{
			setProperty(BasicProperties.STENCIL_TRIANGLE_FACE, value);
		}

		public function get stencilCompareMode() : uint
		{
			return getProperty(BasicProperties.STENCIL_COMPARE_MODE);
		}
		public function set stencilCompareMode(value : uint) : void
		{
			setProperty(BasicProperties.STENCIL_COMPARE_MODE, value);
		}

		public function get stencilActionBothPass() : uint
		{
			return getProperty(BasicProperties.STENCIL_ACTION_BOTH_PASS);
		}
		public function set stencilActionBothPass(value : uint) : void
		{
			setProperty(BasicProperties.STENCIL_ACTION_BOTH_PASS, value);
		}

		public function get stencilActionDepthFail() : uint
		{
			return getProperty(BasicProperties.STENCIL_ACTION_DEPTH_FAIL);
		}
		public function set stencilActionDepthFail(value : uint) : void
		{
			setProperty(BasicProperties.STENCIL_ACTION_DEPTH_FAIL, value);
		}

		public function get stencilActionDepthPassStencilFail() : uint
		{
			return getProperty(BasicProperties.STENCIL_ACTION_DEPTH_PASS_STENCIL_FAIL);
		}
		public function set stencilActionDepthPassStencilFail(value : uint) : void
		{
			setProperty(BasicProperties.STENCIL_ACTION_DEPTH_PASS_STENCIL_FAIL, value);
		}

		public function get stencilReferenceValue() : Number
		{
			return getProperty(BasicProperties.STENCIL_REFERENCE_VALUE);
		}
		public function set stencilReferenceValue(value : Number) : void
		{
			setProperty(BasicProperties.STENCIL_REFERENCE_VALUE, value);
		}

		public function get stencilReadMask() : uint
		{
			return getProperty(BasicProperties.STENCIL_READ_MASK);
		}
		public function set stencilReadMask(value : uint) : void
		{
			setProperty(BasicProperties.STENCIL_READ_MASK, value);
		}

		public function get stencilWriteMask() : uint
		{
			return getProperty(BasicProperties.STENCIL_WRITE_MASK);
		}
		public function set stencilWriteMask(value : uint) : void
		{
			setProperty(BasicProperties.STENCIL_WRITE_MASK, value);
		}

		public function get diffuseTransform() : Matrix4x4
		{
			return getProperty(BasicProperties.DIFFUSE_TRANSFORM);
		}
		public function set diffuseTransform(value : Matrix4x4) : void
		{
			setProperty(BasicProperties.DIFFUSE_TRANSFORM, value);
		}

        public function get uvOffset() : Vector4
        {
            return getProperty(BasicProperties.UV_OFFSET);
        }
        public function set uvOffset(value : Vector4) : void
        {
            setProperty(BasicProperties.UV_OFFSET, value);
        }

        public function get uvScale() : Vector4
        {
            return getProperty(BasicProperties.UV_SCALE);
        }
        public function set uvScale(value : Vector4) : void
        {
            setProperty(BasicProperties.UV_SCALE, value);
        }

		public function BasicMaterial(properties : Object = null, effect : Effect = null, name : String = DEFAULT_NAME)
		{
			super(effect || DEFAULT_EFFECT, properties, name);
		}

		override public function clone() : IDataProvider
		{
			var mat : BasicMaterial	= new BasicMaterial(this, effect, name);

			return mat;
		}
	}
}

add property BasicMaterial.diffuseMapFiltering


package aerys.minko.render.material.basic
{
	import aerys.minko.render.Effect;
	import aerys.minko.render.material.Material;
	import aerys.minko.render.resource.texture.TextureResource;
	import aerys.minko.type.binding.IDataProvider;
	import aerys.minko.type.math.Matrix4x4;
	import aerys.minko.type.math.Vector4;

	public class BasicMaterial extends Material
	{
		public static const DEFAULT_NAME			: String		= 'BasicMaterial';
		public static const DEFAULT_BASIC_SHADER	: BasicShader	= new BasicShader();
		public static const DEFAULT_EFFECT			: Effect		= new Effect(DEFAULT_BASIC_SHADER);

		public function get diffuseFormat() : uint
		{
			return getProperty(BasicProperties.DIFFUSE_MAP_FORMAT);
		}

		public function set diffuseFormat(value : uint) : void
		{
			setProperty(BasicProperties.DIFFUSE_MAP_FORMAT, value);
		}

		public function get blending() : uint
		{
			return getProperty(BasicProperties.BLENDING);
		}
		public function set blending(value : uint) : void
		{
			setProperty(BasicProperties.BLENDING, value);
		}

		public function get triangleCulling() : uint
		{
			return getProperty(BasicProperties.TRIANGLE_CULLING);
		}
		public function set triangleCulling(value : uint) : void
		{
			setProperty(BasicProperties.TRIANGLE_CULLING, value);
		}

		public function get diffuseColor() : Object
		{
			return getProperty(BasicProperties.DIFFUSE_COLOR);
		}
		public function set diffuseColor(value : Object) : void
		{
			setProperty(BasicProperties.DIFFUSE_COLOR, value);
		}

		public function get diffuseMap() : TextureResource
		{
			return getProperty(BasicProperties.DIFFUSE_MAP);
		}
		public function set diffuseMap(value : TextureResource) : void
		{
			setProperty(BasicProperties.DIFFUSE_MAP, value);
		}

		public function get alphaMap() : TextureResource
		{
			return getProperty(BasicProperties.ALPHA_MAP) as TextureResource;
		}
		public function set alphaMap(value : TextureResource) : void
		{
			setProperty(BasicProperties.ALPHA_MAP, value);
		}

		public function get alphaThreshold() : Number
		{
			return getProperty(BasicProperties.ALPHA_THRESHOLD);
		}
		public function set alphaThreshold(value : Number) : void
		{
			setProperty(BasicProperties.ALPHA_THRESHOLD, value);
		}

		public function get depthTest() : uint
		{
			return getProperty(BasicProperties.DEPTH_TEST);
		}
		public function set depthTest(value : uint) : void
		{
			setProperty(BasicProperties.DEPTH_TEST, value);
		}

		public function get depthWriteEnabled() : Boolean
		{
			return getProperty(BasicProperties.DEPTH_WRITE_ENABLED);
		}
		public function set depthWriteEnabled(value : Boolean) : void
		{
			setProperty(BasicProperties.DEPTH_WRITE_ENABLED, value);
		}

		public function get stencilTriangleFace() : uint
		{
			return getProperty(BasicProperties.STENCIL_TRIANGLE_FACE);
		}
		public function set stencilTriangleFace(value : uint) : void
		{
			setProperty(BasicProperties.STENCIL_TRIANGLE_FACE, value);
		}

		public function get stencilCompareMode() : uint
		{
			return getProperty(BasicProperties.STENCIL_COMPARE_MODE);
		}
		public function set stencilCompareMode(value : uint) : void
		{
			setProperty(BasicProperties.STENCIL_COMPARE_MODE, value);
		}

		public function get stencilActionBothPass() : uint
		{
			return getProperty(BasicProperties.STENCIL_ACTION_BOTH_PASS);
		}
		public function set stencilActionBothPass(value : uint) : void
		{
			setProperty(BasicProperties.STENCIL_ACTION_BOTH_PASS, value);
		}

		public function get stencilActionDepthFail() : uint
		{
			return getProperty(BasicProperties.STENCIL_ACTION_DEPTH_FAIL);
		}
		public function set stencilActionDepthFail(value : uint) : void
		{
			setProperty(BasicProperties.STENCIL_ACTION_DEPTH_FAIL, value);
		}

		public function get stencilActionDepthPassStencilFail() : uint
		{
			return getProperty(BasicProperties.STENCIL_ACTION_DEPTH_PASS_STENCIL_FAIL);
		}
		public function set stencilActionDepthPassStencilFail(value : uint) : void
		{
			setProperty(BasicProperties.STENCIL_ACTION_DEPTH_PASS_STENCIL_FAIL, value);
		}

		public function get stencilReferenceValue() : Number
		{
			return getProperty(BasicProperties.STENCIL_REFERENCE_VALUE);
		}
		public function set stencilReferenceValue(value : Number) : void
		{
			setProperty(BasicProperties.STENCIL_REFERENCE_VALUE, value);
		}

		public function get stencilReadMask() : uint
		{
			return getProperty(BasicProperties.STENCIL_READ_MASK);
		}
		public function set stencilReadMask(value : uint) : void
		{
			setProperty(BasicProperties.STENCIL_READ_MASK, value);
		}

		public function get stencilWriteMask() : uint
		{
			return getProperty(BasicProperties.STENCIL_WRITE_MASK);
		}
		public function set stencilWriteMask(value : uint) : void
		{
			setProperty(BasicProperties.STENCIL_WRITE_MASK, value);
		}

		public function get diffuseTransform() : Matrix4x4
		{
			return getProperty(BasicProperties.DIFFUSE_TRANSFORM);
		}
		public function set diffuseTransform(value : Matrix4x4) : void
		{
			setProperty(BasicProperties.DIFFUSE_TRANSFORM, value);
		}

        public function get uvOffset() : Vector4
        {
            return getProperty(BasicProperties.UV_OFFSET);
        }
        public function set uvOffset(value : Vector4) : void
        {
            setProperty(BasicProperties.UV_OFFSET, value);
        }

        public function get uvScale() : Vector4
        {
            return getProperty(BasicProperties.UV_SCALE);
        }
        public function set uvScale(value : Vector4) : void
        {
            setProperty(BasicProperties.UV_SCALE, value);
        }

		public function BasicMaterial(properties : Object = null, effect : Effect = null, name : String = DEFAULT_NAME)
		{
			super(effect || DEFAULT_EFFECT, properties, name);
		}

		override public function clone() : IDataProvider
		{
			var mat : BasicMaterial	= new BasicMaterial(this, effect, name);

			return mat;
		}
	}
}

package aerys.minko.render.material.basic
{
	import aerys.minko.render.Effect;
	import aerys.minko.render.material.Material;
	import aerys.minko.render.resource.texture.TextureResource;
	import aerys.minko.type.binding.IDataProvider;
	import aerys.minko.type.math.Matrix4x4;
	import aerys.minko.type.math.Vector4;

	public class BasicMaterial extends Material
	{
		public static const DEFAULT_NAME			: String		= 'BasicMaterial';
		public static const DEFAULT_BASIC_SHADER	: BasicShader	= new BasicShader();
		public static const DEFAULT_EFFECT			: Effect		= new Effect(DEFAULT_BASIC_SHADER);

		public function get diffuseMapFormat() : uint
		{
			return getProperty(BasicProperties.DIFFUSE_MAP_FORMAT);
		}

		public function set diffuseMapFormat(value : uint) : void
		{
			setProperty(BasicProperties.DIFFUSE_MAP_FORMAT, value);
		}

		public function get blending() : uint
		{
			return getProperty(BasicProperties.BLENDING);
		}
		public function set blending(value : uint) : void
		{
			setProperty(BasicProperties.BLENDING, value);
		}

		public function get triangleCulling() : uint
		{
			return getProperty(BasicProperties.TRIANGLE_CULLING);
		}
		public function set triangleCulling(value : uint) : void
		{
			setProperty(BasicProperties.TRIANGLE_CULLING, value);
		}

		public function get diffuseColor() : Object
		{
			return getProperty(BasicProperties.DIFFUSE_COLOR);
		}
		public function set diffuseColor(value : Object) : void
		{
			setProperty(BasicProperties.DIFFUSE_COLOR, value);
		}

		public function get diffuseMap() : TextureResource
		{
			return getProperty(BasicProperties.DIFFUSE_MAP);
		}
		public function set diffuseMap(value : TextureResource) : void
		{
			setProperty(BasicProperties.DIFFUSE_MAP, value);
		}

		public function get alphaMap() : TextureResource
		{
			return getProperty(BasicProperties.ALPHA_MAP) as TextureResource;
		}
		public function set alphaMap(value : TextureResource) : void
		{
			setProperty(BasicProperties.ALPHA_MAP, value);
		}

		public function get alphaThreshold() : Number
		{
			return getProperty(BasicProperties.ALPHA_THRESHOLD);
		}
		public function set alphaThreshold(value : Number) : void
		{
			setProperty(BasicProperties.ALPHA_THRESHOLD, value);
		}

		public function get depthTest() : uint
		{
			return getProperty(BasicProperties.DEPTH_TEST);
		}
		public function set depthTest(value : uint) : void
		{
			setProperty(BasicProperties.DEPTH_TEST, value);
		}

		public function get depthWriteEnabled() : Boolean
		{
			return getProperty(BasicProperties.DEPTH_WRITE_ENABLED);
		}
		public function set depthWriteEnabled(value : Boolean) : void
		{
			setProperty(BasicProperties.DEPTH_WRITE_ENABLED, value);
		}

		public function get stencilTriangleFace() : uint
		{
			return getProperty(BasicProperties.STENCIL_TRIANGLE_FACE);
		}
		public function set stencilTriangleFace(value : uint) : void
		{
			setProperty(BasicProperties.STENCIL_TRIANGLE_FACE, value);
		}

		public function get stencilCompareMode() : uint
		{
			return getProperty(BasicProperties.STENCIL_COMPARE_MODE);
		}
		public function set stencilCompareMode(value : uint) : void
		{
			setProperty(BasicProperties.STENCIL_COMPARE_MODE, value);
		}

		public function get stencilActionBothPass() : uint
		{
			return getProperty(BasicProperties.STENCIL_ACTION_BOTH_PASS);
		}
		public function set stencilActionBothPass(value : uint) : void
		{
			setProperty(BasicProperties.STENCIL_ACTION_BOTH_PASS, value);
		}

		public function get stencilActionDepthFail() : uint
		{
			return getProperty(BasicProperties.STENCIL_ACTION_DEPTH_FAIL);
		}
		public function set stencilActionDepthFail(value : uint) : void
		{
			setProperty(BasicProperties.STENCIL_ACTION_DEPTH_FAIL, value);
		}

		public function get stencilActionDepthPassStencilFail() : uint
		{
			return getProperty(BasicProperties.STENCIL_ACTION_DEPTH_PASS_STENCIL_FAIL);
		}
		public function set stencilActionDepthPassStencilFail(value : uint) : void
		{
			setProperty(BasicProperties.STENCIL_ACTION_DEPTH_PASS_STENCIL_FAIL, value);
		}

		public function get stencilReferenceValue() : Number
		{
			return getProperty(BasicProperties.STENCIL_REFERENCE_VALUE);
		}
		public function set stencilReferenceValue(value : Number) : void
		{
			setProperty(BasicProperties.STENCIL_REFERENCE_VALUE, value);
		}

		public function get stencilReadMask() : uint
		{
			return getProperty(BasicProperties.STENCIL_READ_MASK);
		}
		public function set stencilReadMask(value : uint) : void
		{
			setProperty(BasicProperties.STENCIL_READ_MASK, value);
		}

		public function get stencilWriteMask() : uint
		{
			return getProperty(BasicProperties.STENCIL_WRITE_MASK);
		}
		public function set stencilWriteMask(value : uint) : void
		{
			setProperty(BasicProperties.STENCIL_WRITE_MASK, value);
		}

		public function get diffuseTransform() : Matrix4x4
		{
			return getProperty(BasicProperties.DIFFUSE_TRANSFORM);
		}
		public function set diffuseTransform(value : Matrix4x4) : void
		{
			setProperty(BasicProperties.DIFFUSE_TRANSFORM, value);
		}

        public function get uvOffset() : Vector4
        {
            return getProperty(BasicProperties.UV_OFFSET);
        }
        public function set uvOffset(value : Vector4) : void
        {
            setProperty(BasicProperties.UV_OFFSET, value);
        }

        public function get uvScale() : Vector4
        {
            return getProperty(BasicProperties.UV_SCALE);
        }
        public function set uvScale(value : Vector4) : void
        {
            setProperty(BasicProperties.UV_SCALE, value);
        }

		public function BasicMaterial(properties : Object = null, effect : Effect = null, name : String = DEFAULT_NAME)
		{
			super(effect || DEFAULT_EFFECT, properties, name);
		}

		override public function clone() : IDataProvider
		{
			var mat : BasicMaterial	= new BasicMaterial(this, effect, name);

			return mat;
		}
	}
}

refactor BasicMaterial.diffuseFormat into BasicMaterial.diffuseMapFormat


////////////////////////////////////////////////////////////////////////////////
//
//  Licensed to the Apache Software Foundation (ASF) under one or more
//  contributor license agreements.  See the NOTICE file distributed with
//  this work for additional information regarding copyright ownership.
//  The ASF licenses this file to You under the Apache License, Version 2.0
//  (the "License"); you may not use this file except in compliance with
//  the License.  You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
//  Unless required by applicable law or agreed to in writing, software
//  distributed under the License is distributed on an "AS IS" BASIS,
//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//  See the License for the specific language governing permissions and
//  limitations under the License.
//
////////////////////////////////////////////////////////////////////////////////
package org.apache.flex.html.beads
{
	import flash.display.DisplayObject;
	import flash.display.DisplayObjectContainer;

	import org.apache.flex.core.CSSTextField;
	import org.apache.flex.core.IBeadView;
    import org.apache.flex.core.ILayoutChild;
	import org.apache.flex.core.IStrand;
	import org.apache.flex.core.ITextModel;
	import org.apache.flex.core.IUIBase;
	import org.apache.flex.core.UIBase;
	import org.apache.flex.core.ValuesManager;
	import org.apache.flex.events.Event;
	import org.apache.flex.events.IEventDispatcher;

    /**
     *  The TextFieldViewBase class is the base class for
     *  the components that display text.
     *  It displays text using a TextField, so there is no
     *  right-to-left text support in this view.
     *
     *  @langversion 3.0
     *  @playerversion Flash 10.2
     *  @playerversion AIR 2.6
     *  @productversion FlexJS 0.0
     */
	public class TextFieldViewBase implements IBeadView, ITextFieldView
	{
        /**
         *  Constructor.
         *
         *  @langversion 3.0
         *  @playerversion Flash 10.2
         *  @playerversion AIR 2.6
         *  @productversion FlexJS 0.0
         */
		public function TextFieldViewBase()
		{
			_textField = new CSSTextField();
		}

		private var _textField:CSSTextField;

        /**
         *  @copy org.apache.flex.core.ITextModel#textField
         *
         *  @langversion 3.0
         *  @playerversion Flash 10.2
         *  @playerversion AIR 2.6
         *  @productversion FlexJS 0.0
         */
		public function get textField() : CSSTextField
		{
			return _textField;
		}

		private var _textModel:ITextModel;

		protected var _strand:IStrand;

        /**
         *  @copy org.apache.flex.core.IBead#strand
         *
         *  @langversion 3.0
         *  @playerversion Flash 10.2
         *  @playerversion AIR 2.6
         *  @productversion FlexJS 0.0
         */
		public function set strand(value:IStrand):void
		{
			_strand = value;
			_textModel = value.getBeadByType(ITextModel) as ITextModel;
            _textModel.addEventListener("textChange", textChangeHandler);
            _textModel.addEventListener("htmlChange", htmlChangeHandler);
            IEventDispatcher(_strand).addEventListener("widthChanged", widthChangeHandler);
            IEventDispatcher(_strand).addEventListener("heightChanged", heightChangeHandler);
            IEventDispatcher(_strand).addEventListener("sizeChanged", sizeChangeHandler);
			DisplayObjectContainer(value).addChild(_textField);
			if (_textModel.text !== null)
				text = _textModel.text;
			if (_textModel.html !== null)
				html = _textModel.html;

            var ilc:ILayoutChild = host as ILayoutChild;

            autoHeight = ilc.isHeightSizedToContent();
            autoWidth = ilc.isWidthSizedToContent();
            if (!autoWidth && !isNaN(ilc.explicitWidth))
            {
                widthChangeHandler(null);
            }
            if (!autoHeight && !isNaN(ilc.explicitHeight))
            {
                heightChangeHandler(null);
            }
		}

        /**
         *  @private
         */
		public function get host() : IUIBase
		{
			return _strand as IUIBase;
		}

        /**
         *  @copy org.apache.flex.core.ITextModel#text
         *
         *  @langversion 3.0
         *  @playerversion Flash 10.2
         *  @playerversion AIR 2.6
         *  @productversion FlexJS 0.0
         */
		public function get text():String
		{
			return _textField.text;
		}

        /**
         *  @private
         */
        public function set text(value:String):void
		{
            if (value == null)
                value = "";
			_textField.text = value;
            autoSizeIfNeeded();
		}

        private function autoSizeIfNeeded():void
        {
            var host:UIBase = UIBase(_strand);
            if (autoHeight)
            {
                if (textField.height != textField.textHeight + 4)
                {
                    textField.height = textField.textHeight + 4;
                    inHeightChange = true;
                    host.dispatchEvent(new Event("heightChanged"));
                    inHeightChange = false;
                }
            }
            if (autoWidth)
            {
                if (textField.width != textField.textWidth + 4)
                {
                    textField.width = textField.textWidth + 4;
                    inWidthChange = true;
                    host.dispatchEvent(new Event("widthChanged"));
                    inWidthChange = false;
                }
            }
        }

        /**
         *  @copy org.apache.flex.core.ITextModel#html
         *
         *  @langversion 3.0
         *  @playerversion Flash 10.2
         *  @playerversion AIR 2.6
         *  @productversion FlexJS 0.0
         */
		public function get html():String
		{
			return _textField.htmlText;
		}

        /**
         *  @private
         */
        public function set html(value:String):void
		{
			_textField.htmlText = value;
            autoSizeIfNeeded();
		}

		private function textChangeHandler(event:Event):void
		{
			text = _textModel.text;
		}

		private function htmlChangeHandler(event:Event):void
		{
			html = _textModel.html;
		}

        private var autoHeight:Boolean;
        private var autoWidth:Boolean;
        private var inHeightChange:Boolean = false;
        private var inWidthChange:Boolean = false;

		private function widthChangeHandler(event:Event):void
		{
            if (!inWidthChange)
            {
                textField.autoSize = "none";
                autoWidth = false;
    			textField.width = DisplayObject(_strand).width;
                if (autoHeight)
        	        autoSizeIfNeeded()
                else
                    textField.height = DisplayObject(_strand).height;
            }
		}

        private function heightChangeHandler(event:Event):void
        {
            if (!inHeightChange)
            {
                textField.autoSize = "none";
                autoHeight = false;
                textField.height = DisplayObject(_strand).height;
                if (autoWidth)
                    autoSizeIfNeeded();
                else
                    textField.width = DisplayObject(_strand).width;
            }
        }

        private function sizeChangeHandler(event:Event):void
        {
            var ilc:ILayoutChild = host as ILayoutChild;

            autoHeight = ilc.isHeightSizedToContent();
            if (!autoHeight)
            {
                textField.autoSize = "none";
                textField.height = DisplayObject(_strand).height;
            }

            autoWidth = ilc.isWidthSizedToContent();
            if (!autoWidth)
            {
                textField.autoSize = "none";
                textField.width = DisplayObject(_strand).width;
            }
        }

        /**
         *  @copy org.apache.flex.core.IBeadView#viewHeight
         *
         *  @langversion 3.0
         *  @playerversion Flash 10.2
         *  @playerversion AIR 2.6
         *  @productversion FlexJS 0.0
         */
        public function get viewHeight():Number
        {
            // textfields with autosize collapse if no text
            if (_textField.text == "" && autoHeight)
                return ValuesManager.valuesImpl.getValue(_strand, "fontSize") + 4;

            return _textField.height;
        }

        /**
         *  @copy org.apache.flex.core.IBeadView#viewWidth
         *
         *  @langversion 3.0
         *  @playerversion Flash 10.2
         *  @playerversion AIR 2.6
         *  @productversion FlexJS 0.0
         */
        public function get viewWidth():Number
        {
            // textfields with autosize collapse if no text
            if (_textField.text == "" && autoWidth)
                return 0;

            return _textField.width;
        }

    }
}

////////////////////////////////////////////////////////////////////////////////
//
//  Licensed to the Apache Software Foundation (ASF) under one or more
//  contributor license agreements.  See the NOTICE file distributed with
//  this work for additional information regarding copyright ownership.
//  The ASF licenses this file to You under the Apache License, Version 2.0
//  (the "License"); you may not use this file except in compliance with
//  the License.  You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
//  Unless required by applicable law or agreed to in writing, software
//  distributed under the License is distributed on an "AS IS" BASIS,
//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//  See the License for the specific language governing permissions and
//  limitations under the License.
//
////////////////////////////////////////////////////////////////////////////////
package org.apache.flex.html.beads
{
	import flash.display.DisplayObject;
	import flash.display.DisplayObjectContainer;
	import flash.text.StyleSheet;

	import org.apache.flex.core.CSSTextField;
	import org.apache.flex.core.IBeadView;
	import org.apache.flex.core.ILayoutChild;
	import org.apache.flex.core.IStrand;
	import org.apache.flex.core.ITextModel;
	import org.apache.flex.core.IUIBase;
	import org.apache.flex.core.UIBase;
	import org.apache.flex.core.ValuesManager;
	import org.apache.flex.events.Event;
	import org.apache.flex.events.IEventDispatcher;

    /**
     *  The TextFieldViewBase class is the base class for
     *  the components that display text.
     *  It displays text using a TextField, so there is no
     *  right-to-left text support in this view.
     *
     *  @langversion 3.0
     *  @playerversion Flash 10.2
     *  @playerversion AIR 2.6
     *  @productversion FlexJS 0.0
     */
	public class TextFieldViewBase implements IBeadView, ITextFieldView
	{
        /**
         *  Constructor.
         *
         *  @langversion 3.0
         *  @playerversion Flash 10.2
         *  @playerversion AIR 2.6
         *  @productversion FlexJS 0.0
         */
		public function TextFieldViewBase()
		{
			_textField = new CSSTextField();
		}

		private var _textField:CSSTextField;

        /**
         *  @copy org.apache.flex.core.ITextModel#textField
         *
         *  @langversion 3.0
         *  @playerversion Flash 10.2
         *  @playerversion AIR 2.6
         *  @productversion FlexJS 0.0
         */
		public function get textField() : CSSTextField
		{
			return _textField;
		}

		private var _textModel:ITextModel;

		protected var _strand:IStrand;

        /**
         *  @copy org.apache.flex.core.IBead#strand
         *
         *  @langversion 3.0
         *  @playerversion Flash 10.2
         *  @playerversion AIR 2.6
         *  @productversion FlexJS 0.0
         */
		public function set strand(value:IStrand):void
		{
			_strand = value;
			_textModel = value.getBeadByType(ITextModel) as ITextModel;
            _textModel.addEventListener("textChange", textChangeHandler);
            _textModel.addEventListener("htmlChange", htmlChangeHandler);
            IEventDispatcher(_strand).addEventListener("widthChanged", widthChangeHandler);
            IEventDispatcher(_strand).addEventListener("heightChanged", heightChangeHandler);
            IEventDispatcher(_strand).addEventListener("sizeChanged", sizeChangeHandler);
			DisplayObjectContainer(value).addChild(_textField);
			if (_textModel.text !== null)
				text = _textModel.text;
			if (_textModel.html !== null)
				html = _textModel.html;

            var ilc:ILayoutChild = host as ILayoutChild;

            autoHeight = ilc.isHeightSizedToContent();
            autoWidth = ilc.isWidthSizedToContent();
            if (!autoWidth && !isNaN(ilc.explicitWidth))
            {
                widthChangeHandler(null);
            }
            if (!autoHeight && !isNaN(ilc.explicitHeight))
            {
                heightChangeHandler(null);
            }
		}

        /**
         *  @private
         */
		public function get host() : IUIBase
		{
			return _strand as IUIBase;
		}

        /**
         *  @copy org.apache.flex.core.ITextModel#text
         *
         *  @langversion 3.0
         *  @playerversion Flash 10.2
         *  @playerversion AIR 2.6
         *  @productversion FlexJS 0.0
         */
		public function get text():String
		{
			return _textField.text;
		}

        /**
         *  @private
         */
        public function set text(value:String):void
		{
            if (value == null)
                value = "";
			_textField.text = value;
            autoSizeIfNeeded();
		}

        private function autoSizeIfNeeded():void
        {
            var host:UIBase = UIBase(_strand);
            if (autoHeight)
            {
                if (textField.height != textField.textHeight + 4)
                {
                    textField.height = textField.textHeight + 4;
                    inHeightChange = true;
                    host.dispatchEvent(new Event("heightChanged"));
                    inHeightChange = false;
                }
            }
            if (autoWidth)
            {
                if (textField.width != textField.textWidth + 4)
                {
                    textField.width = textField.textWidth + 4;
                    inWidthChange = true;
                    host.dispatchEvent(new Event("widthChanged"));
                    inWidthChange = false;
                }
            }
        }

        /**
         *  @copy org.apache.flex.core.ITextModel#html
         *
         *  @langversion 3.0
         *  @playerversion Flash 10.2
         *  @playerversion AIR 2.6
         *  @productversion FlexJS 0.0
         */
		public function get html():String
		{
			return _textField.htmlText;
		}

        /**
         *  @private
         */
        public function set html(value:String):void
		{
			convertToTextFieldHTML(value);
            autoSizeIfNeeded();
		}

        private function convertToTextFieldHTML(input:String):void
        {
            var classCount:int = 0;
            var ss:StyleSheet;
            var c:int = input.indexOf("<span");
            while (c != -1)
            {
                var c1:int = input.indexOf(">", c);
                if (c1 == -1)
                {
                    trace("did not parse span correctly");
                    return;
                }
                var tag:String = input.substring(c, c1 + 1);
                var c2:int = tag.indexOf("style=");
                if (c2 != -1)
                {
                    var quote:String = tag.charAt(c2 + 6);
                    var c3:int = tag.indexOf(quote, c2 + 7);
                    if (c3 != -1)
                    {
                        var styles:String = tag.substring(c2 + 7, c3);
                        if (!ss)
                            ss = new StyleSheet();
                        var styleObject:Object = {};
                        var list:Array = styles.split(";");
                        for each (var pair:String in list)
                        {
                            var parts:Array = pair.split(":");
                            var name:String = parts[0];
                            var c4:int = name.indexOf("-");
                            if (c4 != -1)
                            {
                                var firstChar:String = name.charAt(c4 + 1);
                                firstChar = firstChar.toUpperCase();
                                var tail:String = name.substring(c4 + 2);
                                name = name.substring(0, c4) + firstChar + tail;
                            }
                            styleObject[name] = parts[1];
                        }
                        var className:String = "css" + classCount++;
                        ss.setStyle("." + className, styleObject);
                        var newTag:String = "<span class='" + className + "'>";
                        input = input.replace(tag, newTag);
                        c1 += newTag.length - tag.length;
                    }
                }
                c = input.indexOf("<span", c1);
            }
            _textField.styleSheet = ss;
            _textField.htmlText = input;
        }

		private function textChangeHandler(event:Event):void
		{
			text = _textModel.text;
		}

		private function htmlChangeHandler(event:Event):void
		{
			html = _textModel.html;
		}

        private var autoHeight:Boolean;
        private var autoWidth:Boolean;
        private var inHeightChange:Boolean = false;
        private var inWidthChange:Boolean = false;

		private function widthChangeHandler(event:Event):void
		{
            if (!inWidthChange)
            {
                textField.autoSize = "none";
                autoWidth = false;
    			textField.width = DisplayObject(_strand).width;
                if (autoHeight)
        	        autoSizeIfNeeded()
                else
                    textField.height = DisplayObject(_strand).height;
            }
		}

        private function heightChangeHandler(event:Event):void
        {
            if (!inHeightChange)
            {
                textField.autoSize = "none";
                autoHeight = false;
                textField.height = DisplayObject(_strand).height;
                if (autoWidth)
                    autoSizeIfNeeded();
                else
                    textField.width = DisplayObject(_strand).width;
            }
        }

        private function sizeChangeHandler(event:Event):void
        {
            var ilc:ILayoutChild = host as ILayoutChild;

            autoHeight = ilc.isHeightSizedToContent();
            if (!autoHeight)
            {
                textField.autoSize = "none";
                textField.height = DisplayObject(_strand).height;
            }

            autoWidth = ilc.isWidthSizedToContent();
            if (!autoWidth)
            {
                textField.autoSize = "none";
                textField.width = DisplayObject(_strand).width;
            }
        }

        /**
         *  @copy org.apache.flex.core.IBeadView#viewHeight
         *
         *  @langversion 3.0
         *  @playerversion Flash 10.2
         *  @playerversion AIR 2.6
         *  @productversion FlexJS 0.0
         */
        public function get viewHeight():Number
        {
            // textfields with autosize collapse if no text
            if (_textField.text == "" && autoHeight)
                return ValuesManager.valuesImpl.getValue(_strand, "fontSize") + 4;

            return _textField.height;
        }

        /**
         *  @copy org.apache.flex.core.IBeadView#viewWidth
         *
         *  @langversion 3.0
         *  @playerversion Flash 10.2
         *  @playerversion AIR 2.6
         *  @productversion FlexJS 0.0
         */
        public function get viewWidth():Number
        {
            // textfields with autosize collapse if no text
            if (_textField.text == "" && autoWidth)
                return 0;

            return _textField.width;
        }

    }
}

handle spans better in html

handle spans better in html


/*
#
# Copyright (c) 2008 rPath, Inc.
#
# This program is distributed under the terms of the MIT License as found
# in a file called LICENSE. If it is not present, the license
# is always available at http://www.opensource.org/licenses/mit-license.php.
#
# This program is distributed in the hope that it will be useful, but
# without any waranty; without even the implied warranty of merchantability
# or fitness for a particular purpose. See the MIT License for full details.
*/

package com.rpath.xobj
{

    [RemoteClass]  // tell the compiler we can be deep copied
    public class XObjMetadata
    {
        public var attributes:Array;
        public var elements:Array;
        //public var namespaces:Array;

        public static const METADATA_PROPERTY:String = "_xobj";

        public function XObjMetadata()
        {

            super();

            attributes = [];
            elements = [];
            //namespaces = [];
        }

        private static function getMetadata(target:*):XObjMetadata
        {
           var result:XObjMetadata = null;

           if (METADATA_PROPERTY in target)
           {
                result = target[METADATA_PROPERTY];
           }
           else
           {
               // doesn't exist. Try creating it
               try
               {
                   target[METADATA_PROPERTY] = new XObjMetadata();
                   result = target[METADATA_PROPERTY];
               }
               catch (e:Error)
               {
                   // must be nondynamic type
               }
            }

            return result;
        }

        public static function setElements(target:*, elements:Array):void
        {
            var xobj:XObjMetadata = getMetadata(target);
            if (xobj)
            {
               xobj.elements = elements;
            }
        }

        public static function setAttributes(target:*, attributes:Array):void
        {
            var xobj:XObjMetadata = getMetadata(target);
            if (xobj)
            {
                if (attributes.length == 0)
                    trace("damn!");

                xobj.attributes = attributes;
            }
        }

        public function addAttribute(entry:*):void
        {
            attributes.push(entry);
        }

        public function addElement(entry:*):void
        {
            elements.push(entry);
        }

    }
}

/*
#
# Copyright (c) 2008 rPath, Inc.
#
# This program is distributed under the terms of the MIT License as found
# in a file called LICENSE. If it is not present, the license
# is always available at http://www.opensource.org/licenses/mit-license.php.
#
# This program is distributed in the hope that it will be useful, but
# without any waranty; without even the implied warranty of merchantability
# or fitness for a particular purpose. See the MIT License for full details.
*/

package com.rpath.xobj
{

    [RemoteClass]  // tell the compiler we can be deep copied
    public class XObjMetadata
    {
        public var attributes:Array;
        public var elements:Array;
        //public var namespaces:Array;

        public static const METADATA_PROPERTY:String = "_xobj";

        public function XObjMetadata()
        {

            super();

            attributes = [];
            elements = [];
            //namespaces = [];
        }

        private static function getMetadata(target:*):XObjMetadata
        {
           var result:XObjMetadata = null;

           if (METADATA_PROPERTY in target)
           {
                result = target[METADATA_PROPERTY];
           }
           else
           {
               // doesn't exist. Try creating it
               try
               {
                   target[METADATA_PROPERTY] = new XObjMetadata();
                   target.setPropertyIsEnumerable(METADATA_PROPERTY, false);
                   result = target[METADATA_PROPERTY];
               }
               catch (e:Error)
               {
                   // must be nondynamic type
               }
            }

            return result;
        }

        public static function setElements(target:*, elements:Array):void
        {
            var xobj:XObjMetadata = getMetadata(target);
            if (xobj)
            {
               xobj.elements = elements;
            }
        }

        public static function setAttributes(target:*, attributes:Array):void
        {
            var xobj:XObjMetadata = getMetadata(target);
            if (xobj)
            {
                if (attributes.length == 0)
                    trace("damn!");

                xobj.attributes = attributes;
            }
        }

        public function addAttribute(entry:*):void
        {
            attributes.push(entry);
        }

        public function addElement(entry:*):void
        {
            elements.push(entry);
        }

    }
}

Set the _xobj metadata property to be non-enumerable so that it does not contaminate for each (in) constructs