////////////////////////////////////////////////////////////////////////////////
//
//  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 org.apache.flex.core.BeadViewBase;
	import org.apache.flex.core.IAlertModel;
	import org.apache.flex.core.IBead;
    import org.apache.flex.core.IBeadView;
	import org.apache.flex.core.IMeasurementBead;
	import org.apache.flex.core.IStrand;
    import org.apache.flex.core.IParent;
	import org.apache.flex.core.UIBase;
	import org.apache.flex.core.ValuesManager;
	import org.apache.flex.events.Event;
	import org.apache.flex.events.IEventDispatcher;
    import org.apache.flex.geom.Rectangle;
	import org.apache.flex.html.Label;
	import org.apache.flex.html.TextButton;
    import org.apache.flex.utils.CSSContainerUtils;

	/**
	 *  The SimpleAlertView class creates the visual elements of the
	 *  org.apache.flex.html.SimpleAlert component.
	 *
	 *  @langversion 3.0
	 *  @playerversion Flash 10.2
	 *  @playerversion AIR 2.6
	 *  @productversion FlexJS 0.0
	 */
	public class SimpleAlertView extends BeadViewBase implements IBeadView
	{
		/**
		 *  constructor.
		 *
		 *  @langversion 3.0
		 *  @playerversion Flash 10.2
		 *  @playerversion AIR 2.6
		 *  @productversion FlexJS 0.0
		 */
		public function SimpleAlertView()
		{
		}

		private var messageLabel:Label;
		private var okButton:TextButton;

		/**
		 *  @copy org.apache.flex.core.IBead#strand
		 *
		 *  @langversion 3.0
		 *  @playerversion Flash 10.2
		 *  @playerversion AIR 2.6
		 *  @productversion FlexJS 0.0
		 */
		override public function set strand(value:IStrand):void
		{
			super.strand = value;

			var backgroundColor:Object = ValuesManager.valuesImpl.getValue(value, "background-color");
			var backgroundImage:Object = ValuesManager.valuesImpl.getValue(value, "background-image");
			if (backgroundColor != null || backgroundImage != null)
			{
				if (value.getBeadByType(IBackgroundBead) == null)
					value.addBead(new (ValuesManager.valuesImpl.getValue(value, "iBackgroundBead")) as IBead);
			}

			var borderStyle:String;
			var borderStyles:Object = ValuesManager.valuesImpl.getValue(value, "border");
			if (borderStyles is Array)
			{
				borderStyle = borderStyles[1];
			}
			if (borderStyle == null)
			{
				borderStyle = ValuesManager.valuesImpl.getValue(value, "border-style") as String;
			}
			if (borderStyle != null && borderStyle != "none")
			{
				if (value.getBeadByType(IBorderBead) == null)
					value.addBead(new (ValuesManager.valuesImpl.getValue(value, "iBorderBead")) as IBead);
			}

			var model:IAlertModel = _strand.getBeadByType(IAlertModel) as IAlertModel;
			model.addEventListener("messageChange",handleMessageChange);
			model.addEventListener("htmlMessageChange",handleMessageChange);

            messageLabel = new Label();
			messageLabel.text = model.message;
			messageLabel.html = model.htmlMessage;
			IParent(_strand).addElement(messageLabel);

			okButton = new TextButton();
			okButton.text = model.okLabel;
			IParent(_strand).addElement(okButton);
			okButton.addEventListener("click",handleOK);

			handleMessageChange(null);
		}

		/**
		 * @private
		 */
		private function handleMessageChange(event:Event):void
		{
			var ruler:IMeasurementBead = messageLabel.getBeadByType(IMeasurementBead) as IMeasurementBead;
			if( ruler == null ) {
				messageLabel.addBead(ruler = new (ValuesManager.valuesImpl.getValue(messageLabel, "iMeasurementBead")) as IMeasurementBead);
			}
			var maxWidth:Number = Math.max(UIBase(_strand).width,ruler.measuredWidth);

			var metrics:Rectangle = CSSContainerUtils.getBorderAndPaddingMetrics(_strand);

			messageLabel.x = metrics.left;
			messageLabel.y = metrics.top;
			messageLabel.width = maxWidth;

			okButton.x = (maxWidth - okButton.width)/2;
			okButton.y = messageLabel.y + messageLabel.height + 20;

			UIBase(_strand).width = maxWidth + metrics.left + metrics.right;
			UIBase(_strand).height = okButton.y + okButton.height + metrics.bottom;
		}

		/**
		 * @private
		 */
		private function handleOK(event:Event):void
		{
			var newEvent:Event = new Event("close");
			IEventDispatcher(_strand).dispatchEvent(newEvent);
		}
	}
}

////////////////////////////////////////////////////////////////////////////////
//
//  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 org.apache.flex.core.BeadViewBase;
    import org.apache.flex.core.IAlertModel;
    import org.apache.flex.core.IBead;
    import org.apache.flex.core.IBeadView;
    import org.apache.flex.core.IMeasurementBead;
    import org.apache.flex.core.IParent;
    import org.apache.flex.core.IStrand;
    import org.apache.flex.core.UIBase;
    import org.apache.flex.core.ValuesManager;
    import org.apache.flex.events.Event;
    import org.apache.flex.events.IEventDispatcher;
    import org.apache.flex.events.MouseEvent;
    import org.apache.flex.geom.Rectangle;
    import org.apache.flex.html.Label;
    import org.apache.flex.html.TextButton;
    import org.apache.flex.utils.CSSContainerUtils;

	/**
	 *  The SimpleAlertView class creates the visual elements of the
	 *  org.apache.flex.html.SimpleAlert component.
	 *
	 *  @langversion 3.0
	 *  @playerversion Flash 10.2
	 *  @playerversion AIR 2.6
	 *  @productversion FlexJS 0.0
	 */
	public class SimpleAlertView extends BeadViewBase implements IBeadView
	{
		/**
		 *  constructor.
		 *
		 *  @langversion 3.0
		 *  @playerversion Flash 10.2
		 *  @playerversion AIR 2.6
		 *  @productversion FlexJS 0.0
		 */
		public function SimpleAlertView()
		{
		}

		private var messageLabel:Label;
		private var okButton:TextButton;

		/**
		 *  @copy org.apache.flex.core.IBead#strand
		 *
		 *  @langversion 3.0
		 *  @playerversion Flash 10.2
		 *  @playerversion AIR 2.6
		 *  @productversion FlexJS 0.0
		 */
		override public function set strand(value:IStrand):void
		{
			super.strand = value;

			var backgroundColor:Object = ValuesManager.valuesImpl.getValue(value, "background-color");
			var backgroundImage:Object = ValuesManager.valuesImpl.getValue(value, "background-image");
			if (backgroundColor != null || backgroundImage != null)
			{
				if (value.getBeadByType(IBackgroundBead) == null)
					value.addBead(new (ValuesManager.valuesImpl.getValue(value, "iBackgroundBead")) as IBead);
			}

			var borderStyle:String;
			var borderStyles:Object = ValuesManager.valuesImpl.getValue(value, "border");
			if (borderStyles is Array)
			{
				borderStyle = borderStyles[1];
			}
			if (borderStyle == null)
			{
				borderStyle = ValuesManager.valuesImpl.getValue(value, "border-style") as String;
			}
			if (borderStyle != null && borderStyle != "none")
			{
				if (value.getBeadByType(IBorderBead) == null)
					value.addBead(new (ValuesManager.valuesImpl.getValue(value, "iBorderBead")) as IBead);
			}

			var model:IAlertModel = _strand.getBeadByType(IAlertModel) as IAlertModel;
			model.addEventListener("messageChange",handleMessageChange);
			model.addEventListener("htmlMessageChange",handleMessageChange);

            messageLabel = new Label();
			messageLabel.text = model.message;
			messageLabel.html = model.htmlMessage;
			IParent(_strand).addElement(messageLabel);

			okButton = new TextButton();
			okButton.text = model.okLabel;
			IParent(_strand).addElement(okButton);
			okButton.addEventListener("click",handleOK);

			handleMessageChange(null);
		}

		/**
		 * @private
		 */
		private function handleMessageChange(event:Event):void
		{
			var ruler:IMeasurementBead = messageLabel.getBeadByType(IMeasurementBead) as IMeasurementBead;
			if( ruler == null ) {
				messageLabel.addBead(ruler = new (ValuesManager.valuesImpl.getValue(messageLabel, "iMeasurementBead")) as IMeasurementBead);
			}
			var maxWidth:Number = Math.max(UIBase(_strand).width,ruler.measuredWidth);

			var metrics:Rectangle = CSSContainerUtils.getBorderAndPaddingMetrics(_strand);

			messageLabel.x = metrics.left;
			messageLabel.y = metrics.top;
			messageLabel.width = maxWidth;

			okButton.x = (maxWidth - okButton.width)/2;
			okButton.y = messageLabel.y + messageLabel.height + 20;

			UIBase(_strand).width = maxWidth + metrics.left + metrics.right;
			UIBase(_strand).height = okButton.y + okButton.height + metrics.bottom;
		}

		/**
		 * @private
		 */
		private function handleOK(event:MouseEvent):void
		{
			var newEvent:Event = new Event("close");
			IEventDispatcher(_strand).dispatchEvent(newEvent);
		}
	}
}

Fix ticket

Fix ticket

FLEX-35103


package org.servebox.cafe.core.command
{
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.events.IEventDispatcher;

	import org.servebox.cafe.core.signal.SignalAggregator;

	public class AbstractStateCommand extends EventDispatcher implements IStateCommand
	{
		public function AbstractStateCommand(target:IEventDispatcher=null)
		{
			super(target);
		}

		[Autowired]
		public var signalAggregator : SignalAggregator;

		private var _parameters : Array;

		public function get executable():Boolean
		{
			return true;
		}

		public function set executable(value:Boolean):void
		{
		}

		public function get parameters():Array
		{
			if ( _parameters == null )
			{
				_parameters = new Array();
			}
			return _parameters;
		}

		public function set parameters(value:Array):void
		{
			_parameters = value;
		}

		protected function getParameter( key : String ) : IParameterObject
		{
			var paramToReturn : IParameterObject;
			for each ( var param : IParameterObject in _parameters )
			{
				if ( param.key == key )
				{
					paramToReturn = param;
				}
			}
			if ( !paramToReturn )
			{
				throw new Error("No parameter " + key + " in " + this + " command, check command binding ");
			}
			return paramToReturn;
		}

		public function addParameter( key : String , value : Object ) : void
		{
			var param : AbstractParameterObject = new AbstractParameterObject( key, value );
			parameters.push( param );
		}

		public function execute( e : Event = null ) : void
		{
		}
	}
}

package org.servebox.cafe.core.command
{
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.events.IEventDispatcher;

	import org.servebox.cafe.core.signal.SignalAggregator;

	public class AbstractStateCommand extends EventDispatcher implements IStateCommand
	{
		public function AbstractStateCommand(target:IEventDispatcher=null)
		{
			super(target);
		}

		[Autowired]
		public var signalAggregator : SignalAggregator;

		private var _parameters : Array;

		public function get executable():Boolean
		{
			return true;
		}

		public function set executable(value:Boolean):void
		{
		}

		public function get parameters():Array
		{
			if ( _parameters == null )
			{
				_parameters = new Array();
			}
			return _parameters;
		}

		public function set parameters(value:Array):void
		{
			_parameters = value;
		}

		protected function getParameter( key : String ) : IParameterObject
		{
			var paramToReturn : IParameterObject;
			for each ( var param : IParameterObject in _parameters )
			{
				if ( param.key == key )
				{
					paramToReturn = param;
					if ( paramToReturn.value == null )
					{
						throw new Error("Parameter value for " + key + " in " + this + " is null, check command binding ");
					}
				}
			}
			if ( !paramToReturn )
			{
				throw new Error("No parameter " + key + " in " + this + " command, check command binding ");
			}
			return paramToReturn;
		}

		public function addParameter( key : String , value : Object ) : void
		{
			var param : AbstractParameterObject = new AbstractParameterObject( key, value );
			parameters.push( param );
		}

		public function execute( e : Event = null ) : void
		{
		}
	}
}

Add throw error for parameter value.

Add throw error for parameter value.


package dolly {

import dolly.core.dolly_internal;
import dolly.core.errors.CloningError;
import dolly.core.metadata.MetadataName;
import dolly.utils.ClassUtil;

import flash.utils.ByteArray;
import flash.utils.Dictionary;

import org.as3commons.reflect.Accessor;
import org.as3commons.reflect.AccessorAccess;
import org.as3commons.reflect.Field;
import org.as3commons.reflect.Type;

use namespace dolly_internal;

public class Cloner {

	private static var _isClassPreparedForCloningMap:Dictionary = new Dictionary();

	private static function isTypeCloneable(type:Type):Boolean {
		return type.hasMetadata(MetadataName.CLONEABLE);
	}

	private static function isTypePreparedForCloning(type:Type):Boolean {
		return _isClassPreparedForCloningMap[type.clazz];
	}

	private static function failIfTypeIsNotCloneable(type:Type):void {
		if (!isTypeCloneable(type)) {
			throw new CloningError(
					CloningError.CLASS_IS_NOT_CLONEABLE_MESSAGE,
					CloningError.CLASS_IS_NOT_CLONEABLE_CODE
			);
		}
	}

	private static function prepareTypeForCloning(type:Type):void {
		if (isTypePreparedForCloning(type)) {
			return;
		}

		ClassUtil.registerAliasFor(type.clazz);

		_isClassPreparedForCloningMap[type.clazz] = true;

		const fieldsToClone:Vector.<Field> = findAllWritableFieldsForType(type);
		for each(var field:Field in fieldsToClone) {
			var fieldType:Type = field.type;
			if (isTypeCloneable(fieldType)) {
				prepareTypeForCloning(fieldType);
			}
		}
	}

	dolly_internal static function findAllWritableFieldsForType(type:Type):Vector.<Field> {
		failIfTypeIsNotCloneable(type);

		if (!isTypePreparedForCloning(type)) {
			prepareTypeForCloning(type);
		}

		const result:Vector.<Field> = new Vector.<Field>();

		for each(var field:Field in type.properties) {
			if (!(field is Accessor) || (field as Accessor).access == AccessorAccess.READ_WRITE) {
				result.push(field);
			}
		}

		return result;
	}

	dolly_internal static function doClone(source:*, type:Type = null):* {
		if (!type) {
			type = Type.forInstance(source);
		}

		prepareTypeForCloning(type);

		const byteArray:ByteArray = new ByteArray();
		byteArray.writeObject(source);
		byteArray.position = 0;

		const clonedInstance:* = byteArray.readObject();

		return clonedInstance;
	}

	public static function clone(source:*):* {
		const type:Type = Type.forInstance(source);

		failIfTypeIsNotCloneable(type);

		return doClone(source, type);
	}
}
}

package dolly {

import dolly.core.dolly_internal;
import dolly.core.errors.CloningError;
import dolly.core.metadata.MetadataName;
import dolly.utils.ClassUtil;

import flash.utils.ByteArray;
import flash.utils.Dictionary;

import org.as3commons.reflect.Accessor;
import org.as3commons.reflect.AccessorAccess;
import org.as3commons.reflect.Field;
import org.as3commons.reflect.Type;

use namespace dolly_internal;

public class Cloner {

	private static var _isClassPreparedForCloningMap:Dictionary = new Dictionary();

	private static function isTypeCloneable(type:Type):Boolean {
		return type.hasMetadata(MetadataName.CLONEABLE);
	}

	private static function isTypePreparedForCloning(type:Type):Boolean {
		return _isClassPreparedForCloningMap[type.clazz];
	}

	private static function failIfTypeIsNotCloneable(type:Type):void {
		if (!isTypeCloneable(type)) {
			throw new CloningError(
					CloningError.CLASS_IS_NOT_CLONEABLE_MESSAGE,
					CloningError.CLASS_IS_NOT_CLONEABLE_CODE
			);
		}
	}

	private static function prepareTypeForCloning(type:Type):void {
		if (isTypePreparedForCloning(type)) {
			return;
		}

		ClassUtil.registerAliasFor(type.clazz);

		_isClassPreparedForCloningMap[type.clazz] = true;

		const fieldsToClone:Vector.<Field> = findAllWritableFieldsForType(type);
		for each(var field:Field in fieldsToClone) {
			var fieldType:Type = field.type;
			if (isTypeCloneable(fieldType)) {
				prepareTypeForCloning(fieldType);
			}
		}
	}

	dolly_internal static function findAllWritableFieldsForType(type:Type):Vector.<Field> {
		failIfTypeIsNotCloneable(type);

		if (!isTypePreparedForCloning(type)) {
			prepareTypeForCloning(type);
		}

		const result:Vector.<Field> = new Vector.<Field>();

		for each(var field:Field in type.properties) {
			if (!(field is Accessor) || (field as Accessor).access == AccessorAccess.READ_WRITE) {
				result.push(field);
			}
		}

		return result;
	}

	dolly_internal static function doClone(source:*):* {
		const byteArray:ByteArray = new ByteArray();
		byteArray.writeObject(source);
		byteArray.position = 0;
		return byteArray.readObject();
	}

	public static function clone(source:*):* {
		const type:Type = Type.forInstance(source);

		failIfTypeIsNotCloneable(type);
		prepareTypeForCloning(type);

		return doClone(source);
	}
}
}

Refactor method Cloner.doClone(): currently it only do cloning of objects by using ByteArray.


package dolly {

import dolly.core.dolly_internal;
import dolly.data.PropertyLevelCloneableClass;

import org.as3commons.reflect.Type;

use namespace dolly_internal;

public class CloningOfPropertyLevelCloneableClassTest {

	private var propertyLevelCloneable:PropertyLevelCloneableClass;
	private var propertyLevelCloneableType:Type;

	[Before]
	public function before():void {
		propertyLevelCloneable = new PropertyLevelCloneableClass();
		propertyLevelCloneable.property1 = "property1 value";
		propertyLevelCloneable.writableField1 = "writableField1 value";
		propertyLevelCloneableType = Type.forInstance(propertyLevelCloneable);
	}

	[After]
	public function after():void {
		propertyLevelCloneable = null;
		propertyLevelCloneableType = null;
	}

	/**
	 * Cloner.findingAllWritableFieldsForType() method will throw CloningError in this case
	 * because PropertyLevelCloneable class is not cloneable indeed.
	 */
	[Test(expects="dolly.core.errors.CloningError")]
	public function findingAllWritableFieldsForType():void {
		Cloner.findAllWritableFieldsForType(propertyLevelCloneableType);
	}

	/**
	 * Cloner.clone() method will throw CloningError in this case
	 * because PropertyLevelCloneable class is not cloneable indeed.
	 */
	[Test(expects="dolly.core.errors.CloningError")]
	public function cloningByCloner():void {
		Cloner.clone(propertyLevelCloneable);
	}

	/**
	 * Method clone() will throw CloningError in this case
	 * because PropertyLevelCloneable class is not cloneable indeed.
	 */
	[Test(expects="dolly.core.errors.CloningError")]
	public function cloningByCloneFunction():void {
		clone(propertyLevelCloneable);
	}

}
}

package dolly {

import dolly.core.dolly_internal;
import dolly.data.PropertyLevelCloneableClass;

import org.as3commons.reflect.Type;

use namespace dolly_internal;

public class CloningOfPropertyLevelCloneableClassTest {

	private var propertyLevelCloneable:PropertyLevelCloneableClass;
	private var propertyLevelCloneableType:Type;

	[Before]
	public function before():void {
		propertyLevelCloneable = new PropertyLevelCloneableClass();
		propertyLevelCloneable.property1 = "property1 value";
		propertyLevelCloneable.writableField1 = "writableField1 value";
		propertyLevelCloneableType = Type.forInstance(propertyLevelCloneable);
	}

	[After]
	public function after():void {
		propertyLevelCloneable = null;
		propertyLevelCloneableType = null;
	}

	/**
	 * Cloner.findingAllWritableFieldsForType() method will throw CloningError in this case
	 * because PropertyLevelCloneableClass class is not cloneable indeed.
	 */
	[Test(expects="dolly.core.errors.CloningError")]
	public function findingAllWritableFieldsForType():void {
		Cloner.findAllWritableFieldsForType(propertyLevelCloneableType);
	}

	/**
	 * Cloner.clone() method will throw CloningError in this case
	 * because PropertyLevelCloneableClass class is not cloneable indeed.
	 */
	[Test(expects="dolly.core.errors.CloningError")]
	public function cloningByCloner():void {
		Cloner.clone(propertyLevelCloneable);
	}

	/**
	 * Method clone() will throw CloningError in this case
	 * because PropertyLevelCloneableClass class is not cloneable indeed.
	 */
	[Test(expects="dolly.core.errors.CloningError")]
	public function cloningByCloneFunction():void {
		clone(propertyLevelCloneable);
	}

}
}

Fix ASDoc.

Fix ASDoc.


package flump.export {

import aspire.util.StringUtil;

import flash.events.ErrorEvent;
import flash.events.UncaughtErrorEvent;
import flash.filesystem.File;
import flash.filesystem.FileMode;
import flash.filesystem.FileStream;

import flump.executor.Executor;
import flump.executor.Future;
import flump.xfl.ParseError;
import flump.xfl.XflLibrary;

import react.BoolValue;
import react.BoolView;

/**
 * This class expects to be run from the command-line script found at rsrc/flump-export. It sends
 * output to File.applicationDirectory.nativePath + "/exporter.log" rather than spawning any
 * UI windows for user interaction, and acts as though the user pressed the export all button, then
 * shuts down.
 */
public class AutomaticExporter {
    public function AutomaticExporter (project :File) {
        _complete.connect(function (complete :Boolean) :void {
            if (!complete) return;
            if (OUT != null) {
                OUT.close();
                OUT = null;
            }
        });

        FlumpApp.app.loaderInfo.uncaughtErrorEvents
            .addEventListener(UncaughtErrorEvent.UNCAUGHT_ERROR, exit);

        var outFile :File = new File(File.applicationDirectory.nativePath + "/exporter.log");
        OUT = new FileStream();
        OUT.open(outFile, FileMode.WRITE);

        _confFile = project;
        exportProject();
    }

    public function get complete () :BoolView { return _complete; }

    public function get projectName () :String {
        return (_confFile != null ? _confFile.name.replace(/\.flump$/i, "") : "Untitled Project");
    }

    protected function exportProject () :void {
        println("Exporting project: " + _confFile.nativePath);
        println();

        try {
            _conf = ProjectConf.fromJSON(JSONFormat.readJSON(_confFile));
            _importDirectory = new File(_confFile.parent.resolvePath(_conf.importDir).nativePath);
            if (!_importDirectory.exists || !_importDirectory.isDirectory) {
                exit(new ParseError(_confFile.nativePath, ParseError.CRIT,
                    "Import directory doesn't exist (" + _importDirectory.nativePath + ")"));
                return;
            }
        } catch (e :Error) {
            exit(new ParseError(_confFile.nativePath, ParseError.CRIT,
                "Unable to read configuration"));
            return;
        }

        findFlashDocuments(_importDirectory, new Executor(), true);
    }

    protected function findFlashDocuments (base :File, exec :Executor,
            ignoreXflAtBase :Boolean = false) :void {
        Files.list(base, exec).succeeded.connect(function (files :Array) :void {
            for each (var file :File in files) {
                if (Files.hasExtension(file, "xfl")) {
                    if (ignoreXflAtBase) {
                        exit(new ParseError(base.nativePath,
                            ParseError.CRIT, "The import directory can't be an XFL directory, " +
                            "did you mean " + base.parent.nativePath + "?"));
                        return;
                    } else addFlashDocument(file);
                    return;
                }
            }
            for each (file in files) {
                if (StringUtil.startsWith(file.name, ".", "RECOVER_")) {
                    // Ignore hidden VCS directories, and recovered backups created by Flash
                    continue;
                }
                if (file.isDirectory) findFlashDocuments(file, exec);
                else addFlashDocument(file);
            }
        });
    }

    protected function addFlashDocument (file :File) :void {
        var importPathLen :int = _importDirectory.nativePath.length + 1;
        var name :String = file.nativePath.substring(importPathLen).replace(
            new RegExp("\\" + File.separator, "g"), "/");

        var load :Future;
        switch (Files.getExtension(file)) {
        case "xfl":
            name = name.substr(0, name.lastIndexOf("/"));
            load = new XflLoader().load(name, file.parent);
            println("Loading XFL: " + name + "...");
            break;
        case "fla":
            name = name.substr(0, name.lastIndexOf("."));
            load = new FlaLoader().load(name, file);
            println("Loading FLA: " + name + "...");
            break;
        default:
            // Unsupported file type, ignore
            return;
        }

        const status :DocStatus = new DocStatus(name, Ternary.UNKNOWN, Ternary.UNKNOWN, null);
        _statuses[_statuses.length] = status;
        load.succeeded.connect(function (lib :XflLibrary) :void {
            println("Load completed: " + name + "...");
            status.lib = lib;
            for each (var err :ParseError in lib.getErrors()) printErr(err);
            status.updateValid(Ternary.of(lib.valid));
            checkValid();
        });
        // any failed load means we can't finish the export
        load.failed.connect(exit);
    }

    /** returns all libs if all known flash docs are done loading, else null */
    protected function getLibs () :Vector.<XflLibrary> {
        var libs :Vector.<XflLibrary> = new <XflLibrary>[];
        for each (var status :DocStatus in _statuses) {
            if (status.lib == null) return null; // not done loading yet
            libs[libs.length] = status.lib;
        }
        return libs;
    }

    protected function checkValid () :void {
        if (getLibs() == null) return; // not done loading yet

        var valid :Boolean = _statuses.every(function (status :DocStatus, ..._) :Boolean {
            return status.isValid;
        });
        if (!valid) {
            // we've already printed our parse errors
            exit();
            return;
        }

        println("\nLoading complete...");

        if (_conf.exportDir == null) {
            exit("No export directory specified.");
            return;
        }

        if (_conf.exportDir == null) {
            exit("No export directory specified.");
            return;
        }

        var hasCombined :Boolean = false;
        var hasSingle :Boolean = false;
        for each (var config :ExportConf in _conf.exports) {
            hasCombined ||= config.combine;
            hasSingle ||= !config.combine;
            if (hasCombined && hasSingle) break;
        }
        try {
            var publisher :Publisher = new Publisher(new File(_conf.exportDir), _conf, projectName);
            // if we have one or more combined export format, publish them
            if (hasCombined) {
                println("Exporting combined formats...");
                var numPublished :int = publisher.publishCombined(getLibs());
                if (numPublished == 0) {
                    printErr("No suitable formats were found for combined publishing");
                } else {
                    println("" + numPublished + " combined formats published...");
                }
            }

            // now publish any appropriate single formats
            if (hasSingle) {
                for each (var status :DocStatus in _statuses) {
                    println("Exporting document " + status.path + "...");
                    numPublished = publisher.publishSingle(status.lib);
                    if (numPublished == 0) {
                        printErr("No suitable formats were found for single publishing");
                    } else {
                        println("" + numPublished + " formats published...");
                    }
                }
            }
        } catch (e :Error) {
            exit(e);
            return;
        }

        println("\nPublishing complete...");
        exit();
    }

    protected function printErr (err :*) :void {
        if (err is ParseError) {
            var pe :ParseError = ParseError(err);
            println("[" + pe.severity + "] @ " + pe.location + ": " + pe.message);
        } else if (err is Error) {
            println(Error(err).getStackTrace())
        } else if (err is ErrorEvent) {
            println("ErrorEvent: " + ErrorEvent(err).toString());
            if (err is UncaughtErrorEvent) {
                println(UncaughtErrorEvent(err).error.getStackTrace());
            }
        } else {
            println("" + err);
        }
    }

    protected function print (message :String) :void {
        OUT.writeUTFBytes(message);
    }

    protected function println (message :String = "") :void {
        print(message + "\n");
    }

    protected function exit (err :* = null) :void {
        if (err != null) printErr(err);
        _complete.value = true;
    }

    protected const _complete :BoolValue = new BoolValue(false);

    protected var OUT :FileStream;

    protected var _confFile :File;
    protected var _conf :ProjectConf;
    protected var _importDirectory :File;
    protected var _statuses :Array = [];
}
}

package flump.export {

import aspire.util.StringUtil;

import flash.events.ErrorEvent;
import flash.events.UncaughtErrorEvent;
import flash.filesystem.File;
import flash.filesystem.FileMode;
import flash.filesystem.FileStream;

import flump.executor.Executor;
import flump.executor.Future;
import flump.xfl.ParseError;
import flump.xfl.XflLibrary;

import react.BoolValue;
import react.BoolView;

/**
 * This class expects to be run from the command-line script found at rsrc/flump-export. It sends
 * output to File.applicationDirectory.nativePath + "/exporter.log" rather than spawning any
 * UI windows for user interaction, and acts as though the user pressed the export all button, then
 * shuts down.
 */
public class AutomaticExporter {
    public function AutomaticExporter (project :File) {
        _complete.connect(function (complete :Boolean) :void {
            if (!complete) return;
            if (OUT != null) {
                OUT.close();
                OUT = null;
            }
        });

        FlumpApp.app.loaderInfo.uncaughtErrorEvents
            .addEventListener(UncaughtErrorEvent.UNCAUGHT_ERROR, exit);

        var outFile :File = new File(File.applicationDirectory.nativePath + "/exporter.log");
        OUT = new FileStream();
        OUT.open(outFile, FileMode.WRITE);

        _confFile = project;
        exportProject();
    }

    public function get complete () :BoolView { return _complete; }

    public function get projectName () :String {
        return (_confFile != null ? _confFile.name.replace(/\.flump$/i, "") : "Untitled Project");
    }

    protected function exportProject () :void {
        println("Exporting project: " + _confFile.nativePath);
        println();

        try {
            _conf = ProjectConf.fromJSON(JSONFormat.readJSON(_confFile));
            _importDirectory = new File(_confFile.parent.resolvePath(_conf.importDir).nativePath);
            if (!_importDirectory.exists || !_importDirectory.isDirectory) {
                exit(new ParseError(_confFile.nativePath, ParseError.CRIT,
                    "Import directory doesn't exist (" + _importDirectory.nativePath + ")"));
                return;
            }
        } catch (e :Error) {
            exit(new ParseError(_confFile.nativePath, ParseError.CRIT,
                "Unable to read configuration"));
            return;
        }

        findFlashDocuments(_importDirectory, new Executor(), true);
    }

    protected function findFlashDocuments (base :File, exec :Executor,
            ignoreXflAtBase :Boolean = false) :void {
        Files.list(base, exec).succeeded.connect(function (files :Array) :void {
            for each (var file :File in files) {
                if (Files.hasExtension(file, "xfl")) {
                    if (ignoreXflAtBase) {
                        exit(new ParseError(base.nativePath,
                            ParseError.CRIT, "The import directory can't be an XFL directory, " +
                            "did you mean " + base.parent.nativePath + "?"));
                        return;
                    } else addFlashDocument(file);
                    return;
                }
            }
            for each (file in files) {
                if (StringUtil.startsWith(file.name, ".", "RECOVER_")) {
                    // Ignore hidden VCS directories, and recovered backups created by Flash
                    continue;
                }
                if (file.isDirectory) findFlashDocuments(file, exec);
                else addFlashDocument(file);
            }
        });
    }

    protected function addFlashDocument (file :File) :void {
        var importPathLen :int = _importDirectory.nativePath.length + 1;
        var name :String = file.nativePath.substring(importPathLen).replace(
            new RegExp("\\" + File.separator, "g"), "/");

        var load :Future;
        switch (Files.getExtension(file)) {
        case "xfl":
            name = name.substr(0, name.lastIndexOf("/"));
            load = new XflLoader().load(name, file.parent);
            println("Loading XFL: " + name + "...");
            break;
        case "fla":
            name = name.substr(0, name.lastIndexOf("."));
            load = new FlaLoader().load(name, file);
            println("Loading FLA: " + name + "...");
            break;
        default:
            // Unsupported file type, ignore
            return;
        }

        const status :DocStatus = new DocStatus(name, Ternary.UNKNOWN, Ternary.UNKNOWN, null);
        _statuses[_statuses.length] = status;
        load.succeeded.connect(function (lib :XflLibrary) :void {
            println("Load completed: " + name + "...");
            status.lib = lib;
            for each (var err :ParseError in lib.getErrors()) printErr(err);
            status.updateValid(Ternary.of(lib.valid));
            checkValid();
        });
        // any failed load means we can't finish the export
        load.failed.connect(exit);
    }

    /** returns all libs if all known flash docs are done loading, else null */
    protected function getLibs () :Vector.<XflLibrary> {
        var libs :Vector.<XflLibrary> = new <XflLibrary>[];
        for each (var status :DocStatus in _statuses) {
            if (status.lib == null) return null; // not done loading yet
            libs[libs.length] = status.lib;
        }
        return libs;
    }

    protected function checkValid () :void {
        if (getLibs() == null) return; // not done loading yet

        var valid :Boolean = _statuses.every(function (status :DocStatus, ..._) :Boolean {
            return status.isValid;
        });
        if (!valid) {
            // we've already printed our parse errors
            exit();
            return;
        }

        println("\nLoading complete...");

        if (_conf.exportDir == null) {
            exit("No export directory specified.");
            return;
        }

        var hasCombined :Boolean = false;
        var hasSingle :Boolean = false;
        for each (var config :ExportConf in _conf.exports) {
            hasCombined ||= config.combine;
            hasSingle ||= !config.combine;
            if (hasCombined && hasSingle) break;
        }
        try {
            var publisher :Publisher = new Publisher(new File(_conf.exportDir), _conf, projectName);
            // if we have one or more combined export format, publish them
            if (hasCombined) {
                println("Exporting combined formats...");
                var numPublished :int = publisher.publishCombined(getLibs());
                if (numPublished == 0) {
                    printErr("No suitable formats were found for combined publishing");
                } else {
                    println("" + numPublished + " combined formats published...");
                }
            }

            // now publish any appropriate single formats
            if (hasSingle) {
                for each (var status :DocStatus in _statuses) {
                    println("Exporting document " + status.path + "...");
                    numPublished = publisher.publishSingle(status.lib);
                    if (numPublished == 0) {
                        printErr("No suitable formats were found for single publishing");
                    } else {
                        println("" + numPublished + " formats published...");
                    }
                }
            }
        } catch (e :Error) {
            exit(e);
            return;
        }

        println("\nPublishing complete...");
        exit();
    }

    protected function printErr (err :*) :void {
        if (err is ParseError) {
            var pe :ParseError = ParseError(err);
            println("[" + pe.severity + "] @ " + pe.location + ": " + pe.message);
        } else if (err is Error) {
            println(Error(err).getStackTrace())
        } else if (err is ErrorEvent) {
            println("ErrorEvent: " + ErrorEvent(err).toString());
            if (err is UncaughtErrorEvent) {
                println(UncaughtErrorEvent(err).error.getStackTrace());
            }
        } else {
            println("" + err);
        }
    }

    protected function print (message :String) :void {
        OUT.writeUTFBytes(message);
    }

    protected function println (message :String = "") :void {
        print(message + "\n");
    }

    protected function exit (err :* = null) :void {
        if (err != null) printErr(err);
        _complete.value = true;
    }

    protected const _complete :BoolValue = new BoolValue(false);

    protected var OUT :FileStream;

    protected var _confFile :File;
    protected var _conf :ProjectConf;
    protected var _importDirectory :File;
    protected var _statuses :Array = [];
}
}

Remove redundant check.

Remove redundant check.


/* ***** BEGIN LICENSE BLOCK *****
 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
 *
 * The contents of this file are subject to the Mozilla Public License Version
 * 1.1 (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.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 * for the specific language governing rights and limitations under the
 * License.
 *
 * The Original Code is [Open Source Virtual Machine.].
 *
 * The Initial Developer of the Original Code is
 * Adobe System Incorporated.
 * Portions created by the Initial Developer are Copyright (C) 2009
 * the Initial Developer. All Rights Reserved.
 *
 * Contributor(s):
 *   Adobe AS3 Team
 *
 * Alternatively, the contents of this file may be used under the terms of
 * either the GNU General Public License Version 2 or later (the "GPL"), or
 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 * in which case the provisions of the GPL or the LGPL are applicable instead
 * of those above. If you wish to allow use of your version of this file only
 * under the terms of either the GPL or the LGPL, and not to allow others to
 * use your version of this file under the terms of the MPL, indicate your
 * decision by deleting the provisions above and replace them with the notice
 * and other provisions required by the GPL or the LGPL. If you do not delete
 * the provisions above, a recipient may use your version of this file under
 * the terms of any one of the MPL, the GPL or the LGPL.
 *
 * ***** END LICENSE BLOCK ***** */

import avmplus.* ;      // System class in the avmshell
import flash.system.* ; // System class in the flash player

var SECTION = "System::pauseForGCIfCollectionImminent";
var VERSION = "";
startTest();
var TITLE = "Test pauseForGCIfCollectionImminent api";

class Node {
    var left: Node, right: Node;
    var i: int, j: int;

    function Node(l: Node = null,
    r: Node = null) {
        left = l;
        right = r;
    }
}

// DO NOT MESS WITH THE PARAMETER VALUES.
//
// If the test takes to long to run on mobile with these values then either set the values
// differently on mobile, or disable the test on mobile.  On desktop we need a decent
// number of iterations in order to be able to run reliably, the test is statistical and
// sometimes getting a hit is tricky on a fast machine.

var i_loops = 1000;
var j_loops = 1000;

var start = new Date();
var fractions = [Number.MIN_VALUE, 0, -0,  0.25, 0.5, 0.75, 1.0];
for each(var f in fractions) {
    trace("starting pauseForGCIfCollectionImminent test @ " + f);

    var hits = 0;
    var a = [];
    for (var i = 0; i < i_loops; i++) {
        for (var j = 0; j < j_loops; j++)
            a[0] = 3.14159 + i * j; // compute a Number and store it in a * location to box it

        // Bugzilla 685161: Invoking a System method can disrupt
        // observed memory if its MethodSignature had been evicted but
        // weakly-held until some GC during loop freed it and cleared
        // the weak ref.
        //
        // As work-around, pre-call pauseForGCIfCollectionImminent
        // with imminence=1.0 (which should be a no-op) and the two
        // getters, ensuring all MethodSignatures are available before
        // memory observations in critical section.
        System.pauseForGCIfCollectionImminent(1.0);
        System.totalMemory;
        System.freeMemory;

        // Start critical section
        var beforeTotal = System.totalMemory;
        var beforeFree = System.freeMemory;
        System.pauseForGCIfCollectionImminent(f);
        var afterTotal = System.totalMemory;
        var afterFree = System.freeMemory;
        // End of critical section

        // Bugzilla 678975: 'total' once denoted used+free; now 'total' is used
        var beforeUsed = beforeTotal;
        var afterUsed = afterTotal;
        if (after < before)
            hits++;
        if (((i + 1) % 100) == 0)
            trace("Hits: " + hits);
    }

    AddTestCase("pauseForGCIfCollectionImminent test f=" + f + " : hits="+hits,
                true,
                ((hits > 0) == (f < 1.0)));
}
trace('Main tests: '+(new Date() - start))

start = new Date();
var error_cases = [NaN, undefined, Number.NEGATIVE_INFINITY,
                   -1, 1.000000001, 10000, Number.MAX_VALUE,
                   Number.POSITIVE_INFINITY];

for each (var ec in error_cases) {
    error = "no error";
    try {
        System.pauseForGCIfCollectionImminent(ec);
    } catch (err) {
        error = err.toString();
    }
    AddTestCase("pauseForGCIfCollectionImminent test @ " + ec,
                "no error", error);
}
var loop_time = new Date() - start;
trace("error tests: "+loop_time);

test();

/* ***** BEGIN LICENSE BLOCK *****
 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
 *
 * The contents of this file are subject to the Mozilla Public License Version
 * 1.1 (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.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 * for the specific language governing rights and limitations under the
 * License.
 *
 * The Original Code is [Open Source Virtual Machine.].
 *
 * The Initial Developer of the Original Code is
 * Adobe System Incorporated.
 * Portions created by the Initial Developer are Copyright (C) 2009
 * the Initial Developer. All Rights Reserved.
 *
 * Contributor(s):
 *   Adobe AS3 Team
 *
 * Alternatively, the contents of this file may be used under the terms of
 * either the GNU General Public License Version 2 or later (the "GPL"), or
 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 * in which case the provisions of the GPL or the LGPL are applicable instead
 * of those above. If you wish to allow use of your version of this file only
 * under the terms of either the GPL or the LGPL, and not to allow others to
 * use your version of this file under the terms of the MPL, indicate your
 * decision by deleting the provisions above and replace them with the notice
 * and other provisions required by the GPL or the LGPL. If you do not delete
 * the provisions above, a recipient may use your version of this file under
 * the terms of any one of the MPL, the GPL or the LGPL.
 *
 * ***** END LICENSE BLOCK ***** */

import avmplus.* ;      // System class in the avmshell
import flash.system.* ; // System class in the flash player

var SECTION = "System::pauseForGCIfCollectionImminent";
var VERSION = "";
startTest();
var TITLE = "Test pauseForGCIfCollectionImminent api";

class Node {
    var left: Node, right: Node;
    var i: int, j: int;

    function Node(l: Node = null,
    r: Node = null) {
        left = l;
        right = r;
    }
}

// DO NOT MESS WITH THE PARAMETER VALUES.
//
// If the test takes to long to run on mobile with these values then either set the values
// differently on mobile, or disable the test on mobile.  On desktop we need a decent
// number of iterations in order to be able to run reliably, the test is statistical and
// sometimes getting a hit is tricky on a fast machine.

var i_loops = 1000;
var j_loops = 1000;

var start = new Date();
var fractions = [Number.MIN_VALUE, 0, -0,  0.25, 0.5, 0.75, 1.0];
for each(var f in fractions) {
    trace("starting pauseForGCIfCollectionImminent test @ " + f);

    var hits = 0;
    var a = [];
    for (var i = 0; i < i_loops; i++) {
        for (var j = 0; j < j_loops; j++)
            a[0] = 3.14159 + i * j; // compute a Number and store it in a * location to box it

        // Bugzilla 685161: Invoking a System method can disrupt
        // observed memory if its MethodSignature had been evicted but
        // weakly-held until some GC during loop freed it and cleared
        // the weak ref.
        //
        // As work-around, pre-call pauseForGCIfCollectionImminent
        // with imminence=1.0 (which should be a no-op) and the two
        // getters, ensuring all MethodSignatures are available before
        // memory observations in critical section.
        System.pauseForGCIfCollectionImminent(1.0);
        System.totalMemory;
        System.freeMemory;

        // Start critical section
        var beforeTotal = System.totalMemory;
        var beforeFree = System.freeMemory;
        System.pauseForGCIfCollectionImminent(f);
        var afterTotal = System.totalMemory;
        var afterFree = System.freeMemory;
        // End of critical section

        // Bugzilla 678975: 'total' once denoted used+free; now 'total' is used
        var beforeUsed = beforeTotal;
        var afterUsed = afterTotal;
        if (afterUsed < beforeUsed)
            hits++;
        if (((i + 1) % 100) == 0)
            trace("Hits: " + hits);
    }

    AddTestCase("pauseForGCIfCollectionImminent test f=" + f + " : hits="+hits,
                true,
                ((hits > 0) == (f < 1.0)));
}
trace('Main tests: '+(new Date() - start))

start = new Date();
var error_cases = [NaN, undefined, Number.NEGATIVE_INFINITY,
                   -1, 1.000000001, 10000, Number.MAX_VALUE,
                   Number.POSITIVE_INFINITY];

for each (var ec in error_cases) {
    error = "no error";
    try {
        System.pauseForGCIfCollectionImminent(ec);
    } catch (err) {
        error = err.toString();
    }
    AddTestCase("pauseForGCIfCollectionImminent test @ " + ec,
                "no error", error);
}
var loop_time = new Date() - start;
trace("error tests: "+loop_time);

test();

Fix build breakage due to presumed oversight in changeset 84a074bbb8cf

Bug 678975: change shell totalMemory to match FR meaning, i.e. usedMemory, and fix dependencies on former meaning (r=fklockii).
interrupted! take a look at this.  This is a quick and not carefully considered fix to get the build going again.


package aerys.minko.render.resource
{
	import flash.display.BitmapData;
	import flash.display3D.Context3D;
	import flash.display3D.IndexBuffer3D;
	import flash.display3D.Program3D;
	import flash.display3D.VertexBuffer3D;
	import flash.display3D.textures.CubeTexture;
	import flash.display3D.textures.Texture;
	import flash.display3D.textures.TextureBase;
	import flash.geom.Rectangle;

	public final class Context3DResource
	{
		private var _context				                : Context3D;

		private var _enableErrorChecking	                : Boolean;

		private var _rttTarget			                	: TextureBase;
		private var _rttDepthAndStencil	                	: Boolean;
		private var _rttAntiAliasing	                	: int;
		private var _rttSurfaceSelector		                : int;
		private var _rectangle				                : Rectangle;

		private var _depthMask			                	: Boolean;
		private var _passCompareMode	                	: String;

		private var _program			                	: Program3D;

		private var _blendingSource		                	: String;
		private var _blendingDestination                	: String;

		private var _triangleCulling	                	: String;

		private var _vertexBuffers			                : Vector.<VertexBuffer3D>;
		private var _vertexBuffersOffsets	                : Vector.<int>;
		private var _vertexBuffersFormats	                : Vector.<String>;
		private var _textures				                : Vector.<TextureBase>;

		private var _colorMaskRed			                : Boolean;
		private var _colorMaskGreen			                : Boolean;
		private var _colorMaskBlue			                : Boolean;
		private var _colorMaskAlpha	                		: Boolean;

        private var _stencilRefNum                          : uint;
        private var _stencilReadMask                        : uint;
        private var _stencilWriteMask                       : uint;
        private var _stencilTriangleFace                    : String;
        private var _stencilCompareMode                     : String;
        private var _stencilActionOnBothPass                : String;
        private var _stencilActionOnDepthFail               : String;
        private var _stencilActionOnDepthPassStencilFail    : String;

		public function get enabledErrorChecking() : Boolean
		{
			return _enableErrorChecking;
		}
		public function set enableErrorChecking(value : Boolean) : void
		{
			if (value != _enableErrorChecking)
			{
				_enableErrorChecking = value;
				_context.enableErrorChecking = value;
			}
		}

		public function Context3DResource(context : Context3D)
		{
			_context = context;

            initialize();
		}

        private function initialize() : void
        {
            _vertexBuffers = new Vector.<VertexBuffer3D>(8, true);
            _vertexBuffersOffsets = new Vector.<int>(8, true);
            _vertexBuffersFormats = new Vector.<String>(8, true);
            _textures = new Vector.<TextureBase>(8, true);
        }

		public function clear(red		: Number	= 0.0,
							  green		: Number	= 0.0,
							  blue		: Number	= 0.0,
							  alpha		: Number	= 1.0,
							  depth		: Number	= 1.0,
							  stencil	: uint		= 0,
							  mask		: uint		= 0xffffffff) : void
		{
			_context.clear(red, green, blue, alpha, depth, stencil, mask);
		}

		public function configureBackBuffer(width					: int,
											height					: int,
											antiAlias				: int,
											enabledDepthAndStencil	: Boolean) : Context3DResource
		{
			_context.configureBackBuffer(width, height, antiAlias, enabledDepthAndStencil);

			return this;
		}

		public function createCubeTexture(size							: int,
										  format						: String,
										  optimizeForRenderToTexture	: Boolean) : CubeTexture
		{
			return _context.createCubeTexture(size, format, optimizeForRenderToTexture);
		}

		public function createIndexBuffer(numIndices : int) : IndexBuffer3D
		{
			return _context.createIndexBuffer(numIndices);
		}

		public function createProgram() : Program3D
		{
			return _context.createProgram();
		}

		public function createTexture(width							: int,
									  height						: int,
									  format						: String,
									  optimizeForRenderToTexture	: Boolean) : Texture
		{
			return _context.createTexture(width, height, format, optimizeForRenderToTexture);
		}

		public function createVertexBuffer(numVertices : int, data32PerVertex : int) : VertexBuffer3D
		{
			return _context.createVertexBuffer(numVertices, data32PerVertex);
		}

		public function dispose() : void
		{
			_context.dispose();
		}

		public function drawToBitmapData(destination : BitmapData) : Context3DResource
		{
			_context.drawToBitmapData(destination);

			return this;
		}

		public function drawTriangles(indexBuffer	: IndexBuffer3D,
									  firstIndex	: int	= 0,
									  numTriangles	: int	= -1) : Context3DResource
		{
			_context.drawTriangles(indexBuffer, firstIndex, numTriangles);

			return this;
		}

		public function present() : Context3DResource
		{
			_context.present();

			return this;
		}

		public function setBlendFactors(source : String, destination : String) : Context3DResource
		{
			if (source != _blendingSource || destination != _blendingDestination)
			{
				_blendingSource = source;
				_blendingDestination = destination;
				_context.setBlendFactors(_blendingSource, _blendingDestination);
			}

			return this;
		}

		public function setColorMask(red 	: Boolean,
									 green 	: Boolean,
									 blue 	: Boolean,
									 alpha 	: Boolean) : Context3DResource
		{
			if (red != _colorMaskRed || green != _colorMaskGreen
				|| blue != _colorMaskBlue || alpha != _colorMaskAlpha)
			{
				_colorMaskRed = red;
				_colorMaskGreen = green;
				_colorMaskBlue = blue;
				_colorMaskAlpha = alpha;
				_context.setColorMask(
					_colorMaskRed,
					_colorMaskGreen,
					_colorMaskBlue,
					_colorMaskAlpha
				);
			}

			return this;
		}

		public function setCulling(triangleCulling : String) : Context3DResource
		{
			if (triangleCulling != _triangleCulling)
			{
				_triangleCulling = triangleCulling;
				_context.setCulling(triangleCulling);
			}

			return this;
		}

		public function setDepthTest(depthMask : Boolean, passCompareMode : String) : Context3DResource
		{
			if (depthMask != _depthMask || passCompareMode != _passCompareMode)
			{
				_depthMask = depthMask;
				_passCompareMode = passCompareMode;
				_context.setDepthTest(_depthMask, _passCompareMode);
			}

			return this;
		}

		public function setProgram(program : Program3D) : Context3DResource
		{
			if (_program != program)
			{
				_program = program;
				_context.setProgram(program);
			}

			return this;
		}

		public function setProgramConstantsFromVector(programeType	: String,
													  offset		: uint,
													  values		: Vector.<Number>,
													  numRegisters	: int	= -1) : Context3DResource
		{
			_context.setProgramConstantsFromVector(programeType, offset, values, numRegisters);

			return this;
		}

		public function setRenderToBackBuffer() : Context3DResource
		{
			if (_rttTarget != null)
			{
				_rttTarget = null;
				_context.setRenderToBackBuffer();
			}

			return this;
		}

		public function setRenderToTexture(texture					: TextureBase,
										   enableDepthAndStencil	: Boolean	= false,
										   antiAlias				: int		= 0,
										   surfaceSelector			: int		= 0) : Context3DResource
		{
			if (texture != _rttTarget || enableDepthAndStencil != _rttDepthAndStencil
				|| antiAlias != _rttAntiAliasing || surfaceSelector != _rttSurfaceSelector)
			{
				_rttTarget = texture;
				_rttDepthAndStencil = enableDepthAndStencil;
				_rttAntiAliasing = antiAlias;
				_rttSurfaceSelector = surfaceSelector;
				_context.setRenderToTexture(
					texture,
					enableDepthAndStencil,
					antiAlias,
					surfaceSelector
				);
			}

			return this;
		}

		public function setScissorRectangle(rectangle : Rectangle) : Context3DResource
		{
			if (_rectangle != rectangle)
			{
				_rectangle = rectangle;
				_context.setScissorRectangle(_rectangle);
			}

			return this;
		}

		public function setTextureAt(sampler	: uint,
									 texture	: TextureBase) : Context3DResource
		{
			if (_textures[sampler] != texture)
			{
				_textures[sampler] = texture;
				_context.setTextureAt(sampler, texture);
			}

			return this;
		}

		public function setVertexBufferAt(index			: int,
										  vertexBuffer	: VertexBuffer3D,
										  bufferOffset	: int		= 0,
										  format		: String	= 'float4') : Context3DResource
		{
			if (_vertexBuffers[index] != vertexBuffer
				|| _vertexBuffersOffsets[index] != bufferOffset
				|| _vertexBuffersFormats[index] != format)
			{
				_vertexBuffers[index] = vertexBuffer;
				_vertexBuffersOffsets[index] = bufferOffset;
				_vertexBuffersFormats[index] = format;

				_context.setVertexBufferAt(
					index,
					vertexBuffer,
					bufferOffset,
					format
				);
			}

			return this;
		}

		public function setStencilReferenceValue(refNum		: uint 	= 0,
												 readMask	: uint 	= 255,
												 writeMask	: uint 	= 255) : Context3DResource
		{
            if (refNum != _stencilRefNum
                || readMask != _stencilReadMask
                || writeMask != _stencilWriteMask
                )
            {
                _context.setStencilReferenceValue(refNum, readMask, writeMask);

                _stencilRefNum = refNum;
                _stencilReadMask = readMask;
                _stencilWriteMask = writeMask;
            }

			return this;
		}

		public function setStencilActions(triangleFace					: String = 'frontAndBack',
										  compareMode					: String = 'always',
										  actionOnBothPass				: String = 'keep',
										  actionOnDepthFail				: String = 'keep',
										  actionOnDepthPassStencilFail	: String = 'keep') : Context3DResource
		{
            if (triangleFace != _stencilTriangleFace
                || compareMode != _stencilCompareMode
                || actionOnBothPass != _stencilActionOnBothPass
                || actionOnDepthFail != _stencilActionOnDepthFail
                || actionOnDepthPassStencilFail != _stencilActionOnDepthPassStencilFail
            )
            {
    			_context.setStencilActions(
    				triangleFace,
    				compareMode,
    				actionOnBothPass,
    				actionOnDepthFail,
    				actionOnDepthPassStencilFail
    			);

                _stencilTriangleFace = triangleFace;
                _stencilCompareMode = compareMode;
                _stencilActionOnBothPass = actionOnBothPass;
                _stencilActionOnDepthFail = actionOnDepthFail;
                _stencilActionOnDepthPassStencilFail = actionOnDepthPassStencilFail;
            }

			return this;
		}

	}
}

package aerys.minko.render.resource
{
	import flash.display.BitmapData;
	import flash.display3D.Context3D;
	import flash.display3D.IndexBuffer3D;
	import flash.display3D.Program3D;
	import flash.display3D.VertexBuffer3D;
	import flash.display3D.textures.CubeTexture;
	import flash.display3D.textures.Texture;
	import flash.display3D.textures.TextureBase;
	import flash.geom.Rectangle;

	import aerys.minko.ns.minko_render;

	public final class Context3DResource
	{
		private var _context				                : Context3D;

		private var _enableErrorChecking	                : Boolean;

		private var _rttTarget			                	: TextureBase;
		private var _rttDepthAndStencil	                	: Boolean;
		private var _rttAntiAliasing	                	: int;
		private var _rttSurfaceSelector		                : int;
		private var _rectangle				                : Rectangle;

		private var _depthMask			                	: Boolean;
		private var _passCompareMode	                	: String;

		private var _program			                	: Program3D;

		private var _blendingSource		                	: String;
		private var _blendingDestination                	: String;

		private var _triangleCulling	                	: String;

		private var _vertexBuffers			                : Vector.<VertexBuffer3D>;
		private var _vertexBuffersOffsets	                : Vector.<int>;
		private var _vertexBuffersFormats	                : Vector.<String>;
		private var _textures				                : Vector.<TextureBase>;

		private var _colorMaskRed			                : Boolean;
		private var _colorMaskGreen			                : Boolean;
		private var _colorMaskBlue			                : Boolean;
		private var _colorMaskAlpha	                		: Boolean;

        private var _stencilRefNum                          : uint;
        private var _stencilReadMask                        : uint;
        private var _stencilWriteMask                       : uint;
        private var _stencilTriangleFace                    : String;
        private var _stencilCompareMode                     : String;
        private var _stencilActionOnBothPass                : String;
        private var _stencilActionOnDepthFail               : String;
        private var _stencilActionOnDepthPassStencilFail    : String;

		minko_render function get context() : Context3D
		{
			return _context;
		}

		public function get enabledErrorChecking() : Boolean
		{
			return _enableErrorChecking;
		}
		public function set enableErrorChecking(value : Boolean) : void
		{
			if (value != _enableErrorChecking)
			{
				_enableErrorChecking = value;
				_context.enableErrorChecking = value;
			}
		}

		public function Context3DResource(context : Context3D)
		{
			_context = context;

            initialize();
		}

        private function initialize() : void
        {
            _vertexBuffers = new Vector.<VertexBuffer3D>(8, true);
            _vertexBuffersOffsets = new Vector.<int>(8, true);
            _vertexBuffersFormats = new Vector.<String>(8, true);
            _textures = new Vector.<TextureBase>(8, true);
        }

		public function clear(red		: Number	= 0.0,
							  green		: Number	= 0.0,
							  blue		: Number	= 0.0,
							  alpha		: Number	= 1.0,
							  depth		: Number	= 1.0,
							  stencil	: uint		= 0,
							  mask		: uint		= 0xffffffff) : void
		{
			_context.clear(red, green, blue, alpha, depth, stencil, mask);
		}

		public function configureBackBuffer(width					: int,
											height					: int,
											antiAlias				: int,
											enabledDepthAndStencil	: Boolean) : Context3DResource
		{
			_context.configureBackBuffer(width, height, antiAlias, enabledDepthAndStencil);

			return this;
		}

		public function createCubeTexture(size							: int,
										  format						: String,
										  optimizeForRenderToTexture	: Boolean) : CubeTexture
		{
			return _context.createCubeTexture(size, format, optimizeForRenderToTexture);
		}

		public function createIndexBuffer(numIndices : int) : IndexBuffer3D
		{
			return _context.createIndexBuffer(numIndices);
		}

		public function createProgram() : Program3D
		{
			return _context.createProgram();
		}

		public function createTexture(width							: int,
									  height						: int,
									  format						: String,
									  optimizeForRenderToTexture	: Boolean) : Texture
		{
			return _context.createTexture(width, height, format, optimizeForRenderToTexture);
		}

		public function createVertexBuffer(numVertices : int, data32PerVertex : int) : VertexBuffer3D
		{
			return _context.createVertexBuffer(numVertices, data32PerVertex);
		}

		public function dispose() : void
		{
			_context.dispose();
		}

		public function drawToBitmapData(destination : BitmapData) : Context3DResource
		{
			_context.drawToBitmapData(destination);

			return this;
		}

		public function drawTriangles(indexBuffer	: IndexBuffer3D,
									  firstIndex	: int	= 0,
									  numTriangles	: int	= -1) : Context3DResource
		{
			_context.drawTriangles(indexBuffer, firstIndex, numTriangles);

			return this;
		}

		public function present() : Context3DResource
		{
			_context.present();

			return this;
		}

		public function setBlendFactors(source : String, destination : String) : Context3DResource
		{
			if (source != _blendingSource || destination != _blendingDestination)
			{
				_blendingSource = source;
				_blendingDestination = destination;
				_context.setBlendFactors(_blendingSource, _blendingDestination);
			}

			return this;
		}

		public function setColorMask(red 	: Boolean,
									 green 	: Boolean,
									 blue 	: Boolean,
									 alpha 	: Boolean) : Context3DResource
		{
			if (red != _colorMaskRed || green != _colorMaskGreen
				|| blue != _colorMaskBlue || alpha != _colorMaskAlpha)
			{
				_colorMaskRed = red;
				_colorMaskGreen = green;
				_colorMaskBlue = blue;
				_colorMaskAlpha = alpha;
				_context.setColorMask(
					_colorMaskRed,
					_colorMaskGreen,
					_colorMaskBlue,
					_colorMaskAlpha
				);
			}

			return this;
		}

		public function setCulling(triangleCulling : String) : Context3DResource
		{
			if (triangleCulling != _triangleCulling)
			{
				_triangleCulling = triangleCulling;
				_context.setCulling(triangleCulling);
			}

			return this;
		}

		public function setDepthTest(depthMask : Boolean, passCompareMode : String) : Context3DResource
		{
			if (depthMask != _depthMask || passCompareMode != _passCompareMode)
			{
				_depthMask = depthMask;
				_passCompareMode = passCompareMode;
				_context.setDepthTest(_depthMask, _passCompareMode);
			}

			return this;
		}

		public function setProgram(program : Program3D) : Context3DResource
		{
			if (_program != program)
			{
				_program = program;
				_context.setProgram(program);
			}

			return this;
		}

		public function setProgramConstantsFromVector(programeType	: String,
													  offset		: uint,
													  values		: Vector.<Number>,
													  numRegisters	: int	= -1) : Context3DResource
		{
			_context.setProgramConstantsFromVector(programeType, offset, values, numRegisters);

			return this;
		}

		public function setRenderToBackBuffer() : Context3DResource
		{
			if (_rttTarget != null)
			{
				_rttTarget = null;
				_context.setRenderToBackBuffer();
			}

			return this;
		}

		public function setRenderToTexture(texture					: TextureBase,
										   enableDepthAndStencil	: Boolean	= false,
										   antiAlias				: int		= 0,
										   surfaceSelector			: int		= 0) : Context3DResource
		{
			if (texture != _rttTarget || enableDepthAndStencil != _rttDepthAndStencil
				|| antiAlias != _rttAntiAliasing || surfaceSelector != _rttSurfaceSelector)
			{
				_rttTarget = texture;
				_rttDepthAndStencil = enableDepthAndStencil;
				_rttAntiAliasing = antiAlias;
				_rttSurfaceSelector = surfaceSelector;
				_context.setRenderToTexture(
					texture,
					enableDepthAndStencil,
					antiAlias,
					surfaceSelector
				);
			}

			return this;
		}

		public function setScissorRectangle(rectangle : Rectangle) : Context3DResource
		{
			if (_rectangle != rectangle)
			{
				_rectangle = rectangle;
				_context.setScissorRectangle(_rectangle);
			}

			return this;
		}

		public function setTextureAt(sampler	: uint,
									 texture	: TextureBase) : Context3DResource
		{
			if (_textures[sampler] != texture)
			{
				_textures[sampler] = texture;
				_context.setTextureAt(sampler, texture);
			}

			return this;
		}

		public function setVertexBufferAt(index			: int,
										  vertexBuffer	: VertexBuffer3D,
										  bufferOffset	: int		= 0,
										  format		: String	= 'float4') : Context3DResource
		{
			if (_vertexBuffers[index] != vertexBuffer
				|| _vertexBuffersOffsets[index] != bufferOffset
				|| _vertexBuffersFormats[index] != format)
			{
				_vertexBuffers[index] = vertexBuffer;
				_vertexBuffersOffsets[index] = bufferOffset;
				_vertexBuffersFormats[index] = format;

				_context.setVertexBufferAt(
					index,
					vertexBuffer,
					bufferOffset,
					format
				);
			}

			return this;
		}

		public function setStencilReferenceValue(refNum		: uint 	= 0,
												 readMask	: uint 	= 255,
												 writeMask	: uint 	= 255) : Context3DResource
		{
            if (refNum != _stencilRefNum
                || readMask != _stencilReadMask
                || writeMask != _stencilWriteMask
                )
            {
                _context.setStencilReferenceValue(refNum, readMask, writeMask);

                _stencilRefNum = refNum;
                _stencilReadMask = readMask;
                _stencilWriteMask = writeMask;
            }

			return this;
		}

		public function setStencilActions(triangleFace					: String = 'frontAndBack',
										  compareMode					: String = 'always',
										  actionOnBothPass				: String = 'keep',
										  actionOnDepthFail				: String = 'keep',
										  actionOnDepthPassStencilFail	: String = 'keep') : Context3DResource
		{
            if (triangleFace != _stencilTriangleFace
                || compareMode != _stencilCompareMode
                || actionOnBothPass != _stencilActionOnBothPass
                || actionOnDepthFail != _stencilActionOnDepthFail
                || actionOnDepthPassStencilFail != _stencilActionOnDepthPassStencilFail
            )
            {
    			_context.setStencilActions(
    				triangleFace,
    				compareMode,
    				actionOnBothPass,
    				actionOnDepthFail,
    				actionOnDepthPassStencilFail
    			);

                _stencilTriangleFace = triangleFace;
                _stencilCompareMode = compareMode;
                _stencilActionOnBothPass = actionOnBothPass;
                _stencilActionOnDepthFail = actionOnDepthFail;
                _stencilActionOnDepthPassStencilFail = actionOnDepthPassStencilFail;
            }

			return this;
		}

	}
}

Add getter on context (minko_render namespace)