//
// $Id$
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2011 Three Rings Design, Inc., All Rights Reserved
// http://code.google.com/p/narya/
//
// This library is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published
// by the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

package com.threerings.presents.dobj {
import org.osflash.signals.Signal;

import flash.errors.IllegalOperationError;

import flash.events.EventDispatcher;

import com.threerings.util.ClassUtil;
import com.threerings.util.Joiner;
import com.threerings.util.Log;

import com.threerings.io.ObjectInputStream;
import com.threerings.io.ObjectOutputStream;
import com.threerings.io.Streamable;

public class DObject // extends EventDispatcher
    implements Streamable
{
    private static const log :Log = Log.getLog(DObject);

    public function DObject ()
    {
        new Signaller(this);
    }

    public function getOid ():int
    {
        return _oid;
    }

    public function getManager () :DObjectManager
    {
        return _omgr;
    }

    public function addSubscriber (sub :Subscriber) :void
    {
        if (_subscribers == null) {
            _subscribers = [ ];
        }
        if (_subscribers.indexOf(sub) == -1) {
            _subscribers.push(sub);
        }
    }

    public function removeSubscriber (sub :Subscriber) :void
    {
        if (_subscribers == null) {
            return;
        }
        var dex :int = _subscribers.indexOf(sub);
        if (dex != -1) {
            _subscribers.splice(dex, 1);
            if (_subscribers.length == 0) {
                _omgr.removedLastSubscriber(this, _deathWish);
            }
        }
    }

    public const messageReceived :Signal = new Signal(String, Array);
    public const destroyed :Signal = new Signal();

    public function setDestroyOnLastSubscriberRemoved (deathWish :Boolean) :void
    {
        _deathWish = deathWish;
    }

    public function addListener (listener :ChangeListener) :void
    {
        if (_listeners == null) {
            _listeners = [ ];

        } else if (_listeners.indexOf(listener) != -1) {
            log.warning("Refusing repeat listener registration",
                "dobj", which(), "list", listener, new Error());
            return;
        }
        _listeners.push(listener);
    }

    public function removeListener (listener :ChangeListener) :void
    {
        if (_listeners != null) {
            var dex :int = _listeners.indexOf(listener);
            if (dex != -1) {
                _listeners.splice(dex, 1);
            }
        }
    }

    public function notifyListeners (event :DEvent) :void
    {
        if (_listeners == null) {
            return;
        }

        var listenersCopy :Array = _listeners.concat();
        for each (var listener :Object in listenersCopy) {
            // make sure the listener is still a listener
            // and hasn't been removed while dispatching to another listener..
            if (_listeners.indexOf(listener) == -1) {
                continue;
            }
            try {
                event.friendNotifyListener(listener);

                if (listener is EventListener) {
                    (listener as EventListener).eventReceived(event);
                }
            } catch (e :Error) {
                log.warning("Listener choked during notification",
                    "list", listener, "event", event, e);
            }
        }
    }

    /**
     * Posts a message event on this distrubuted object.
     */
    public function postMessage (name :String, args :Array) :void
    {
        postEvent(new MessageEvent(_oid, name, args));
    }

    /**
     * Posts the specified event either to our dobject manager or to the compound event for which
     * we are currently transacting.
     */
    public function postEvent (event :DEvent) :void
    {
        if (_tevent != null) {
            _tevent.postEvent(event);

        } else if (_omgr != null) {
            _omgr.postEvent(event);

        } else {
            log.warning("Unable to post event, object has no omgr",
                "oid", getOid(), "class", ClassUtil.getClassName(this), "event", event);
        }
    }

    /**
     * Generates a concise string representation of this object.
     */
    public function which () :String
    {
        var j :Joiner = Joiner.createFor(this);
        whichJoiner(j);
        return j.toString();
    }

    /**
     * Used to briefly describe this distributed object.
     */
    protected function whichJoiner (j :Joiner) :void
    {
        j.addArgs(_oid);
    }

    // documentation inherited
    public function toString () :String
    {
        var j :Joiner = Joiner.createFor(this);
        toStringJoiner(j);
        return j.toString();
    }

    /**
     * Generates a string representation of this object.
     */
    public function toStringJoiner (j :Joiner) :void
    {
        j.add("oid", _oid);
    }

    /**
     * Begins a transaction on this distributed object. In some situations, it is desirable to
     * cause multiple changes to distributed object fields in one unified operation. Starting a
     * transaction causes all subsequent field modifications to be stored in a single compound
     * event which can then be committed, dispatching and applying all included events in a single
     * group. Additionally, the events are dispatched over the network in a single unit which can
     * significantly enhance network efficiency.
     *
     *
 When the transaction is complete, the caller must call {@link #commitTransaction} to
     * commit the transaction and release the object back to its normal non-transacting state. If
     * the caller decides not to commit their transaction, they must call {@link
     * #cancelTransaction} to cancel the transaction. Failure to do so will cause the pooch to be
     * totally screwed.
     *
     *
 Note: like all other distributed object operations, transactions are not thread safe. It
     * is expected that a single thread will handle all distributed object operations and that
     * thread will begin and complete a transaction before giving up control to unknown code which
     * might try to operate on the transacting distributed object.
     *
     *
 Note also: if the object is already engaged in a transaction, a transaction participant
     * count will be incremented to note that an additional call to {@link #commitTransaction} is
     * required before the transaction should actually be committed. Thus every call to
     * {@link #startTransaction} must be accompanied by a call to either {@link #commitTransaction}
     * or {@link #cancelTransaction}. Additionally, if any transaction participant cancels the
     * transaction, the entire transaction is cancelled for all participants, regardless of whether
     * the other participants attempted to commit the transaction.
     */
    public function startTransaction () :void
    {
        if (_tevent != null) {
            _tcount++;
        } else {
            _tevent = new CompoundEvent(getOid());
        }
    }

    /**
     * Commits the transaction in which this distributed object is involved.
     */
    public function commitTransaction () :void
    {
        if (_tevent == null) {
            throw new IllegalOperationError(
                "Cannot commit: not involved in a transaction [dobj=" + this + "]");
        }

        // if we are nested, we decrement our nesting count rather than committing the transaction
        if (_tcount > 0) {
            _tcount--;

        } else {
            // we may actually be doing our final commit after someone already cancelled this
            // transaction, so we need to perform the appropriate action at this point
            if (!_tcancelled) {
                _tevent.commit(_omgr);
            }
            clearTransaction();
        }
    }

    /**
     * Returns true if this object is in the middle of a transaction or false if it is not.
     */
    public function inTransaction () :Boolean
    {
        return (_tevent != null);
    }

    /**
     * Cancels the transaction in which this distributed object is involved.
     */
    public function cancelTransaction () :void
    {
        if (_tevent == null) {
            throw new IllegalOperationError(
                "Cannot cancel: not involved in a transaction [dobj=" + this + "]");
        }

        // if we're in a nested transaction, make a note that it is to be cancelled when all
        // parties commit and decrement the nest count
        if (_tcount > 0) {
            _tcancelled = true;
            _tcount--;

        } else {
            clearTransaction();
        }
    }

    /**
     * Removes this object from participation in any transaction in which it might be taking part.
     */
    internal function clearTransaction () :void
    {
        // sanity check
        if (_tcount != 0) {
            log.warning("Transaction cleared with non-zero nesting count", "dobj", this);
            _tcount = 0;
        }

        // clear our transaction state
        _tevent = null;
        _tcancelled = false;
    }

    /**
     * Returns true if this object is active and registered with the distributed object system. If
     * an object is created via DObjectManager.createObject it will be active until
     * such time as it is destroyed.
     */
    public final function isActive () :Boolean
    {
        return (_omgr != null);
    }

    /**
     * Don't call this function! It initializes this distributed object with the supplied
     * distributed object manager. This is called by the distributed object manager when an object
     * is created and registered with the system.
     *
     * @see DObjectManager#createObject
     */
    public function setManager (omgr :DObjectManager) :void
    {
        _omgr = omgr;
    }

    /**
     * Called by derived instances when an attribute setter method was called.
     */
    protected function requestAttributeChange (name :String, value :Object, oldValue :Object) :void
    {
        postEvent(new AttributeChangedEvent(_oid, name, value, oldValue));
    }

    /**
     * Called by derived instances when an element updater method was called.
     */
    protected function requestElementUpdate (
        name :String, index :int, value :Object, oldValue :Object) :void
    {
        // dispatch an attribute changed event
        postEvent(new ElementUpdatedEvent(_oid, name, value, oldValue, index));
    }

    /**
     * Calls by derived instances when an oid adder method was called.
     */
    protected function requestOidAdd (name :String, oid :int) :void
    {
        // dispatch an object added event
        postEvent(new ObjectAddedEvent(_oid, name, oid));
    }

    /**
     * Calls by derived instances when an oid remover method was called.
     */
    protected function requestOidRemove (name :String, oid :int) :void
    {
        // dispatch an object removed event
        postEvent(new ObjectRemovedEvent(_oid, name, oid));
    }

    /**
     * Calls by derived instances when a set adder method was called.
     */
    protected function requestEntryAdd (name :String, entry :DSet_Entry) :void
    {
        // dispatch an entry added event
        postEvent(new EntryAddedEvent(_oid, name, entry));
    }

    /**
     * Calls by derived instances when a set remover method was called.
     */
    protected function requestEntryRemove (name :String, key :Object) :void
    {
        // dispatch an entry removed event
        postEvent(new EntryRemovedEvent(_oid, name, key, null));
    }

    /**
     * Calls by derived instances when a set updater method was called.
     */
    protected function requestEntryUpdate (name :String, entry :DSet_Entry) :void
    {
        // dispatch an entry updated event
        postEvent(new EntryUpdatedEvent(_oid, name, entry, null));
    }

    // documentation inherited from interface Streamable
    public final function writeObject (out :ObjectOutputStream) :void
    {
        throw new Error();
//        out.writeInt(_oid);
    }

    // documentation inherited from interface Streamable
    public function readObject (ins :ObjectInputStream) :void
    {
        _oid = ins.readInt();
    }

    /** Our unique identifier. */
    protected var _oid :int;

    /** A reference to our object manager. */
    protected var _omgr :DObjectManager;

    /** Our event listeners. */
    protected var _listeners :Array;

    /** A list of all subscribers to this object. */
    protected var _subscribers :Array;

    /** The compound event associated with our transaction, if we're currently in a transaction. */
    protected var _tevent :CompoundEvent;

    /** The nesting depth of our current transaction. */
    protected var _tcount :int;

    /** Whether or not our nested transaction has been cancelled. */
    protected var _tcancelled :Boolean;

    /** Indicates whether we want to be destroyed when our last subscriber is removed. */
    protected var _deathWish :Boolean = false;
}
}

import com.threerings.presents.dobj.MessageEvent;
import com.threerings.presents.dobj.MessageListener;
import com.threerings.presents.dobj.ObjectDeathListener;
import com.threerings.presents.dobj.ObjectDestroyedEvent;

import com.threerings.presents.dobj.DObject;

class Signaller
    implements MessageListener, ObjectDeathListener
{
    public function Signaller (obj :DObject)
    {
        _obj = obj;
        _obj.addListener(this);
    }

    public function messageReceived (event :MessageEvent) :void
    {
        _obj.messageReceived.dispatch(event.getName(), event.getArgs());
    }

    public function objectDestroyed (event :ObjectDestroyedEvent) :void
    {
        _obj.destroyed.dispatch();
    }

    protected var _obj :DObject;
}

//
// $Id$
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2011 Three Rings Design, Inc., All Rights Reserved
// http://code.google.com/p/narya/
//
// This library is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published
// by the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

package com.threerings.presents.dobj {
import org.osflash.signals.Signal;

import flash.errors.IllegalOperationError;

import flash.events.EventDispatcher;

import com.threerings.util.ClassUtil;
import com.threerings.util.Joiner;
import com.threerings.util.Log;

import com.threerings.io.ObjectInputStream;
import com.threerings.io.ObjectOutputStream;
import com.threerings.io.Streamable;

public class DObject // extends EventDispatcher
    implements Streamable
{
    /** Dispatched when a message is posted to the DObject */
    public const messageReceived :Signal = new Signal(String, Array);

    /** Dispatched when the DObject is destroyed */
    public const destroyed :Signal = new Signal();

    public function DObject ()
    {
        new Signaller(this);
    }

    public function getOid ():int
    {
        return _oid;
    }

    public function getManager () :DObjectManager
    {
        return _omgr;
    }

    public function addSubscriber (sub :Subscriber) :void
    {
        if (_subscribers == null) {
            _subscribers = [ ];
        }
        if (_subscribers.indexOf(sub) == -1) {
            _subscribers.push(sub);
        }
    }

    public function removeSubscriber (sub :Subscriber) :void
    {
        if (_subscribers == null) {
            return;
        }
        var dex :int = _subscribers.indexOf(sub);
        if (dex != -1) {
            _subscribers.splice(dex, 1);
            if (_subscribers.length == 0) {
                _omgr.removedLastSubscriber(this, _deathWish);
            }
        }
    }

    public function setDestroyOnLastSubscriberRemoved (deathWish :Boolean) :void
    {
        _deathWish = deathWish;
    }

    public function addListener (listener :ChangeListener) :void
    {
        if (_listeners == null) {
            _listeners = [ ];

        } else if (_listeners.indexOf(listener) != -1) {
            log.warning("Refusing repeat listener registration",
                "dobj", which(), "list", listener, new Error());
            return;
        }
        _listeners.push(listener);
    }

    public function removeListener (listener :ChangeListener) :void
    {
        if (_listeners != null) {
            var dex :int = _listeners.indexOf(listener);
            if (dex != -1) {
                _listeners.splice(dex, 1);
            }
        }
    }

    public function notifyListeners (event :DEvent) :void
    {
        if (_listeners == null) {
            return;
        }

        var listenersCopy :Array = _listeners.concat();
        for each (var listener :Object in listenersCopy) {
            // make sure the listener is still a listener
            // and hasn't been removed while dispatching to another listener..
            if (_listeners.indexOf(listener) == -1) {
                continue;
            }
            try {
                event.friendNotifyListener(listener);

                if (listener is EventListener) {
                    (listener as EventListener).eventReceived(event);
                }
            } catch (e :Error) {
                log.warning("Listener choked during notification",
                    "list", listener, "event", event, e);
            }
        }
    }

    /**
     * Posts a message event on this distrubuted object.
     */
    public function postMessage (name :String, args :Array) :void
    {
        postEvent(new MessageEvent(_oid, name, args));
    }

    /**
     * Posts the specified event either to our dobject manager or to the compound event for which
     * we are currently transacting.
     */
    public function postEvent (event :DEvent) :void
    {
        if (_tevent != null) {
            _tevent.postEvent(event);

        } else if (_omgr != null) {
            _omgr.postEvent(event);

        } else {
            log.warning("Unable to post event, object has no omgr",
                "oid", getOid(), "class", ClassUtil.getClassName(this), "event", event);
        }
    }

    /**
     * Generates a concise string representation of this object.
     */
    public function which () :String
    {
        var j :Joiner = Joiner.createFor(this);
        whichJoiner(j);
        return j.toString();
    }

    /**
     * Used to briefly describe this distributed object.
     */
    protected function whichJoiner (j :Joiner) :void
    {
        j.addArgs(_oid);
    }

    // documentation inherited
    public function toString () :String
    {
        var j :Joiner = Joiner.createFor(this);
        toStringJoiner(j);
        return j.toString();
    }

    /**
     * Generates a string representation of this object.
     */
    public function toStringJoiner (j :Joiner) :void
    {
        j.add("oid", _oid);
    }

    /**
     * Begins a transaction on this distributed object. In some situations, it is desirable to
     * cause multiple changes to distributed object fields in one unified operation. Starting a
     * transaction causes all subsequent field modifications to be stored in a single compound
     * event which can then be committed, dispatching and applying all included events in a single
     * group. Additionally, the events are dispatched over the network in a single unit which can
     * significantly enhance network efficiency.
     *
     *
 When the transaction is complete, the caller must call {@link #commitTransaction} to
     * commit the transaction and release the object back to its normal non-transacting state. If
     * the caller decides not to commit their transaction, they must call {@link
     * #cancelTransaction} to cancel the transaction. Failure to do so will cause the pooch to be
     * totally screwed.
     *
     *
 Note: like all other distributed object operations, transactions are not thread safe. It
     * is expected that a single thread will handle all distributed object operations and that
     * thread will begin and complete a transaction before giving up control to unknown code which
     * might try to operate on the transacting distributed object.
     *
     *
 Note also: if the object is already engaged in a transaction, a transaction participant
     * count will be incremented to note that an additional call to {@link #commitTransaction} is
     * required before the transaction should actually be committed. Thus every call to
     * {@link #startTransaction} must be accompanied by a call to either {@link #commitTransaction}
     * or {@link #cancelTransaction}. Additionally, if any transaction participant cancels the
     * transaction, the entire transaction is cancelled for all participants, regardless of whether
     * the other participants attempted to commit the transaction.
     */
    public function startTransaction () :void
    {
        if (_tevent != null) {
            _tcount++;
        } else {
            _tevent = new CompoundEvent(getOid());
        }
    }

    /**
     * Commits the transaction in which this distributed object is involved.
     */
    public function commitTransaction () :void
    {
        if (_tevent == null) {
            throw new IllegalOperationError(
                "Cannot commit: not involved in a transaction [dobj=" + this + "]");
        }

        // if we are nested, we decrement our nesting count rather than committing the transaction
        if (_tcount > 0) {
            _tcount--;

        } else {
            // we may actually be doing our final commit after someone already cancelled this
            // transaction, so we need to perform the appropriate action at this point
            if (!_tcancelled) {
                _tevent.commit(_omgr);
            }
            clearTransaction();
        }
    }

    /**
     * Returns true if this object is in the middle of a transaction or false if it is not.
     */
    public function inTransaction () :Boolean
    {
        return (_tevent != null);
    }

    /**
     * Cancels the transaction in which this distributed object is involved.
     */
    public function cancelTransaction () :void
    {
        if (_tevent == null) {
            throw new IllegalOperationError(
                "Cannot cancel: not involved in a transaction [dobj=" + this + "]");
        }

        // if we're in a nested transaction, make a note that it is to be cancelled when all
        // parties commit and decrement the nest count
        if (_tcount > 0) {
            _tcancelled = true;
            _tcount--;

        } else {
            clearTransaction();
        }
    }

    /**
     * Removes this object from participation in any transaction in which it might be taking part.
     */
    internal function clearTransaction () :void
    {
        // sanity check
        if (_tcount != 0) {
            log.warning("Transaction cleared with non-zero nesting count", "dobj", this);
            _tcount = 0;
        }

        // clear our transaction state
        _tevent = null;
        _tcancelled = false;
    }

    /**
     * Returns true if this object is active and registered with the distributed object system. If
     * an object is created via DObjectManager.createObject it will be active until
     * such time as it is destroyed.
     */
    public final function isActive () :Boolean
    {
        return (_omgr != null);
    }

    /**
     * Don't call this function! It initializes this distributed object with the supplied
     * distributed object manager. This is called by the distributed object manager when an object
     * is created and registered with the system.
     *
     * @see DObjectManager#createObject
     */
    public function setManager (omgr :DObjectManager) :void
    {
        _omgr = omgr;
    }

    /**
     * Called by derived instances when an attribute setter method was called.
     */
    protected function requestAttributeChange (name :String, value :Object, oldValue :Object) :void
    {
        postEvent(new AttributeChangedEvent(_oid, name, value, oldValue));
    }

    /**
     * Called by derived instances when an element updater method was called.
     */
    protected function requestElementUpdate (
        name :String, index :int, value :Object, oldValue :Object) :void
    {
        // dispatch an attribute changed event
        postEvent(new ElementUpdatedEvent(_oid, name, value, oldValue, index));
    }

    /**
     * Calls by derived instances when an oid adder method was called.
     */
    protected function requestOidAdd (name :String, oid :int) :void
    {
        // dispatch an object added event
        postEvent(new ObjectAddedEvent(_oid, name, oid));
    }

    /**
     * Calls by derived instances when an oid remover method was called.
     */
    protected function requestOidRemove (name :String, oid :int) :void
    {
        // dispatch an object removed event
        postEvent(new ObjectRemovedEvent(_oid, name, oid));
    }

    /**
     * Calls by derived instances when a set adder method was called.
     */
    protected function requestEntryAdd (name :String, entry :DSet_Entry) :void
    {
        // dispatch an entry added event
        postEvent(new EntryAddedEvent(_oid, name, entry));
    }

    /**
     * Calls by derived instances when a set remover method was called.
     */
    protected function requestEntryRemove (name :String, key :Object) :void
    {
        // dispatch an entry removed event
        postEvent(new EntryRemovedEvent(_oid, name, key, null));
    }

    /**
     * Calls by derived instances when a set updater method was called.
     */
    protected function requestEntryUpdate (name :String, entry :DSet_Entry) :void
    {
        // dispatch an entry updated event
        postEvent(new EntryUpdatedEvent(_oid, name, entry, null));
    }

    // documentation inherited from interface Streamable
    public final function writeObject (out :ObjectOutputStream) :void
    {
        throw new Error();
//        out.writeInt(_oid);
    }

    // documentation inherited from interface Streamable
    public function readObject (ins :ObjectInputStream) :void
    {
        _oid = ins.readInt();
    }

    /** Our unique identifier. */
    protected var _oid :int;

    /** A reference to our object manager. */
    protected var _omgr :DObjectManager;

    /** Our event listeners. */
    protected var _listeners :Array;

    /** A list of all subscribers to this object. */
    protected var _subscribers :Array;

    /** The compound event associated with our transaction, if we're currently in a transaction. */
    protected var _tevent :CompoundEvent;

    /** The nesting depth of our current transaction. */
    protected var _tcount :int;

    /** Whether or not our nested transaction has been cancelled. */
    protected var _tcancelled :Boolean;

    /** Indicates whether we want to be destroyed when our last subscriber is removed. */
    protected var _deathWish :Boolean = false;

    private static const log :Log = Log.getLog(DObject);
}
}

import com.threerings.presents.dobj.MessageEvent;
import com.threerings.presents.dobj.MessageListener;
import com.threerings.presents.dobj.ObjectDeathListener;
import com.threerings.presents.dobj.ObjectDestroyedEvent;

import com.threerings.presents.dobj.DObject;

class Signaller
    implements MessageListener, ObjectDeathListener
{
    public function Signaller (obj :DObject)
    {
        _obj = obj;
        _obj.addListener(this);
    }

    public function messageReceived (event :MessageEvent) :void
    {
        _obj.messageReceived.dispatch(event.getName(), event.getArgs());
    }

    public function objectDestroyed (event :ObjectDestroyedEvent) :void
    {
        _obj.destroyed.dispatch();
    }

    protected var _obj :DObject;
}

Move these variables where they belong and add some documentation. Also apparently whitespace.

git-svn-id: a1a4b28b82a3276cc491891159dd9963a0a72fae@6506 542714f4-19e9-0310-aa3c-eee0fc999fb1


var historia_txt:String ="";
var baixa_mc:MovieClip;
var puja_mc:MovieClip;

var buttonsUI:Array = new Array ("puja_mc", "baixa_mc");

this.historia_txt.html = true;
this.historia.htmlText =true;
this.historia_txt.wordWrap = true;
this.historia_txt.multiline = true;

function textScroll():Void
{
	this.onPress = this.oOut;
	this.onRollOver =this.oOver;
	this.onRollOut = this.oOut;
	this.onRelease = this.oOut;
};

function oOver():Void
{
	pressing = true;
	movement = -1;
};
function oOut():Void
{
	pressing = false;
};

var Private_lv = new LoadVars ();
Private_lv.load ("/assets/tendes.txt");
Private_lv.onLoad = function ()
{
	this.historia_txt.htmlText = this.Privat;
	this.play ();
	textScroll();
};

var historia_txt:String ="";
var baixa_mc:MovieClip;
var puja_mc:MovieClip;

var buttonsUI:Array = new Array ("puja_mc", "baixa_mc");

this.historia_txt.html = true;
this.historia.htmlText =true;
this.historia_txt.wordWrap = true;
this.historia_txt.multiline = true;

this.onEnterFrame = function ():Void
{
    buttonsUI[i].oOver();
    this.stop();
};

function textScroll():Void
{
	this.onPress = this.oOut;
	this.onRollOver =this.oOver;
	this.onRollOut = this.oOut;
	this.onRelease = this.oOut;
};

function oOver():Void
{
	pressing = true;
	movement = -1;
};
function oOut():Void
{
	pressing = false;
};

var Private_lv = new LoadVars ();

Private_lv.load ("/assets/tendes.txt");

Private_lv.onLoad = function ():Void
{
	this.historia_txt.htmlText = this.Privat;
	this.play ();
	textScroll();
};

Update frame4.as

Update frame4.as


package battlecode.common {

    public class RobotType {
        public static const HQ:String = "HQ";
        public static const TOWER:String = "TOWER";

        public static const SUPPLYDEPOT:String = "SUPPLYDEPOT";
        public static const TECHNOLOGYINSTITUTE:String = "TECHNOLOGYINSTITUTE";
        public static const BARRACKS:String = "BARRACKS";
        public static const HELIPAD:String = "HELIPAD";
        public static const TRAININGFIELD:String = "TRAININGFIELD";
        public static const TANKFACTORY:String = "TANKFACTORY";
        public static const HANDWASHSTATION:String = "HANDWASHSTATION";
        public static const AEROSPACELAB:String = "AEROSPACELAB";

        public static const BEAVER:String = "BEAVER";
        public static const COMPUTER:String = "COMPUTER";
        public static const SOLDIER:String = "SOLDIER";
        public static const BASHER:String = "BASHER";
        public static const MINER:String = "MINER";
        public static const DRONE:String = "DRONE";
        public static const TANK:String = "TANK";
        public static const COMMANDER:String = "COMMANDER";
        public static const LAUNCHER:String = "LAUNCHER";
        public static const MISSILE:String = "MISSILE";

        public function RobotType() {
        }

        public static function values():Array {
            return [
                HQ,
                TOWER,
                SUPPLYDEPOT,
                TECHNOLOGYINSTITUTE,
                BARRACKS,
                HELIPAD,
                TRAININGFIELD,
                TANKFACTORY,
                HANDWASHSTATION,
                AEROSPACELAB,
                BEAVER,
                COMPUTER,
                SOLDIER,
                BASHER,
                MINER,
                DRONE,
                TANK,
                COMMANDER,
                LAUNCHER,
                MISSILE
            ];
        }

        public static function buildings():Array {
            return [
                HQ,
                TOWER,
                SUPPLYDEPOT,
                TECHNOLOGYINSTITUTE,
                BARRACKS,
                HELIPAD,
                TRAININGFIELD,
                TANKFACTORY,
                HANDWASHSTATION,
                AEROSPACELAB
            ];
        }

        public static function ground():Array {
            return [
                BEAVER,
                COMPUTER,
                SOLDIER,
                BASHER,
                MINER,
                TANK,
                COMMANDER,
                LAUNCHER,
                MISSILE
            ];
        }

        public static function air():Array {
            return []; // TODO air types
        }

        // TODO fix values
        public static function maxEnergon(type:String):Number {
            switch (type) {
                case HQ:
                    return 2000;
                case TOWER:
                    return 1000;
                case SUPPLYDEPOT:
                case TECHNOLOGYINSTITUTE:
                case BARRACKS:
                case HELIPAD:
                case TRAININGFIELD:
                case TANKFACTORY:
                case HANDWASHSTATION:
                case AEROSPACELAB:
                    return 100;
                case BEAVER:
                    return 30;
                case MINER:
                    return 50;
                case COMPUTER:
                    return 1;
                case SOLDIER:
                    return 40;
                case BASHER:
                    return 50;
                case DRONE:
                    return 70;
                case TANK:
                    return 160;
                case COMMANDER:
                    return 120;
                case LAUNCHER:
                    return 400;
                case MISSILE:
                    return 3;
            }
            throw new ArgumentError("Unknown type: " + type);
        }

        public static function movementDelay(type:String):uint {
            return 1;
        }

        public static function movementDelayDiagonal(type:String):uint {
            return 1;
        }

        public static function attackDelay(type:String):uint {
            return 0;
        }
    }
}

package battlecode.common {

    public class RobotType {
        public static const HQ:String = "HQ";
        public static const TOWER:String = "TOWER";

        public static const SUPPLYDEPOT:String = "SUPPLYDEPOT";
        public static const TECHNOLOGYINSTITUTE:String = "TECHNOLOGYINSTITUTE";
        public static const BARRACKS:String = "BARRACKS";
        public static const HELIPAD:String = "HELIPAD";
        public static const TRAININGFIELD:String = "TRAININGFIELD";
        public static const TANKFACTORY:String = "TANKFACTORY";
        public static const HANDWASHSTATION:String = "HANDWASHSTATION";
        public static const AEROSPACELAB:String = "AEROSPACELAB";

        public static const BEAVER:String = "BEAVER";
        public static const COMPUTER:String = "COMPUTER";
        public static const SOLDIER:String = "SOLDIER";
        public static const BASHER:String = "BASHER";
        public static const MINER:String = "MINER";
        public static const DRONE:String = "DRONE";
        public static const TANK:String = "TANK";
        public static const COMMANDER:String = "COMMANDER";
        public static const LAUNCHER:String = "LAUNCHER";
        public static const MISSILE:String = "MISSILE";

        public function RobotType() {
        }

        public static function values():Array {
            return [
                HQ,
                TOWER,
                SUPPLYDEPOT,
                TECHNOLOGYINSTITUTE,
                BARRACKS,
                HELIPAD,
                TRAININGFIELD,
                TANKFACTORY,
                HANDWASHSTATION,
                AEROSPACELAB,
                BEAVER,
                COMPUTER,
                SOLDIER,
                BASHER,
                MINER,
                DRONE,
                TANK,
                COMMANDER,
                LAUNCHER,
                MISSILE
            ];
        }

        public static function buildings():Array {
            return [
                HQ,
                TOWER,
                SUPPLYDEPOT,
                TECHNOLOGYINSTITUTE,
                BARRACKS,
                HELIPAD,
                TRAININGFIELD,
                TANKFACTORY,
                HANDWASHSTATION,
                AEROSPACELAB
            ];
        }

        public static function ground():Array {
            return [
                BEAVER,
                COMPUTER,
                SOLDIER,
                BASHER,
                MINER,
                TANK,
                COMMANDER,
                LAUNCHER,
                MISSILE
            ];
        }

        public static function air():Array {
            return []; // TODO air types
        }

        public static function maxEnergon(type:String):Number {
            switch (type) {
                case HQ:
                    return 2000;
                case TOWER:
                    return 1000;
                case SUPPLYDEPOT:
                case TECHNOLOGYINSTITUTE:
                case BARRACKS:
                case HELIPAD:
                case TRAININGFIELD:
                case TANKFACTORY:
                case HANDWASHSTATION:
                case AEROSPACELAB:
                    return 100;
                case BEAVER:
                    return 30;
                case MINER:
                    return 50;
                case COMPUTER:
                    return 1;
                case SOLDIER:
                    return 40;
                case BASHER:
                    return 50;
                case DRONE:
                    return 70;
                case TANK:
                    return 160;
                case COMMANDER:
                    return 120;
                case LAUNCHER:
                    return 400;
                case MISSILE:
                    return 3;
            }
            throw new ArgumentError("Unknown type: " + type);
        }

        public static function movementDelay(type:String):uint {
            return 1;
        }

        public static function movementDelayDiagonal(type:String):uint {
            return 1;
        }

        public static function attackDelay(type:String):uint {
            return 0;
        }
    }
}

remove TODO

remove TODO


//
// Nenya library - tools for developing networked games
// Copyright (C) 2002-2010 Three Rings Design, Inc., All Rights Reserved
// http://www.threerings.net/code/nenya/
//
// This library is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published
// by the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

package com.threerings.cast {

import flash.display.Bitmap;
import flash.display.Sprite;

import flash.geom.Point;

import flash.events.Event;

import com.threerings.media.Tickable;
import com.threerings.util.StringUtil;

public class MultiFrameBitmap extends Sprite
    implements Tickable
{
    public function MultiFrameBitmap (frames :Array, fps :Number)
    {
        _frames = frames;
        _bitmap = new Bitmap();
        _fps = fps;
        _frameRate = fps / 1000.0;
        addChild(_bitmap);
        setFrame(0);
    }

    public function tick (tickStamp :int) :void
    {
        if (_start == 0) {
            _start = tickStamp;
        }

        var elapsedTime :int = (tickStamp - _start);
        var frameIndex :int = Math.floor(elapsedTime * _frameRate) % _frames.length;
        setFrame(frameIndex);
    }

    protected function setFrame (index :int) :void
    {
        if (_curFrameIndex != index) {
            _bitmap.bitmapData = Bitmap(_frames[index]).bitmapData;
            _curFrameIndex = index;
        }
    }

    public function getFrame (index :int) :Bitmap
    {
        return _frames[index];
    }

    public function getFrameCount () :int
    {
        return _frames.length;
    }

    public function hitTest (stageX :int, stageY :int) :Boolean
    {
        if (_curFrameIndex == -1) {
            return false;
        } else {
            if (_bitmap.hitTestPoint(stageX, stageY, true)) {
                // Doesn't even hit the bounds...
                return false;
            }
            // Check the actual pixels...
            var pt :Point = _bitmap.globalToLocal(new Point(stageX, stageY));
            return _bitmap.bitmapData.hitTest(new Point(0, 0), 0, pt);
        }
    }

    public function clone () :MultiFrameBitmap
    {
        return new MultiFrameBitmap(_frames, _fps);
    }

    protected var _frames :Array;

    protected var _bitmap :Bitmap;

    protected var _start :int;

    protected var _frameRate :Number;

    protected var _fps :Number;

    protected var _curFrameIndex :int = -1;
}
}

//
// Nenya library - tools for developing networked games
// Copyright (C) 2002-2010 Three Rings Design, Inc., All Rights Reserved
// http://www.threerings.net/code/nenya/
//
// This library is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published
// by the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

package com.threerings.cast {

import flash.display.Bitmap;
import flash.display.Sprite;

import flash.geom.Point;

import flash.events.Event;

import com.threerings.media.Tickable;
import com.threerings.util.StringUtil;

public class MultiFrameBitmap extends Sprite
    implements Tickable
{
    public function MultiFrameBitmap (frames :Array, fps :Number)
    {
        _frames = frames;
        _bitmap = new Bitmap();
        _fps = fps;
        _frameRate = fps / 1000.0;
        addChild(_bitmap);
        setFrame(0);
    }

    public function tick (tickStamp :int) :void
    {
        if (_start == 0) {
            _start = tickStamp;
        }

        var elapsedTime :int = (tickStamp - _start);
        var frameIndex :int = Math.floor(elapsedTime * _frameRate) % _frames.length;
        setFrame(frameIndex);
    }

    protected function setFrame (index :int) :void
    {
        if (_curFrameIndex != index) {
            _bitmap.bitmapData = Bitmap(_frames[index]).bitmapData;
            _curFrameIndex = index;
        }
    }

    public function getFrame (index :int) :Bitmap
    {
        return _frames[index];
    }

    public function getFrameCount () :int
    {
        return _frames.length;
    }

    public function hitTest (stageX :int, stageY :int) :Boolean
    {
        if (_curFrameIndex == -1) {
            return false;
        } else {
            if (!_bitmap.hitTestPoint(stageX, stageY, true)) {
                // Doesn't even hit the bounds...
                return false;
            }
            // Check the actual pixels...
            var pt :Point = _bitmap.globalToLocal(new Point(stageX, stageY));
            return _bitmap.bitmapData.hitTest(new Point(0, 0), 0, pt);
        }
    }

    public function clone () :MultiFrameBitmap
    {
        return new MultiFrameBitmap(_frames, _fps);
    }

    protected var _frames :Array;

    protected var _bitmap :Bitmap;

    protected var _start :int;

    protected var _frameRate :Number;

    protected var _fps :Number;

    protected var _curFrameIndex :int = -1;
}
}

Fix some reversed logic.

Fix some reversed logic.

git-svn-id: b675b909355d5cf946977f44a8ec5a6ceb3782e4@990 ed5b42cb-e716-0410-a449-f6a68f950b19


package aerys.minko.render
{
	import aerys.minko.ns.minko_render;
	import aerys.minko.render.geometry.Geometry;
	import aerys.minko.render.geometry.stream.IVertexStream;
	import aerys.minko.render.geometry.stream.StreamUsage;
	import aerys.minko.render.geometry.stream.VertexStream;
	import aerys.minko.render.geometry.stream.format.VertexComponent;
	import aerys.minko.render.geometry.stream.format.VertexFormat;
	import aerys.minko.render.resource.Context3DResource;
	import aerys.minko.render.resource.IndexBuffer3DResource;
	import aerys.minko.render.resource.Program3DResource;
	import aerys.minko.render.resource.VertexBuffer3DResource;
	import aerys.minko.render.resource.texture.ITextureResource;
	import aerys.minko.render.shader.binding.IBinder;
	import aerys.minko.type.binding.DataBindings;
	import aerys.minko.type.enum.Blending;
	import aerys.minko.type.enum.ColorMask;
	import aerys.minko.type.enum.TriangleCulling;
	import aerys.minko.type.math.Matrix4x4;
	import aerys.minko.type.math.Vector4;

	import flash.display3D.Context3DProgramType;
	import flash.utils.Dictionary;

	/**
	 * DrawCall objects contain all the shader constants and buffer settings required
	 * to perform drawing operations using the Stage3D API.
	 * @author Jean-Marc Le Roux
	 *
	 */
	public final class DrawCall
	{
		use namespace minko_render;

		private static const PROGRAM_TYPE_VERTEX	: String			= Context3DProgramType.VERTEX;
		private static const PROGRAM_TYPE_FRAGMENT	: String			= Context3DProgramType.FRAGMENT;
		private static const NUM_TEXTURES			: uint				= 8;
		private static const NUM_VERTEX_BUFFERS		: uint				= 8;

		private static const TMP_VECTOR4			: Vector4			= new Vector4();
		private static const TMP_NUMBERS			: Vector.<Number>	= new Vector.<Number>(0xffff, true);
		private static const TMP_INTS				: Vector.<int>		= new Vector.<int>(0xffff, true);

		private var _bindings			: Object							= null;

		private var _vsInputComponents	: Vector.<VertexComponent>			= null;
		private var _vsInputIndices		: Vector.<uint>						= null;
		private var _cpuConstants		: Dictionary						= null;
		private var _vsConstants		: Vector.<Number>					= null;
		private var _fsConstants		: Vector.<Number>					= null;
		private var _fsTextures			: Vector.<ITextureResource>			= new Vector.<ITextureResource>(NUM_TEXTURES, true);

		// states
		private var _indexBuffer		: IndexBuffer3DResource				= null;
		private var _firstIndex			: int								= 0;
		private var _numTriangles		: int								= -1;

		private var _vertexBuffers		: Vector.<VertexBuffer3DResource>	= new Vector.<VertexBuffer3DResource>(NUM_VERTEX_BUFFERS, true);
		private var _numVertexComponents: uint								= 0;
		private var _offsets			: Vector.<int>						= new Vector.<int>(8, true);
		private var _formats			: Vector.<String>					= new Vector.<String>(8, true);

		private var _blending			: uint								= 0;
		private var _blendingSource		: String							= null;
		private var _blendingDest		: String							= null;

		private var _triangleCulling	: uint								= 0;
		private var _triangleCullingStr	: String							= null;

		private var _colorMask			: uint								= 0;
		private var _colorMaskR			: Boolean							= true;
		private var _colorMaskG			: Boolean							= true;
		private var _colorMaskB			: Boolean							= true;
		private var _colorMaskA			: Boolean							= true;

		private var _enabled			: Boolean							= true;

		private var _depth				: Number							= 0.;
		private var _invalidDepth		: Boolean							= false;
		private var _localToWorld		: Matrix4x4							= null;
		private var _worldToScreen		: Matrix4x4							= null;

		public function get vertexComponents() : Vector.<VertexComponent>
		{
			return _vsInputComponents;
		}

		public function get blending() : uint
		{
			return _blending;
		}
		public function set blending(value : uint) : void
		{
			_blending = value;
			_blendingSource = Blending.STRINGS[int(value & 0xffff)];
			_blendingDest	= Blending.STRINGS[int(value >>> 16)]
		}

		public function get triangleCulling() : uint
		{
			return _triangleCulling;
		}
		public function set triangleCulling(value : uint) : void
		{
			_triangleCulling = value;
			_triangleCullingStr = TriangleCulling.STRINGS[value];
		}

		public function get colorMask() : uint
		{
			return _colorMask;
		}
		public function set colorMask(value : uint) : void
		{
			_colorMask = value;
			_colorMaskR = (value & ColorMask.RED) != 0;
			_colorMaskG = (value & ColorMask.GREEN) != 0;
			_colorMaskB = (value & ColorMask.BLUE) != 0;
			_colorMaskA = (value & ColorMask.ALPHA) != 0;
		}

		public function get enabled() : Boolean
		{
			return _enabled;
		}
		public function set enabled(value : Boolean) : void
		{
			_enabled = value;
		}

		public function get depth() : Number
		{
			if (_invalidDepth)
			{
				_invalidDepth = false;

				if (_localToWorld != null && _worldToScreen != null)
				{
					var worldSpacePosition 	: Vector4	= _localToWorld.transformVector(
						Vector4.ZERO, TMP_VECTOR4
					);
					var screenSpacePosition : Vector4 	= _worldToScreen.transformVector(
						worldSpacePosition, TMP_VECTOR4
					);

					_depth = screenSpacePosition.z / screenSpacePosition.w;
				}
			}

			return _depth;
		}

		public function configure(program		: Program3DResource,
								  geometry		: Geometry,
								  meshBindings	: DataBindings,
								  sceneBindings	: DataBindings,
								  computeDepth	: Boolean) : void
		{
//			if (_bindings != null)
//				unsetBindings(meshBindings, sceneBindings);

			_invalidDepth = computeDepth;

			setProgram(program);
			updateGeometry(geometry);
			setGeometry(geometry);
			setBindings(meshBindings, sceneBindings, computeDepth);
		}

		public function unsetBindings(meshBindings	: DataBindings,
									  sceneBindings	: DataBindings) : void
		{
			for (var parameter : String in _bindings)
			{
				meshBindings.removeCallback(parameter, parameterChangedHandler);
				sceneBindings.removeCallback(parameter, parameterChangedHandler);
			}

			if (sceneBindings.hasCallback('worldToScreen', transformChangedHandler))
				sceneBindings.removeCallback('worldToScreen', transformChangedHandler);

			if (meshBindings.hasCallback('localToWorld', transformChangedHandler))
				meshBindings.removeCallback('localToWorld', transformChangedHandler);
		}

		private function setProgram(program : Program3DResource) : void
		{
			_cpuConstants		= new Dictionary();
			_vsConstants		= program._vsConstants.concat();
			_fsConstants		= program._fsConstants.concat();
			_fsTextures			= program._fsTextures.concat();
			_vsInputComponents	= program._vertexInputComponents;
			_vsInputIndices		= program._vertexInputIndices;
			_bindings			= program._bindings;

			triangleCulling		= TriangleCulling.FRONT;
			blending			= Blending.NORMAL;
			colorMask			= ColorMask.RGBA;
		}

		 /**
		  * Ask geometry to compute additional vertex data if needed for this drawcall.
		  */
		public function updateGeometry(geometry : Geometry) : void
		{
			var vertexFormat : VertexFormat	= geometry.format;

			if (_vsInputComponents.indexOf(VertexComponent.TANGENT) >= 0
				&& !vertexFormat.hasComponent(VertexComponent.TANGENT))
			{
				geometry.computeTangentSpace();
			}
			else if (_vsInputComponents.indexOf(VertexComponent.NORMAL) >= 0
				&& !vertexFormat.hasComponent(VertexComponent.NORMAL))
			{
				geometry.computeNormals();
			}
		}

		/**
		 * Obtain a reference to each buffer and offset that apply() may possibly need.
		 *
		 */
		public function setGeometry(geometry : Geometry, frame : uint = 0) : void
		{
			_numVertexComponents = _vsInputComponents.length;
			_indexBuffer		 = geometry.indexStream.resource;
			_firstIndex			 = geometry.firstIndex;
			_numTriangles		 = geometry.numTriangles;

			for (var i : uint = 0; i < _numVertexComponents; ++i)
			{
				var component : VertexComponent	= _vsInputComponents[i];
				var index	  : uint			= _vsInputIndices[i];

				if (component)
				{
					var vertexStream	: IVertexStream = geometry.getVertexStream(index + frame);
					var stream	 		: VertexStream	= vertexStream.getStreamByComponent(component);

					if (stream == null)
					{
						throw new Error(
							'Missing vertex component: \'' + component.toString() + '\'.'
						);
					}

					_vertexBuffers[i]	= stream.resource;
					_formats[i]			= component.nativeFormatString;
					_offsets[i]			= stream.format.getOffsetForComponent(component);
				}
			}
		}

		/**
		 * @fixme There is a bug here
		 * @fixme We splitted properties between scene and mesh
		 * @fixme it should be done on the compiler also to avoid this ugly hack
		 */
		private function setBindings(meshBindings	: DataBindings,
									 sceneBindings	: DataBindings,
									 computeDepth	: Boolean) : void
		{
			for (var parameter : String in _bindings)
			{
				meshBindings.addCallback(parameter, parameterChangedHandler);
				sceneBindings.addCallback(parameter, parameterChangedHandler);

				if (meshBindings.propertyExists(parameter))
					setParameter(parameter, meshBindings.getProperty(parameter));
				else if (sceneBindings.propertyExists(parameter))
					setParameter(parameter, sceneBindings.getProperty(parameter));
			}

			if (computeDepth)
			{
				_worldToScreen = sceneBindings.getProperty('worldToScreen') as Matrix4x4;
				_localToWorld = meshBindings.getProperty('localToWorld') as Matrix4x4;

				sceneBindings.addCallback('worldToScreen', transformChangedHandler);
				meshBindings.addCallback('localToWorld', transformChangedHandler);

				_invalidDepth = true;
			}
		}

		public function apply(context : Context3DResource, previous : DrawCall) : uint
		{
			if (!_enabled)
				return 0;

			context.setColorMask(_colorMaskR, _colorMaskG, _colorMaskB, _colorMaskA)
				   .setProgramConstantsFromVector(PROGRAM_TYPE_VERTEX, 0, _vsConstants)
				   .setProgramConstantsFromVector(PROGRAM_TYPE_FRAGMENT, 0, _fsConstants);

			var numTextures	: uint	= _fsTextures.length;
			var maxTextures	: uint	= previous ? previous._fsTextures.length : NUM_TEXTURES;
			var maxBuffers	: uint	= previous ? previous._numVertexComponents : NUM_VERTEX_BUFFERS;
			var i 			: uint 	= 0;

			// setup textures
			for (i = 0; i < numTextures; ++i)
			{
				context.setTextureAt(
					i,
					(_fsTextures[i] as ITextureResource).getNativeTexture(context)
				);
			}

			while (i < maxTextures)
				context.setTextureAt(i++, null);

			// setup buffers
			for (i = 0; i < _numVertexComponents; ++i)
			{
				context.setVertexBufferAt(
					i,
					(_vertexBuffers[i] as VertexBuffer3DResource).getVertexBuffer3D(context),
					_offsets[i],
					_formats[i]
				);
			}

			while (i < maxBuffers)
				context.setVertexBufferAt(i++, null);

			// draw triangles
			context.drawTriangles(
				_indexBuffer.getIndexBuffer3D(context),
				_firstIndex,
				_numTriangles
			);

			return _numTriangles == -1 ? _indexBuffer.numIndices / 3 : _numTriangles;
		}

		public function setParameter(name : String, value : Object) : void
		{
			var binding : IBinder = _bindings[name] as IBinder;

			if (binding != null)
				binding.set(_cpuConstants, _vsConstants, _fsConstants, _fsTextures, value);
		}

		private function parameterChangedHandler(dataBindings	: DataBindings,
												 property		: String,
												 oldValue		: Object,
												 newValue		: Object) : void
		{
			newValue !== null && setParameter(property, newValue);
		}

		private function transformChangedHandler(bindings 	: DataBindings,
												 property 	: String,
												 oldValue	: Matrix4x4,
												 newValue 	: Matrix4x4) : void
		{
			if (property == 'worldToScreen')
				_worldToScreen = newValue;
			else if (property == 'localToWorld')
				_localToWorld = newValue;

			_invalidDepth = true;
		}
	}
}

package aerys.minko.render
{
	import aerys.minko.ns.minko_render;
	import aerys.minko.render.geometry.Geometry;
	import aerys.minko.render.geometry.stream.IVertexStream;
	import aerys.minko.render.geometry.stream.StreamUsage;
	import aerys.minko.render.geometry.stream.VertexStream;
	import aerys.minko.render.geometry.stream.format.VertexComponent;
	import aerys.minko.render.geometry.stream.format.VertexFormat;
	import aerys.minko.render.resource.Context3DResource;
	import aerys.minko.render.resource.IndexBuffer3DResource;
	import aerys.minko.render.resource.Program3DResource;
	import aerys.minko.render.resource.VertexBuffer3DResource;
	import aerys.minko.render.resource.texture.ITextureResource;
	import aerys.minko.render.shader.binding.IBinder;
	import aerys.minko.type.binding.DataBindings;
	import aerys.minko.type.enum.Blending;
	import aerys.minko.type.enum.ColorMask;
	import aerys.minko.type.enum.TriangleCulling;
	import aerys.minko.type.math.Matrix4x4;
	import aerys.minko.type.math.Vector4;

	import flash.display3D.Context3DProgramType;
	import flash.utils.Dictionary;

	/**
	 * DrawCall objects contain all the shader constants and buffer settings required
	 * to perform drawing operations using the Stage3D API.
	 * @author Jean-Marc Le Roux
	 *
	 */
	public final class DrawCall
	{
		use namespace minko_render;

		private static const PROGRAM_TYPE_VERTEX	: String			= Context3DProgramType.VERTEX;
		private static const PROGRAM_TYPE_FRAGMENT	: String			= Context3DProgramType.FRAGMENT;
		private static const NUM_TEXTURES			: uint				= 8;
		private static const NUM_VERTEX_BUFFERS		: uint				= 8;

		private static const TMP_VECTOR4			: Vector4			= new Vector4();
		private static const TMP_NUMBERS			: Vector.<Number>	= new Vector.<Number>(0xffff, true);
		private static const TMP_INTS				: Vector.<int>		= new Vector.<int>(0xffff, true);

		private var _bindings			: Object							= null;

		private var _vsInputComponents	: Vector.<VertexComponent>			= null;
		private var _vsInputIndices		: Vector.<uint>						= null;
		private var _cpuConstants		: Dictionary						= null;
		private var _vsConstants		: Vector.<Number>					= null;
		private var _fsConstants		: Vector.<Number>					= null;
		private var _fsTextures			: Vector.<ITextureResource>			= new Vector.<ITextureResource>(NUM_TEXTURES, true);

		// states
		private var _indexBuffer		: IndexBuffer3DResource				= null;
		private var _firstIndex			: int								= 0;
		private var _numTriangles		: int								= -1;

		private var _vertexBuffers		: Vector.<VertexBuffer3DResource>	= new Vector.<VertexBuffer3DResource>(NUM_VERTEX_BUFFERS, true);
		private var _numVertexComponents: uint								= 0;
		private var _offsets			: Vector.<int>						= new Vector.<int>(8, true);
		private var _formats			: Vector.<String>					= new Vector.<String>(8, true);

		private var _blending			: uint								= 0;
		private var _blendingSource		: String							= null;
		private var _blendingDest		: String							= null;

		private var _triangleCulling	: uint								= 0;
		private var _triangleCullingStr	: String							= null;

		private var _colorMask			: uint								= 0;
		private var _colorMaskR			: Boolean							= true;
		private var _colorMaskG			: Boolean							= true;
		private var _colorMaskB			: Boolean							= true;
		private var _colorMaskA			: Boolean							= true;

		private var _enabled			: Boolean							= true;

		private var _depth				: Number							= 0.;
		private var _invalidDepth		: Boolean							= false;
		private var _localToWorld		: Matrix4x4							= null;
		private var _worldToScreen		: Matrix4x4							= null;

		public function get vertexComponents() : Vector.<VertexComponent>
		{
			return _vsInputComponents;
		}

		public function get blending() : uint
		{
			return _blending;
		}
		public function set blending(value : uint) : void
		{
			_blending = value;
			_blendingSource = Blending.STRINGS[int(value & 0xffff)];
			_blendingDest	= Blending.STRINGS[int(value >>> 16)]
		}

		public function get triangleCulling() : uint
		{
			return _triangleCulling;
		}
		public function set triangleCulling(value : uint) : void
		{
			_triangleCulling = value;
			_triangleCullingStr = TriangleCulling.STRINGS[value];
		}

		public function get colorMask() : uint
		{
			return _colorMask;
		}
		public function set colorMask(value : uint) : void
		{
			_colorMask = value;
			_colorMaskR = (value & ColorMask.RED) != 0;
			_colorMaskG = (value & ColorMask.GREEN) != 0;
			_colorMaskB = (value & ColorMask.BLUE) != 0;
			_colorMaskA = (value & ColorMask.ALPHA) != 0;
		}

		public function get enabled() : Boolean
		{
			return _enabled;
		}
		public function set enabled(value : Boolean) : void
		{
			_enabled = value;
		}

		public function get depth() : Number
		{
			if (_invalidDepth && _enabled)
			{
				_invalidDepth = false;

				if (_localToWorld != null && _worldToScreen != null)
				{
					var worldSpacePosition 	: Vector4	= _localToWorld.transformVector(
						Vector4.ZERO, TMP_VECTOR4
					);
					var screenSpacePosition : Vector4 	= _worldToScreen.transformVector(
						worldSpacePosition, TMP_VECTOR4
					);

					_depth = screenSpacePosition.z / screenSpacePosition.w;
				}
			}

			return _depth;
		}

		public function configure(program		: Program3DResource,
								  geometry		: Geometry,
								  meshBindings	: DataBindings,
								  sceneBindings	: DataBindings,
								  computeDepth	: Boolean) : void
		{
//			if (_bindings != null)
//				unsetBindings(meshBindings, sceneBindings);

			_invalidDepth = computeDepth;

			setProgram(program);
			updateGeometry(geometry);
			setGeometry(geometry);
			setBindings(meshBindings, sceneBindings, computeDepth);
		}

		public function unsetBindings(meshBindings	: DataBindings,
									  sceneBindings	: DataBindings) : void
		{
			for (var parameter : String in _bindings)
			{
				meshBindings.removeCallback(parameter, parameterChangedHandler);
				sceneBindings.removeCallback(parameter, parameterChangedHandler);
			}

			if (sceneBindings.hasCallback('worldToScreen', transformChangedHandler))
				sceneBindings.removeCallback('worldToScreen', transformChangedHandler);

			if (meshBindings.hasCallback('localToWorld', transformChangedHandler))
				meshBindings.removeCallback('localToWorld', transformChangedHandler);
		}

		private function setProgram(program : Program3DResource) : void
		{
			_cpuConstants		= new Dictionary();
			_vsConstants		= program._vsConstants.concat();
			_fsConstants		= program._fsConstants.concat();
			_fsTextures			= program._fsTextures.concat();
			_vsInputComponents	= program._vertexInputComponents;
			_vsInputIndices		= program._vertexInputIndices;
			_bindings			= program._bindings;

			triangleCulling		= TriangleCulling.FRONT;
			blending			= Blending.NORMAL;
			colorMask			= ColorMask.RGBA;
		}

		 /**
		  * Ask geometry to compute additional vertex data if needed for this drawcall.
		  */
		public function updateGeometry(geometry : Geometry) : void
		{
			var vertexFormat : VertexFormat	= geometry.format;

			if (_vsInputComponents.indexOf(VertexComponent.TANGENT) >= 0
				&& !vertexFormat.hasComponent(VertexComponent.TANGENT))
			{
				geometry.computeTangentSpace();
			}
			else if (_vsInputComponents.indexOf(VertexComponent.NORMAL) >= 0
				&& !vertexFormat.hasComponent(VertexComponent.NORMAL))
			{
				geometry.computeNormals();
			}
		}

		/**
		 * Obtain a reference to each buffer and offset that apply() may possibly need.
		 *
		 */
		public function setGeometry(geometry : Geometry, frame : uint = 0) : void
		{
			_numVertexComponents = _vsInputComponents.length;
			_indexBuffer		 = geometry.indexStream.resource;
			_firstIndex			 = geometry.firstIndex;
			_numTriangles		 = geometry.numTriangles;

			for (var i : uint = 0; i < _numVertexComponents; ++i)
			{
				var component : VertexComponent	= _vsInputComponents[i];
				var index	  : uint			= _vsInputIndices[i];

				if (component)
				{
					var vertexStream	: IVertexStream = geometry.getVertexStream(index + frame);
					var stream	 		: VertexStream	= vertexStream.getStreamByComponent(component);

					if (stream == null)
					{
						throw new Error(
							'Missing vertex component: \'' + component.toString() + '\'.'
						);
					}

					_vertexBuffers[i]	= stream.resource;
					_formats[i]			= component.nativeFormatString;
					_offsets[i]			= stream.format.getOffsetForComponent(component);
				}
			}
		}

		/**
		 * @fixme There is a bug here
		 * @fixme We splitted properties between scene and mesh
		 * @fixme it should be done on the compiler also to avoid this ugly hack
		 */
		private function setBindings(meshBindings	: DataBindings,
									 sceneBindings	: DataBindings,
									 computeDepth	: Boolean) : void
		{
			for (var parameter : String in _bindings)
			{
				meshBindings.addCallback(parameter, parameterChangedHandler);
				sceneBindings.addCallback(parameter, parameterChangedHandler);

				if (meshBindings.propertyExists(parameter))
					setParameter(parameter, meshBindings.getProperty(parameter));
				else if (sceneBindings.propertyExists(parameter))
					setParameter(parameter, sceneBindings.getProperty(parameter));
			}

			if (computeDepth)
			{
				_worldToScreen = sceneBindings.getProperty('worldToScreen') as Matrix4x4;
				_localToWorld = meshBindings.getProperty('localToWorld') as Matrix4x4;

				sceneBindings.addCallback('worldToScreen', transformChangedHandler);
				meshBindings.addCallback('localToWorld', transformChangedHandler);

				_invalidDepth = true;
			}
		}

		public function apply(context : Context3DResource, previous : DrawCall) : uint
		{
			if (!_enabled)
				return 0;

			context.setColorMask(_colorMaskR, _colorMaskG, _colorMaskB, _colorMaskA)
				   .setProgramConstantsFromVector(PROGRAM_TYPE_VERTEX, 0, _vsConstants)
				   .setProgramConstantsFromVector(PROGRAM_TYPE_FRAGMENT, 0, _fsConstants);

			var numTextures	: uint	= _fsTextures.length;
			var maxTextures	: uint	= previous ? previous._fsTextures.length : NUM_TEXTURES;
			var maxBuffers	: uint	= previous ? previous._numVertexComponents : NUM_VERTEX_BUFFERS;
			var i 			: uint 	= 0;

			// setup textures
			for (i = 0; i < numTextures; ++i)
			{
				context.setTextureAt(
					i,
					(_fsTextures[i] as ITextureResource).getNativeTexture(context)
				);
			}

			while (i < maxTextures)
				context.setTextureAt(i++, null);

			// setup buffers
			for (i = 0; i < _numVertexComponents; ++i)
			{
				context.setVertexBufferAt(
					i,
					(_vertexBuffers[i] as VertexBuffer3DResource).getVertexBuffer3D(context),
					_offsets[i],
					_formats[i]
				);
			}

			while (i < maxBuffers)
				context.setVertexBufferAt(i++, null);

			// draw triangles
			context.drawTriangles(
				_indexBuffer.getIndexBuffer3D(context),
				_firstIndex,
				_numTriangles
			);

			return _numTriangles == -1 ? _indexBuffer.numIndices / 3 : _numTriangles;
		}

		public function setParameter(name : String, value : Object) : void
		{
//			if (!_enabled)
//				return ;

			var binding : IBinder = _bindings[name] as IBinder;

			if (binding != null)
				binding.set(_cpuConstants, _vsConstants, _fsConstants, _fsTextures, value);
		}

		private function parameterChangedHandler(dataBindings	: DataBindings,
												 property		: String,
												 oldValue		: Object,
												 newValue		: Object) : void
		{
			newValue !== null && setParameter(property, newValue);
		}

		private function transformChangedHandler(bindings 	: DataBindings,
												 property 	: String,
												 oldValue	: Matrix4x4,
												 newValue 	: Matrix4x4) : void
		{
			if (property == 'worldToScreen')
				_worldToScreen = newValue;
			else if (property == 'localToWorld')
				_localToWorld = newValue;

			_invalidDepth = true;
		}
	}
}

update DrawCall.depth to do nothing if DrawCall._enabled = false


////////////////////////////////////////////////////////////////////////////////
//
//  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
{

/**
 *  @private
 *  This class is used to link additional classes into rpc.swc
 *  beyond those that are found by dependecy analysis starting
 *  from the classes specified in manifest.xml.
 */
internal class FlexJSUIClasses
{
	import org.apache.cordova.camera.Camera; Camera;
	import org.apache.cordova.Application; Application;
	import org.apache.cordova.Weinre; Weinre;

	import org.apache.flex.charts.core.CartesianChart; CartesianChart;
	import org.apache.flex.charts.core.ChartBase; ChartBase;
	import org.apache.flex.charts.core.IChart; IChart;
	import org.apache.flex.charts.core.ICartesianChartLayout; ICartesianChartLayout;
	import org.apache.flex.charts.core.IChartDataGroup; IChartDataGroup;
	import org.apache.flex.charts.core.IChartSeries; IChartSeries;
	import org.apache.flex.charts.core.IHorizontalAxisBead; IHorizontalAxisBead;
	import org.apache.flex.charts.core.IVerticalAxisBead; IVerticalAxisBead;
	import org.apache.flex.charts.core.IChartItemRenderer; IChartItemRenderer;
	import org.apache.flex.charts.core.IConnectedItemRenderer; IConnectedItemRenderer;
	import org.apache.flex.charts.core.PolarChart; PolarChart;
	import org.apache.flex.charts.supportClasses.ChartDataGroup; ChartDataGroup;
	import org.apache.flex.maps.google.Map; Map;

	import org.apache.flex.html.accessories.NumericOnlyTextInputBead; NumericOnlyTextInputBead;
	import org.apache.flex.html.accessories.PasswordInputBead; PasswordInputBead;
	import org.apache.flex.html.accessories.TextPromptBead; TextPromptBead;
    import org.apache.flex.html.beads.AlertView; AlertView;
	import org.apache.flex.html.beads.ButtonBarView; ButtonBarView;
	import org.apache.flex.html.beads.CheckBoxView; CheckBoxView;
    import org.apache.flex.html.beads.ComboBoxView; ComboBoxView;
    import org.apache.flex.html.beads.ContainerView; ContainerView;
    import org.apache.flex.html.beads.ControlBarMeasurementBead; ControlBarMeasurementBead;
    import org.apache.flex.html.beads.CSSButtonView; CSSButtonView;
	import org.apache.flex.html.beads.CSSTextButtonView; CSSTextButtonView;
	import org.apache.flex.html.beads.DropDownListView; DropDownListView;
	import org.apache.flex.html.beads.CloseButtonView; CloseButtonView;
    import org.apache.flex.html.beads.ImageButtonView; ImageButtonView;
	import org.apache.flex.html.beads.ImageView; ImageView;
    import org.apache.flex.html.beads.ListView; ListView;
    import org.apache.flex.html.beads.NumericStepperView; NumericStepperView;
    import org.apache.flex.html.beads.PanelView; PanelView;
    import org.apache.flex.html.beads.PanelWithControlBarView; PanelWithControlBarView;
	import org.apache.flex.html.beads.RadioButtonView; RadioButtonView;
    import org.apache.flex.html.beads.ScrollBarView; ScrollBarView;
	import org.apache.flex.html.beads.SimpleAlertView; SimpleAlertView;
    import org.apache.flex.html.beads.SingleLineBorderBead; SingleLineBorderBead;
	import org.apache.flex.html.beads.SliderView; SliderView;
	import org.apache.flex.html.beads.SliderThumbView; SliderThumbView;
	import org.apache.flex.html.beads.SliderTrackView; SliderTrackView;
	import org.apache.flex.html.beads.SolidBackgroundBead; SolidBackgroundBead;
    import org.apache.flex.html.beads.SpinnerView; SpinnerView;
    import org.apache.flex.html.beads.TextButtonMeasurementBead; TextButtonMeasurementBead;
	import org.apache.flex.html.beads.TextFieldLabelMeasurementBead; TextFieldLabelMeasurementBead;
    import org.apache.flex.html.beads.TextAreaView; TextAreaView;
    import org.apache.flex.html.beads.TextButtonView; TextButtonView;
    import org.apache.flex.html.beads.TextFieldView; TextFieldView;
    import org.apache.flex.html.beads.TextInputView; TextInputView;
    import org.apache.flex.html.beads.TextInputWithBorderView; TextInputWithBorderView;
    import org.apache.flex.html.beads.models.AlertModel; AlertModel;
    import org.apache.flex.html.beads.models.ArraySelectionModel; ArraySelectionModel;
    import org.apache.flex.html.beads.models.ComboBoxModel; ComboBoxModel;
	import org.apache.flex.html.beads.models.ImageModel; ImageModel;
	import org.apache.flex.html.beads.models.PanelModel; PanelModel;
    import org.apache.flex.html.beads.models.SingleLineBorderModel; SingleLineBorderModel;
	import org.apache.flex.html.beads.models.TextModel; TextModel;
    import org.apache.flex.html.beads.models.TitleBarModel; TitleBarModel;
	import org.apache.flex.html.beads.models.ToggleButtonModel; ToggleButtonModel;
	import org.apache.flex.html.beads.models.ValueToggleButtonModel; ValueToggleButtonModel;
    import org.apache.flex.html.beads.controllers.AlertController; AlertController;
	import org.apache.flex.html.beads.controllers.ComboBoxController; ComboBoxController;
    import org.apache.flex.html.beads.controllers.DropDownListController; DropDownListController;
	import org.apache.flex.html.beads.controllers.EditableTextKeyboardController; EditableTextKeyboardController;
    import org.apache.flex.html.beads.controllers.ItemRendererMouseController; ItemRendererMouseController;
    import org.apache.flex.html.beads.controllers.ListSingleSelectionMouseController; ListSingleSelectionMouseController;
	import org.apache.flex.html.beads.controllers.SliderMouseController; SliderMouseController;
	import org.apache.flex.html.beads.controllers.SpinnerMouseController; SpinnerMouseController;
    import org.apache.flex.html.beads.controllers.VScrollBarMouseController; VScrollBarMouseController;
	import org.apache.flex.html.beads.layouts.ButtonBarLayout; ButtonBarLayout;
    import org.apache.flex.html.beads.layouts.NonVirtualVerticalScrollingLayout; NonVirtualVerticalScrollingLayout;
	import org.apache.flex.html.beads.layouts.NonVirtualHorizontalScrollingLayout; NonVirtualHorizontalScrollingLayout;
    import org.apache.flex.html.beads.layouts.NonVirtualBasicLayout; NonVirtualBasicLayout;
    import org.apache.flex.html.beads.layouts.VScrollBarLayout; VScrollBarLayout;
	import org.apache.flex.html.beads.layouts.TileLayout; TileLayout;
    import org.apache.flex.html.beads.TextItemRendererFactoryForArrayData; TextItemRendererFactoryForArrayData;
	import org.apache.flex.html.beads.DataItemRendererFactoryForArrayData; DataItemRendererFactoryForArrayData;
	import org.apache.flex.html.supportClasses.NonVirtualDataGroup; NonVirtualDataGroup;
    import org.apache.flex.core.ItemRendererClassFactory; ItemRendererClassFactory;
	import org.apache.flex.core.FilledRectangle; FilledRectangle;
	import org.apache.flex.core.FormatBase; FormatBase;
	import org.apache.flex.events.CustomEvent; CustomEvent;
	import org.apache.flex.events.Event; Event;
	import org.apache.flex.events.MouseEvent; MouseEvent;
	import org.apache.flex.events.ValueEvent; ValueEvent;
	import org.apache.flex.utils.EffectTimer; EffectTimer;
	import org.apache.flex.utils.Timer; Timer;
	import org.apache.flex.utils.UIUtils; UIUtils;
    import org.apache.flex.core.SimpleStatesImpl; SimpleStatesImpl;
	import org.apache.flex.core.graphics.GraphicShape; GraphicShape;
	import org.apache.flex.core.graphics.Rect; Rect;
	import org.apache.flex.core.graphics.Ellipse; Ellipse;
	import org.apache.flex.core.graphics.Circle; Circle;
	import org.apache.flex.core.graphics.Path; Path;
	import org.apache.flex.core.graphics.SolidColor; SolidColor;
	import org.apache.flex.core.graphics.SolidColorStroke; SolidColorStroke;
	import org.apache.flex.core.graphics.Text; Text;
	import org.apache.flex.core.graphics.GraphicsContainer; GraphicsContainer;
	import org.apache.flex.core.graphics.LinearGradient; LinearGradient;
    import org.apache.flex.core.DropType; DropType;
    import org.apache.flex.core.DataBindingBase; DataBindingBase;
    import org.apache.flex.effects.PlatformWiper; PlatformWiper;

	import mx.core.ClassFactory; ClassFactory;
    import mx.states.AddItems; AddItems;
    import mx.states.SetEventHandler; SetEventHandler;
    import mx.states.SetProperty; SetProperty;
    import mx.states.State; State;
}

}

////////////////////////////////////////////////////////////////////////////////
//
//  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
{

/**
 *  @private
 *  This class is used to link additional classes into rpc.swc
 *  beyond those that are found by dependecy analysis starting
 *  from the classes specified in manifest.xml.
 */
internal class FlexJSUIClasses
{
	import org.apache.cordova.camera.Camera; Camera;
	import org.apache.cordova.Application; Application;
	import org.apache.cordova.Weinre; Weinre;

	import org.apache.flex.charts.core.CartesianChart; CartesianChart;
	import org.apache.flex.charts.core.ChartBase; ChartBase;
	import org.apache.flex.charts.core.IChart; IChart;
	import org.apache.flex.charts.core.ICartesianChartLayout; ICartesianChartLayout;
	import org.apache.flex.charts.core.IChartDataGroup; IChartDataGroup;
	import org.apache.flex.charts.core.IChartSeries; IChartSeries;
	import org.apache.flex.charts.core.IHorizontalAxisBead; IHorizontalAxisBead;
	import org.apache.flex.charts.core.IVerticalAxisBead; IVerticalAxisBead;
	import org.apache.flex.charts.core.IChartItemRenderer; IChartItemRenderer;
	import org.apache.flex.charts.core.IConnectedItemRenderer; IConnectedItemRenderer;
	import org.apache.flex.charts.core.PolarChart; PolarChart;
	import org.apache.flex.charts.supportClasses.ChartDataGroup; ChartDataGroup;
	import org.apache.flex.maps.google.Map; Map;

	import org.apache.flex.html.accessories.NumericOnlyTextInputBead; NumericOnlyTextInputBead;
	import org.apache.flex.html.accessories.PasswordInputBead; PasswordInputBead;
	import org.apache.flex.html.accessories.TextPromptBead; TextPromptBead;
    import org.apache.flex.html.beads.AlertView; AlertView;
	import org.apache.flex.html.beads.ButtonBarView; ButtonBarView;
	import org.apache.flex.html.beads.CheckBoxView; CheckBoxView;
    import org.apache.flex.html.beads.ComboBoxView; ComboBoxView;
    import org.apache.flex.html.beads.ContainerView; ContainerView;
    import org.apache.flex.html.beads.ControlBarMeasurementBead; ControlBarMeasurementBead;
    import org.apache.flex.html.beads.CSSButtonView; CSSButtonView;
	import org.apache.flex.html.beads.CSSTextButtonView; CSSTextButtonView;
	import org.apache.flex.html.beads.DropDownListView; DropDownListView;
	import org.apache.flex.html.beads.CloseButtonView; CloseButtonView;
    import org.apache.flex.html.beads.ImageButtonView; ImageButtonView;
	import org.apache.flex.html.beads.ImageView; ImageView;
    import org.apache.flex.html.beads.ListView; ListView;
    import org.apache.flex.html.beads.NumericStepperView; NumericStepperView;
    import org.apache.flex.html.beads.PanelView; PanelView;
    import org.apache.flex.html.beads.PanelWithControlBarView; PanelWithControlBarView;
	import org.apache.flex.html.beads.RadioButtonView; RadioButtonView;
    import org.apache.flex.html.beads.ScrollBarView; ScrollBarView;
	import org.apache.flex.html.beads.SimpleAlertView; SimpleAlertView;
    import org.apache.flex.html.beads.SingleLineBorderBead; SingleLineBorderBead;
	import org.apache.flex.html.beads.SliderView; SliderView;
	import org.apache.flex.html.beads.SliderThumbView; SliderThumbView;
	import org.apache.flex.html.beads.SliderTrackView; SliderTrackView;
	import org.apache.flex.html.beads.SolidBackgroundBead; SolidBackgroundBead;
    import org.apache.flex.html.beads.SpinnerView; SpinnerView;
    import org.apache.flex.html.beads.TextButtonMeasurementBead; TextButtonMeasurementBead;
	import org.apache.flex.html.beads.TextFieldLabelMeasurementBead; TextFieldLabelMeasurementBead;
    import org.apache.flex.html.beads.TextAreaView; TextAreaView;
    import org.apache.flex.html.beads.TextButtonView; TextButtonView;
    import org.apache.flex.html.beads.TextFieldView; TextFieldView;
    import org.apache.flex.html.beads.TextInputView; TextInputView;
    import org.apache.flex.html.beads.TextInputWithBorderView; TextInputWithBorderView;
    import org.apache.flex.html.beads.models.AlertModel; AlertModel;
    import org.apache.flex.html.beads.models.ArraySelectionModel; ArraySelectionModel;
    import org.apache.flex.html.beads.models.ComboBoxModel; ComboBoxModel;
	import org.apache.flex.html.beads.models.ImageModel; ImageModel;
	import org.apache.flex.html.beads.models.PanelModel; PanelModel;
    import org.apache.flex.html.beads.models.SingleLineBorderModel; SingleLineBorderModel;
	import org.apache.flex.html.beads.models.TextModel; TextModel;
    import org.apache.flex.html.beads.models.TitleBarModel; TitleBarModel;
	import org.apache.flex.html.beads.models.ToggleButtonModel; ToggleButtonModel;
	import org.apache.flex.html.beads.models.ValueToggleButtonModel; ValueToggleButtonModel;
    import org.apache.flex.html.beads.controllers.AlertController; AlertController;
	import org.apache.flex.html.beads.controllers.ComboBoxController; ComboBoxController;
    import org.apache.flex.html.beads.controllers.DropDownListController; DropDownListController;
	import org.apache.flex.html.beads.controllers.EditableTextKeyboardController; EditableTextKeyboardController;
    import org.apache.flex.html.beads.controllers.ItemRendererMouseController; ItemRendererMouseController;
    import org.apache.flex.html.beads.controllers.ListSingleSelectionMouseController; ListSingleSelectionMouseController;
	import org.apache.flex.html.beads.controllers.SliderMouseController; SliderMouseController;
	import org.apache.flex.html.beads.controllers.SpinnerMouseController; SpinnerMouseController;
    import org.apache.flex.html.beads.controllers.VScrollBarMouseController; VScrollBarMouseController;
	import org.apache.flex.html.beads.layouts.ButtonBarLayout; ButtonBarLayout;
    import org.apache.flex.html.beads.layouts.NonVirtualVerticalScrollingLayout; NonVirtualVerticalScrollingLayout;
	import org.apache.flex.html.beads.layouts.NonVirtualHorizontalScrollingLayout; NonVirtualHorizontalScrollingLayout;
    import org.apache.flex.html.beads.layouts.NonVirtualBasicLayout; NonVirtualBasicLayout;
    import org.apache.flex.html.beads.layouts.VScrollBarLayout; VScrollBarLayout;
	import org.apache.flex.html.beads.layouts.TileLayout; TileLayout;
    import org.apache.flex.html.beads.TextItemRendererFactoryForArrayData; TextItemRendererFactoryForArrayData;
	import org.apache.flex.html.beads.DataItemRendererFactoryForArrayData; DataItemRendererFactoryForArrayData;
	import org.apache.flex.html.supportClasses.NonVirtualDataGroup; NonVirtualDataGroup;
    import org.apache.flex.core.ItemRendererClassFactory; ItemRendererClassFactory;
	import org.apache.flex.core.FilledRectangle; FilledRectangle;
	import org.apache.flex.core.FormatBase; FormatBase;
	import org.apache.flex.events.CustomEvent; CustomEvent;
	import org.apache.flex.events.Event; Event;
	import org.apache.flex.events.MouseEvent; MouseEvent;
	import org.apache.flex.events.ValueEvent; ValueEvent;
	import org.apache.flex.utils.EffectTimer; EffectTimer;
	import org.apache.flex.utils.Timer; Timer;
	import org.apache.flex.utils.UIUtils; UIUtils;
    import org.apache.flex.core.SimpleStatesImpl; SimpleStatesImpl;
	import org.apache.flex.core.graphics.GraphicShape; GraphicShape;
	import org.apache.flex.core.graphics.Rect; Rect;
	import org.apache.flex.core.graphics.Ellipse; Ellipse;
	import org.apache.flex.core.graphics.Circle; Circle;
	import org.apache.flex.core.graphics.Path; Path;
	import org.apache.flex.core.graphics.SolidColor; SolidColor;
	import org.apache.flex.core.graphics.SolidColorStroke; SolidColorStroke;
	import org.apache.flex.core.graphics.Text; Text;
	import org.apache.flex.core.graphics.GraphicsContainer; GraphicsContainer;
	import org.apache.flex.core.graphics.LinearGradient; LinearGradient;
    import org.apache.flex.core.DropType; DropType;
    import org.apache.flex.core.DataBindingBase; DataBindingBase;
    import org.apache.flex.effects.PlatformWiper; PlatformWiper;
    import org.apache.flex.geom.Rectangle; Rectangle;

	import mx.core.ClassFactory; ClassFactory;
    import mx.states.AddItems; AddItems;
    import mx.states.SetEventHandler; SetEventHandler;
    import mx.states.SetProperty; SetProperty;
    import mx.states.State; State;
}

}

add rect to swc

add rect to swc


package aerys.minko.render.resource.texture
{
	import aerys.minko.render.resource.Context3DResource;

	import flash.display.BitmapData;
	import flash.display3D.Context3DTextureFormat;
	import flash.display3D.textures.Texture;
	import flash.display3D.textures.TextureBase;
	import flash.geom.Matrix;
	import flash.utils.ByteArray;

	/**
	 * @inheritdoc
	 * @author Jean-Marc Le Roux
	 *
	 */
	public class TextureResource implements ITextureResource
	{
		private static const MAX_SIZE			: uint		= 2048;
		private static const TMP_MATRIX			: Matrix	= new Matrix();
		private static const FORMAT_BGRA		: String	= Context3DTextureFormat.BGRA
		private static const FORMAT_COMPRESSED	: String	= Context3DTextureFormat.COMPRESSED;

		private var _texture	: Texture		= null;
		private var _mipmap		: Boolean		= false;

		private var _bitmapData	: BitmapData	= null;
		private var _atf		: ByteArray		= null;
		private var _atfFormat	: uint			= 0;

		private var _width		: Number		= 0;
		private var _height		: Number		= 0;

		private var _update		: Boolean		= false;
		private var _resize		: Boolean		= false;

		public function get width() : uint
		{
			return _width;
		}

		public function get height() : uint
		{
			return _height;
		}

		public function TextureResource(width : int = 0, height : int = 0)
		{
			if (width != 0 && height != 0)
				setSize(width, height);
		}

		public function setSize(width : uint, height : uint) : void
		{
			//http://graphics.stanford.edu/~seander/bithacks.html#DetermineIfPowerOf2
			if (!(width && !(width & (width - 1))) || !(height && !(height & (height - 1))))
				throw new Error('The size must be a power of 2.');

			_width	= width;
			_height	= height;
			_resize = true;
		}

		public function setContentFromBitmapData(bitmapData	: BitmapData,
								   				 mipmap		: Boolean,
												 downSample	: Boolean	= false) : void
		{
			var bitmapWidth		: uint 	= bitmapData.width;
			var bitmapHeight	: uint 	= bitmapData.height;
			var w				: int	= 0;
			var h				: int	= 0;

			if (downSample)
			{
				w = 1 << Math.floor(Math.log(bitmapWidth) * Math.LOG2E);
				h = 1 << Math.floor(Math.log(bitmapHeight) * Math.LOG2E);
			}
			else
			{
				w = 1 << Math.ceil(Math.log(bitmapWidth) * Math.LOG2E);
				h = 1 << Math.ceil(Math.log(bitmapHeight) * Math.LOG2E);
			}

			if (w > MAX_SIZE)
				w = MAX_SIZE;
			if (h > MAX_SIZE)
				h = MAX_SIZE;

			if (_bitmapData == null || _bitmapData.width != w || _bitmapData.height != h)
				_bitmapData	= new BitmapData(w, h, bitmapData.transparent, 0);

			if (w != bitmapWidth || h != bitmapHeight)
			{
				TMP_MATRIX.identity();
				TMP_MATRIX.scale(w / bitmapWidth, h / bitmapHeight);
				_bitmapData.draw(bitmapData, TMP_MATRIX);
			}
			else
			{
				_bitmapData.draw(bitmapData);
			}

			if (_texture
				&& (mipmap != _mipmap
					|| bitmapData.width != _width
					|| bitmapData.height != _height))
			{
				_texture.dispose();
				_texture = null;
			}

			_width = _bitmapData.width;
			_height = _bitmapData.height;

			_mipmap	= mipmap;
			_update	= true;
		}

		public function setContentFromATF(atf : ByteArray) : void
		{
			_atf			= atf;
			_bitmapData		= null;
			_update 		= true;

			atf.position 	= 6;

			_atfFormat 		= atf.readUnsignedByte() & 3;
			_width 			= 1 << atf.readUnsignedByte();
			_height 		= 1 << atf.readUnsignedByte();
			_mipmap 		= atf.readUnsignedByte() > 1;

			atf.position 	= 0;
		}

		public function getNativeTexture(context : Context3DResource) : TextureBase
		{
			if ((!_texture || _resize) && _width && _height)
			{
				_resize = false;

				if (_texture)
					_texture.dispose();

				_texture = context.createTexture(
					_width,
					_height,
					_atf && _atfFormat == 2 ? FORMAT_COMPRESSED : FORMAT_BGRA,
					_bitmapData == null && _atf == null
				);

				_update = true;
			}

			if (_update)
			{
				_update = false;

				uploadTextureWithMipMaps();
			}

			_atf = null;
			_bitmapData = null;

			if (_texture == null)
				throw new Error();

			return _texture;
		}

		private function uploadTextureWithMipMaps() : void
		{
			if (_bitmapData)
			{
				if (_mipmap)
				{
					var level 		: uint 			= 0;
					var size		: uint 			= _width > _height ? _width : _height;
					var transparent	: Boolean		= _bitmapData.transparent;
					var tmp 		: BitmapData 	= new BitmapData(size, size, transparent, 0);
					var transform 	: Matrix		= new Matrix();

					while (size >= 1)
					{
						tmp.draw(_bitmapData, transform, null, null, null, true);
						_texture.uploadFromBitmapData(tmp, level);

						transform.scale(.5, .5);
						level++;
						size >>= 1;

						if (tmp.transparent)
							tmp.fillRect(tmp.rect, 0);
					}

					tmp.dispose();
				}
				else
				{
					_texture.uploadFromBitmapData(_bitmapData, 0);
				}

				_bitmapData.dispose();
			}
			else if (_atf)
			{
				_texture.uploadCompressedTextureFromByteArray(_atf, 0, false);
			}
		}

		public function dispose() : void
		{
			if (_texture)
			{
				_texture.dispose();
				_texture = null;
			}
		}
	}
}

package aerys.minko.render.resource.texture
{
	import aerys.minko.render.resource.Context3DResource;

	import flash.display.BitmapData;
	import flash.display3D.Context3DTextureFormat;
	import flash.display3D.textures.Texture;
	import flash.display3D.textures.TextureBase;
	import flash.geom.Matrix;
	import flash.utils.ByteArray;

	/**
	 * @inheritdoc
	 * @author Jean-Marc Le Roux
	 *
	 */
	public class TextureResource implements ITextureResource
	{
		private static const MAX_SIZE					: uint		= 2048;
		private static const TMP_MATRIX					: Matrix	= new Matrix();
		private static const FORMAT_BGRA				: String	= Context3DTextureFormat.BGRA
		private static const FORMAT_COMPRESSED			: String	= Context3DTextureFormat.COMPRESSED;
		private static const FORMAT_COMPRESSED_ALPHA 	: String 	= Context3DTextureFormat.COMPRESSED_ALPHA;

		private var _texture	: Texture		= null;
		private var _mipmap		: Boolean		= false;

		private var _bitmapData	: BitmapData	= null;
		private var _atf		: ByteArray		= null;
		private var _atfFormat	: uint			= 0;

		private var _width		: Number		= 0;
		private var _height		: Number		= 0;

		private var _update		: Boolean		= false;
		private var _resize		: Boolean		= false;

		public function get width() : uint
		{
			return _width;
		}

		public function get height() : uint
		{
			return _height;
		}

		public function TextureResource(width : int = 0, height : int = 0)
		{
			if (width != 0 && height != 0)
				setSize(width, height);
		}

		public function setSize(width : uint, height : uint) : void
		{
			//http://graphics.stanford.edu/~seander/bithacks.html#DetermineIfPowerOf2
			if (!(width && !(width & (width - 1))) || !(height && !(height & (height - 1))))
				throw new Error('The size must be a power of 2.');

			_width	= width;
			_height	= height;
			_resize = true;
		}

		public function setContentFromBitmapData(bitmapData	: BitmapData,
								   				 mipmap		: Boolean,
												 downSample	: Boolean	= false) : void
		{
			var bitmapWidth		: uint 	= bitmapData.width;
			var bitmapHeight	: uint 	= bitmapData.height;
			var w				: int	= 0;
			var h				: int	= 0;

			if (downSample)
			{
				w = 1 << Math.floor(Math.log(bitmapWidth) * Math.LOG2E);
				h = 1 << Math.floor(Math.log(bitmapHeight) * Math.LOG2E);
			}
			else
			{
				w = 1 << Math.ceil(Math.log(bitmapWidth) * Math.LOG2E);
				h = 1 << Math.ceil(Math.log(bitmapHeight) * Math.LOG2E);
			}

			if (w > MAX_SIZE)
				w = MAX_SIZE;
			if (h > MAX_SIZE)
				h = MAX_SIZE;

			if (_bitmapData == null || _bitmapData.width != w || _bitmapData.height != h)
				_bitmapData	= new BitmapData(w, h, bitmapData.transparent, 0);

			if (w != bitmapWidth || h != bitmapHeight)
			{
				TMP_MATRIX.identity();
				TMP_MATRIX.scale(w / bitmapWidth, h / bitmapHeight);
				_bitmapData.draw(bitmapData, TMP_MATRIX);
			}
			else
			{
				_bitmapData.draw(bitmapData);
			}

			if (_texture
				&& (mipmap != _mipmap
					|| bitmapData.width != _width
					|| bitmapData.height != _height))
			{
				_texture.dispose();
				_texture = null;
			}

			_width = _bitmapData.width;
			_height = _bitmapData.height;

			_mipmap	= mipmap;
			_update	= true;
		}

		public function setContentFromATF(atf : ByteArray) : void
		{
			_atf			= atf;
			_bitmapData		= null;
			_update 		= true;

			atf.position 	= 6;

			var formatByte 	: uint = atf.readUnsignedByte();

			_atfFormat 		= formatByte & 7;
			_width 			= 1 << atf.readUnsignedByte();
			_height 		= 1 << atf.readUnsignedByte();
			_mipmap 		= atf.readUnsignedByte() > 1;

			atf.position 	= 0;
		}

		public function getNativeTexture(context : Context3DResource) : TextureBase
		{
			if ((!_texture || _resize) && _width && _height)
			{
				_resize = false;

				if (_texture)
					_texture.dispose();

				var format : String = FORMAT_BGRA;

				if (_atf)
				{
					if (_atfFormat == 5)
						format = FORMAT_COMPRESSED_ALPHA;
					else if (_atfFormat == 3)
						format = FORMAT_COMPRESSED;
				}

				_texture = context.createTexture(
					_width,
					_height,
					format,
					_bitmapData == null && _atf == null
				);

				_update = true;
			}

			if (_update)
			{
				_update = false;

				uploadTextureWithMipMaps();
			}

			_atf = null;
			_bitmapData = null;

			if (_texture == null)
				throw new Error();

			return _texture;
		}

		private function uploadTextureWithMipMaps() : void
		{
			if (_bitmapData)
			{
				if (_mipmap)
				{
					var level 		: uint 			= 0;
					var size		: uint 			= _width > _height ? _width : _height;
					var transparent	: Boolean		= _bitmapData.transparent;
					var tmp 		: BitmapData 	= new BitmapData(size, size, transparent, 0);
					var transform 	: Matrix		= new Matrix();

					while (size >= 1)
					{
						tmp.draw(_bitmapData, transform, null, null, null, true);
						_texture.uploadFromBitmapData(tmp, level);

						transform.scale(.5, .5);
						level++;
						size >>= 1;

						if (tmp.transparent)
							tmp.fillRect(tmp.rect, 0);
					}

					tmp.dispose();
				}
				else
				{
					_texture.uploadFromBitmapData(_bitmapData, 0);
				}

				_bitmapData.dispose();
			}
			else if (_atf)
			{
				_texture.uploadCompressedTextureFromByteArray(_atf, 0);
			}
		}

		public function dispose() : void
		{
			if (_texture)
			{
				_texture.dispose();
				_texture = null;
			}
		}
	}
}

Update textureResource to handle atf properly