//
// $Id$
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2007 Three Rings Design, Inc., All Rights Reserved
// http://www.threerings.net/code/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.client {

import flash.errors.IOError;

import flash.events.Event;
import flash.events.IOErrorEvent;

import flash.net.Socket;

import flash.utils.ByteArray;
import flash.utils.Endian;

import com.threerings.util.StringUtil;

import com.threerings.io.FrameAvailableEvent;
import com.threerings.io.FrameReader;
import com.threerings.io.ObjectInputStream;
import com.threerings.io.ObjectOutputStream;
import com.threerings.io.Translations;

import com.threerings.presents.data.AuthCodes;
import com.threerings.presents.net.AuthRequest;
import com.threerings.presents.net.AuthResponse;
import com.threerings.presents.net.AuthResponseData;
import com.threerings.presents.net.DownstreamMessage;
import com.threerings.presents.net.LogoffRequest;
import com.threerings.presents.net.UpstreamMessage;

public class Communicator
{
    public function Communicator (client :Client)
    {
        _client = client;
    }

    public function logon () :void
    {
        // create our input/output business
        _outBuffer = new ByteArray();
        _outBuffer.endian = Endian.BIG_ENDIAN;
        _outStream = new ObjectOutputStream(_outBuffer);

        _inStream = new ObjectInputStream();

        _portIdx = 0;
        logonToPort();
    }

    /**
     * This method is strangely named, and it does two things which is
     * bad style. Either log on to the next port, or save that the port
     * we just logged on to was a good one.
     */
    protected function logonToPort (logonWasSuccessful :Boolean = false) :Boolean
    {
        var ports :Array = _client.getPorts();

        if (!logonWasSuccessful) {
            if (_portIdx >= ports.length) {
                return false;
            }
            if (_portIdx != 0) {
                _client.reportLogonTribulations(
                    new LogonError(AuthCodes.TRYING_NEXT_PORT, true));

                removeListeners();
            }

            // create the socket and set up listeners
            _socket = new Socket();
            _socket.endian = Endian.BIG_ENDIAN;
            _socket.addEventListener(Event.CONNECT, socketOpened);
            _socket.addEventListener(IOErrorEvent.IO_ERROR, socketError);
            _socket.addEventListener(Event.CLOSE, socketClosed);

            _frameReader = new FrameReader(_socket);
            _frameReader.addEventListener(FrameAvailableEvent.FRAME_AVAILABLE,
                inputFrameReceived);
        }

        var host :String = _client.getHostname();
        var pportKey :String = host + ".preferred_port";
        var pport :int =
            (PresentsPrefs.config.getValue(pportKey, ports[0]) as int);
        var ppidx :int = Math.max(0, ports.indexOf(pport));
        var port :int = (ports[(_portIdx + ppidx) % ports.length] as int);

        if (logonWasSuccessful) {
            _portIdx = -1; // indicate that we're no longer trying new ports
            PresentsPrefs.config.setValue(pportKey, port);

        } else {
            Log.getLog(this).info(
                "Connecting [host=" + host + ", port=" + port + "].");
            _socket.connect(host, port);
        }

        return true;
    }

    protected function removeListeners () :void
    {
        _socket.removeEventListener(Event.CONNECT, socketOpened);
        _socket.removeEventListener(IOErrorEvent.IO_ERROR, socketError);
        _socket.removeEventListener(Event.CLOSE, socketClosed);

        _frameReader.removeEventListener(FrameAvailableEvent.FRAME_AVAILABLE,
            inputFrameReceived);
    }

    public function logoff () :void
    {
        if (_socket == null) {
            return;
        }

        sendMessage(new LogoffRequest());

        shutdown(null);
    }

    public function postMessage (msg :UpstreamMessage) :void
    {
        sendMessage(msg); // send it now: we have no out queue
    }

    protected function shutdown (logonError :Error) :void
    {
        _client.notifyObservers(ClientEvent.CLIENT_DID_LOGOFF, null);

        if (_socket != null)  {
            try {
                _socket.close();
            } catch (err :Error) {
                Log.getLog(this).warning(
                    "Error closing failed socket [error=" + err + "].");
            }
            removeListeners();
            _socket = null;
            _outStream = null;
            _inStream = null;
            _frameReader = null;
            _outBuffer = null;
        }

        _client.cleanup(logonError);
    }

    protected function sendMessage (msg :UpstreamMessage) :void
    {
        if (_outStream == null) {
            Log.getLog(this).warning(
                "No socket, dropping msg [msg=" + msg + "].");
            return;
        }

        // write the message (ends up in _outBuffer)
        _outStream.writeObject(msg);

//        Log.debug("outBuffer: " + StringUtil.unhexlate(_outBuffer));

        // Frame it by writing the length, then the bytes.
        // We add 4 to the length, because the length is of the entire frame
        // including the 4 bytes used to encode the length!
        _socket.writeInt(_outBuffer.length + 4);
        _socket.writeBytes(_outBuffer);
        _socket.flush();

        // clean up the output buffer
        _outBuffer.length = 0;
        _outBuffer.position = 0;

        // make a note of our most recent write time
        updateWriteStamp();
    }

    /**
     * Returns the time at which we last sent a packet to the server.
     */
    internal function getLastWrite () :uint
    {
        return _lastWrite;
    }

    /**
     * Makes a note of the time at which we last communicated with the server.
     */
    internal function updateWriteStamp () :void
    {
        _lastWrite = flash.utils.getTimer();
    }

    /**
     * Called when a frame of data from the server is ready to be
     * decoded into a DownstreamMessage.
     */
    protected function inputFrameReceived (event :FrameAvailableEvent) :void
    {
        // convert the frame data into a message from the server
        var frameData :ByteArray = event.getFrameData();
        //Log.debug("length of in frame: " + frameData.length);
        //Log.debug("inBuffer: " + StringUtil.unhexlate(frameData));
        _inStream.setSource(frameData);
        var msg :DownstreamMessage;
        try {
            msg = (_inStream.readObject() as DownstreamMessage);
        } catch (e :Error) {
            var log :Log = Log.getLog(this);
            log.warning("Error processing downstream message: " + e);
            log.logStackTrace(e);
            return;
        }

        if (frameData.bytesAvailable > 0) {
            Log.getLog(this).warning(
                "Beans! We didn't fully read a frame, surely there's " +
                "a bug in some streaming code. " +
                "[bytesLeftOver=" + frameData.bytesAvailable + "].");
        }

        if (_omgr != null) {
            // if we're logged on, then just do the normal thing
            _omgr.processMessage(msg);
            return;
        }

        // Otherwise, this would be the AuthResponse to our logon attempt.
        var rsp :AuthResponse = (msg as AuthResponse);
        var data :AuthResponseData = rsp.getData();
        if (data.code !== AuthResponseData.SUCCESS) {
            shutdown(new Error(data.code));
            return;
        }

        // logon success
        _omgr = new ClientDObjectMgr(this, _client);
        _client.setAuthResponseData(data);
    }

    /**
     * Called when the connection to the server was successfully opened.
     */
    protected function socketOpened (event :Event) :void
    {
        logonToPort(true);
        // well that's great! let's logon
        var req :AuthRequest = new AuthRequest(
            _client.getCredentials(), _client.getVersion(), _client.getBootGroups());
        sendMessage(req);
    }

    /**
     * Called when there is an io error with the socket.
     */
    protected function socketError (event :IOErrorEvent) :void
    {
        // if we're trying ports, try the next one.
        if (_portIdx != -1) {
            _portIdx++;
            if (logonToPort()) {
                return;
            }
        }

        // total failure
        Log.getLog(this).warning("socket error: " + event);
        Log.dumpStack();
        if (_socket.connected) {
            Log.getLog(this).info("Things seem ok. Ignoring.");

        } else {
            shutdown(new Error("socket closed unexpectedly."));
        }
    }

    /**
     * Called when the connection to the server was closed.
     */
    protected function socketClosed (event :Event) :void
    {
        Log.getLog(this).warning("socket was closed: " + event);
        _client.notifyObservers(ClientEvent.CLIENT_CONNECTION_FAILED);
        logoff();
    }

    protected var _client :Client;
    protected var _omgr :ClientDObjectMgr;

    protected var _outBuffer :ByteArray;
    protected var _outStream :ObjectOutputStream;

    protected var _inStream :ObjectInputStream;
    protected var _frameReader :FrameReader;

    protected var _socket :Socket;

    protected var _lastWrite :uint;

    /** The current port we'll try to connect to. */
    protected var _portIdx :int = -1;
}
}

//
// $Id$
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2007 Three Rings Design, Inc., All Rights Reserved
// http://www.threerings.net/code/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.client {

import flash.errors.IOError;

import flash.events.Event;
import flash.events.IOErrorEvent;

import flash.net.Socket;

import flash.utils.ByteArray;
import flash.utils.Endian;

import com.threerings.util.StringUtil;

import com.threerings.io.FrameAvailableEvent;
import com.threerings.io.FrameReader;
import com.threerings.io.ObjectInputStream;
import com.threerings.io.ObjectOutputStream;
import com.threerings.io.Translations;

import com.threerings.presents.data.AuthCodes;
import com.threerings.presents.net.AuthRequest;
import com.threerings.presents.net.AuthResponse;
import com.threerings.presents.net.AuthResponseData;
import com.threerings.presents.net.DownstreamMessage;
import com.threerings.presents.net.LogoffRequest;
import com.threerings.presents.net.UpstreamMessage;

public class Communicator
{
    public function Communicator (client :Client)
    {
        _client = client;
    }

    public function logon () :void
    {
        // create our input/output business
        _outBuffer = new ByteArray();
        _outBuffer.endian = Endian.BIG_ENDIAN;
        _outStream = new ObjectOutputStream(_outBuffer);

        _inStream = new ObjectInputStream();

        _portIdx = 0;
        logonToPort();
    }

    /**
     * This method is strangely named, and it does two things which is
     * bad style. Either log on to the next port, or save that the port
     * we just logged on to was a good one.
     */
    protected function logonToPort (logonWasSuccessful :Boolean = false) :Boolean
    {
        var ports :Array = _client.getPorts();

        if (!logonWasSuccessful) {
            if (_portIdx >= ports.length) {
                return false;
            }
            if (_portIdx != 0) {
                _client.reportLogonTribulations(
                    new LogonError(AuthCodes.TRYING_NEXT_PORT, true));

                removeListeners();
            }

            // create the socket and set up listeners
            _socket = new Socket();
            _socket.endian = Endian.BIG_ENDIAN;
            _socket.addEventListener(Event.CONNECT, socketOpened);
            _socket.addEventListener(IOErrorEvent.IO_ERROR, socketError);
            _socket.addEventListener(Event.CLOSE, socketClosed);

            _frameReader = new FrameReader(_socket);
            _frameReader.addEventListener(FrameAvailableEvent.FRAME_AVAILABLE,
                inputFrameReceived);
        }

        var host :String = _client.getHostname();
        var pportKey :String = host + ".preferred_port";
        var pport :int =
            (PresentsPrefs.config.getValue(pportKey, ports[0]) as int);
        var ppidx :int = Math.max(0, ports.indexOf(pport));
        var port :int = (ports[(_portIdx + ppidx) % ports.length] as int);

        if (logonWasSuccessful) {
            _portIdx = -1; // indicate that we're no longer trying new ports
            PresentsPrefs.config.setValue(pportKey, port);

        } else {
            Log.getLog(this).info(
                "Connecting [host=" + host + ", port=" + port + "].");
            _socket.connect(host, port);
        }

        return true;
    }

    protected function removeListeners () :void
    {
        _socket.removeEventListener(Event.CONNECT, socketOpened);
        _socket.removeEventListener(IOErrorEvent.IO_ERROR, socketError);
        _socket.removeEventListener(Event.CLOSE, socketClosed);

        _frameReader.removeEventListener(FrameAvailableEvent.FRAME_AVAILABLE,
            inputFrameReceived);
    }

    public function logoff () :void
    {
        if (_socket == null) {
            return;
        }

        sendMessage(new LogoffRequest());

        shutdown(null);
    }

    public function postMessage (msg :UpstreamMessage) :void
    {
        sendMessage(msg); // send it now: we have no out queue
    }

    protected function shutdown (logonError :Error) :void
    {
        _client.notifyObservers(ClientEvent.CLIENT_DID_LOGOFF, null);

        if (_socket != null)  {
            try {
                _socket.close();
            } catch (err :Error) {
                Log.getLog(this).warning(
                    "Error closing failed socket [error=" + err + "].");
            }
            removeListeners();
            _socket = null;
            _outStream = null;
            _inStream = null;
            _frameReader = null;
            _outBuffer = null;
        }

        _client.cleanup(logonError);
    }

    protected function sendMessage (msg :UpstreamMessage) :void
    {
        if (_outStream == null) {
            Log.getLog(this).warning(
                "No socket, dropping msg [msg=" + msg + "].");
            return;
        }

        // write the message (ends up in _outBuffer)
        _outStream.writeObject(msg);

//        Log.debug("outBuffer: " + StringUtil.unhexlate(_outBuffer));

        // Frame it by writing the length, then the bytes.
        // We add 4 to the length, because the length is of the entire frame
        // including the 4 bytes used to encode the length!
        _socket.writeInt(_outBuffer.length + 4);
        _socket.writeBytes(_outBuffer);
        _socket.flush();

        // clean up the output buffer
        _outBuffer.length = 0;
        _outBuffer.position = 0;

        // make a note of our most recent write time
        updateWriteStamp();
    }

    /**
     * Returns the time at which we last sent a packet to the server.
     */
    internal function getLastWrite () :uint
    {
        return _lastWrite;
    }

    /**
     * Makes a note of the time at which we last communicated with the server.
     */
    internal function updateWriteStamp () :void
    {
        _lastWrite = flash.utils.getTimer();
    }

    /**
     * Called when a frame of data from the server is ready to be
     * decoded into a DownstreamMessage.
     */
    protected function inputFrameReceived (event :FrameAvailableEvent) :void
    {
        // convert the frame data into a message from the server
        var frameData :ByteArray = event.getFrameData();
        //Log.debug("length of in frame: " + frameData.length);
        //Log.debug("inBuffer: " + StringUtil.unhexlate(frameData));
        _inStream.setSource(frameData);
        var msg :DownstreamMessage;
        try {
            msg = (_inStream.readObject() as DownstreamMessage);
        } catch (e :Error) {
            var log :Log = Log.getLog(this);
            log.warning("Error processing downstream message: " + e);
            log.logStackTrace(e);
            return;
        }

        if (frameData.bytesAvailable > 0) {
            Log.getLog(this).warning(
                "Beans! We didn't fully read a frame, surely there's " +
                "a bug in some streaming code. " +
                "[bytesLeftOver=" + frameData.bytesAvailable + "].");
        }

        if (_omgr != null) {
            // if we're logged on, then just do the normal thing
            _omgr.processMessage(msg);
            return;
        }

        // Otherwise, this would be the AuthResponse to our logon attempt.
        var rsp :AuthResponse = (msg as AuthResponse);
        var data :AuthResponseData = rsp.getData();
        if (data.code !== AuthResponseData.SUCCESS) {
            shutdown(new Error(data.code));
            return;
        }

        // logon success
        _omgr = new ClientDObjectMgr(this, _client);
        _client.setAuthResponseData(data);
    }

    /**
     * Called when the connection to the server was successfully opened.
     */
    protected function socketOpened (event :Event) :void
    {
        logonToPort(true);
        // well that's great! let's logon
        var req :AuthRequest = new AuthRequest(
            _client.getCredentials(), _client.getVersion(), _client.getBootGroups());
        sendMessage(req);
    }

    /**
     * Called when there is an io error with the socket.
     */
    protected function socketError (event :IOErrorEvent) :void
    {
        // if we're trying ports, try the next one.
        if (_portIdx != -1) {
            _portIdx++;
            if (logonToPort()) {
                return;
            }
        }

        // total failure
        Log.getLog(this).warning("socket error: " + event + ", target=" + event.target);
        Log.dumpStack();
        shutdown(new Error("socket closed unexpectedly."));
    }

    /**
     * Called when the connection to the server was closed.
     */
    protected function socketClosed (event :Event) :void
    {
        Log.getLog(this).warning("socket was closed: " + event);
        _client.notifyObservers(ClientEvent.CLIENT_CONNECTION_FAILED);
        logoff();
    }

    protected var _client :Client;
    protected var _omgr :ClientDObjectMgr;

    protected var _outBuffer :ByteArray;
    protected var _outStream :ObjectOutputStream;

    protected var _inStream :ObjectInputStream;
    protected var _frameReader :FrameReader;

    protected var _socket :Socket;

    protected var _lastWrite :uint;

    /** The current port we'll try to connect to. */
    protected var _portIdx :int = -1;
}
}

Stop trying to recover from this error (it doesn't work), but try logging
the event target.

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


////////////////////////////////////////////////////////////////////////////////
//
//  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.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.ChartDataGroup; ChartDataGroup;
	import org.apache.flex.charts.supportClasses.BoxItemRenderer; BoxItemRenderer;
	import org.apache.flex.charts.supportClasses.LineSegmentItemRenderer; LineSegmentItemRenderer;
	import org.apache.flex.charts.supportClasses.WedgeItemRenderer; WedgeItemRenderer;
	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.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.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.TitleBarMeasurementBead; TitleBarMeasurementBead;
	import org.apache.flex.html.beads.TitleBarView; TitleBarView;
    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.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.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.SolidColor; SolidColor;
	import org.apache.flex.core.graphics.SolidColorStroke; SolidColorStroke;

	import mx.core.ClassFactory; ClassFactory;
    import mx.states.AddItems; AddItems;
    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.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.ChartDataGroup; ChartDataGroup;
	import org.apache.flex.charts.supportClasses.BoxItemRenderer; BoxItemRenderer;
	import org.apache.flex.charts.supportClasses.LineSegmentItemRenderer; LineSegmentItemRenderer;
	import org.apache.flex.charts.supportClasses.WedgeItemRenderer; WedgeItemRenderer;
	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.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.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.TitleBarMeasurementBead; TitleBarMeasurementBead;
	import org.apache.flex.html.beads.TitleBarView; TitleBarView;
    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.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.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.SolidColor; SolidColor;
	import org.apache.flex.core.graphics.SolidColorStroke; SolidColorStroke;

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

}

Include Ellipse in FlexJSUIClasses.as

Include Ellipse in FlexJSUIClasses.as


/*
 * Copyright (c) 2014 castLabs GmbH
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

package com.castlabs.dash {
import com.castlabs.dash.events.FragmentEvent;
import com.castlabs.dash.events.ManifestEvent;
import com.castlabs.dash.events.SegmentEvent;
import com.castlabs.dash.events.StreamEvent;
import com.castlabs.dash.handlers.ManifestHandler;
import com.castlabs.dash.loaders.FragmentLoader;
import com.castlabs.dash.loaders.ManifestLoader;

import flash.events.NetStatusEvent;
import flash.events.TimerEvent;
import flash.net.NetConnection;
import flash.net.NetStream;
import flash.net.NetStreamAppendBytesAction;
import flash.utils.ByteArray;
import flash.utils.Timer;

import com.castlabs.dash.utils.NetStreamCodes;

public class DashNetStream extends NetStream {
    private const MIN_BUFFER_TIME:Number = 5;
    private const MAX_BUFFER_TIME:Number = 30;

    // actions
    private const PLAY:uint = 1;
    private const PAUSE:uint = 2;
    private const RESUME:uint = 3;
    private const STOP:uint = 4;
    private const SEEK:uint = 5;
    private const BUFFER:uint = 6;

    // states
    private const INITIALIZING:uint = 0;
    private const PLAYING:uint = 1;
    private const BUFFERING:uint = 2;
    private const SEEKING:uint = 3;
    private const PAUSED:uint = 4;
    private const STOPPED:uint = 5;

    protected var _context:DashContext;

    private var _state:uint = INITIALIZING;

    private var _loader:FragmentLoader;

    private var _loaded:Boolean = false;

    private var _offset:Number = 0;
    private var _loadedTimestamp:Number = 0;
    private var _duration:Number = 0;
    private var _live:Boolean;

    private var _bufferTimer:Timer;
    private var _fragmentTimer:Timer;

    public function DashNetStream(context:DashContext, connection:NetConnection) {
        super(connection);

        _context = context;

        addEventListener(NetStatusEvent.NET_STATUS, onNetStatus);

        _bufferTimer = new Timer(250); // 250 ms
        _bufferTimer.addEventListener(TimerEvent.TIMER, onBufferTimer);

        _fragmentTimer = new Timer(250); // 250 ms
        _fragmentTimer.addEventListener(TimerEvent.TIMER, onFragmentTimer);

        inBufferSeek = false;
        bufferTime = 0;
        bufferTimeMax = 0;
        maxPauseBufferTime = 0;
        useHardwareDecoder = true;
    }

    override public function play(...rest):void {
		if (typeof(rest[0]) == 'string' && rest[0] != '')
		{
			loadManifest(rest[0]);
			updateState(PLAY);
			return;
		}

        super.play(null);

        appendBytesAction(NetStreamAppendBytesAction.RESET_BEGIN);
        appendFileHeader();

        notifyPlayStart();

        _bufferTimer.start();

        jump();

        updateState(PLAY);
    }

    private function onBufferTimer(timerEvent:TimerEvent):void {
        var bufferTime:Number = _loadedTimestamp - time;

        switch(_state) {
            case PLAYING:
                if (!_loaded && bufferTime < MIN_BUFFER_TIME) {
                    pause();
                    notifyBufferEmpty();
                    updateState(BUFFER);
                    return;
                }
                break;
            case BUFFERING:
                if (bufferTime > MIN_BUFFER_TIME) {
                    resume();
                    notifyBufferFull();
                    return;
                }
                break;
        }
    }

    override public function pause():void {
        super.pause();
        updateState(PAUSE);
    }

    override public function resume():void {
        switch (_state) {
            case PAUSED:
            case BUFFERING:
                super.resume();
                break;
            case STOPPED:
                play();
                break;
            case SEEKING:
                jump();
                break;
        }

        updateState(RESUME);
    }

    override public function seek(offset:Number):void {
        switch (_state) {
            case PAUSED:
            case SEEKING:
            case STOPPED:
                _fragmentTimer.stop();
                _loader.close();
                _offset = offset;
                super.seek(_offset);
                break;
            case PLAYING:
            case BUFFERING:
                _fragmentTimer.stop();
                _loader.close();
                _offset = offset;
                super.seek(_offset);
                jump();
                break;
        }

        updateState(SEEK);
    }

    override public function get time():Number {
        return super.time + _offset;
    }

    override public function close():void {
        super.close();

        appendBytesAction(NetStreamAppendBytesAction.END_SEQUENCE);
        appendBytesAction(NetStreamAppendBytesAction.RESET_SEEK);

        _bufferTimer.stop();

        notifyPlayStop();

        reset();

        updateState(STOP);
    }

    override public function get bytesLoaded():uint {
        if (_live) {
            return 1;
        } else {
            if (_loadedTimestamp == 0) {

                //WORKAROUND ScrubBar:531 ignores zero value
                return 1;
            }

            // seconds
            return _loadedTimestamp;
        }
    }

    override public function get bytesTotal():uint {
        if (_live) {
            return 1;
        } else {
            if (_loadedTimestamp == 0) {

                //WORKAROUND ScrubBar:531 ignore zero value; generate smallest possible fraction
                return uint.MAX_VALUE;
            }

            // seconds
            return _duration;
        }
    }

	public function loadManifest(url:String):void
	{
		var thisStream:DashNetStream = this;
        var loader:ManifestLoader = _context.buildManifestLoader(url);

        loader.addEventListener(ManifestEvent.LOADED, onLoad);
        loader.addEventListener(ManifestEvent.ERROR, onError);

        function onLoad(event:ManifestEvent):void {
            _context.console.info("Creating manifest...");

            var manifest:ManifestHandler = _context.createManifestHandler(event.url, event.xml);
            _context.console.info("Created manifest, " + manifest.toString());

            thisStream.init();
        }

        function onError(event:ManifestEvent):void {
            /*loadTrait.dispatchEvent(new MediaErrorEvent(MediaErrorEvent.MEDIA_ERROR, false, false,
                    new MediaError(MediaErrorCodes.MEDIA_LOAD_FAILED)));*/
        }

        loader.load();
    }

    public function init():void {
        _live = _context.manifestHandler.live;
        _duration = _context.manifestHandler.duration;

		if (client && client.hasOwnProperty('onMetaData'))
		{
			client.onMetaData({
				canSeekToEnd : !_live,
				videocodecid : 0,
				framerate : 24,
				videodatarate : 0,
				height : 0,
				width : 0,
				duration : _duration,
				dash: true
			});
		}

        _loader = _context.fragmentLoader;
        _loader.addEventListener(StreamEvent.READY, onReady);
        _loader.addEventListener(FragmentEvent.LOADED, onLoaded);
        _loader.addEventListener(StreamEvent.END, onEnd);
        _loader.addEventListener(SegmentEvent.ERROR, onError);
        _loader.init();
    }

    protected function appendFileHeader():void {
        var output:ByteArray = new ByteArray();
        output.writeByte(0x46);	// 'F'
        output.writeByte(0x4c); // 'L'
        output.writeByte(0x56); // 'V'
        output.writeByte(0x01); // version 0x01

        var flags:uint = 0;

        flags |= 0x01;

        output.writeByte(flags);

        var offsetToWrite:uint = 9; // minimum file header byte count

        output.writeUnsignedInt(offsetToWrite);

        var previousTagSize0:uint = 0;

        output.writeUnsignedInt(previousTagSize0);

        appendBytes(output);
    }

    private function updateState(action:Number):void {
        switch (action) {
            case PLAY:
                _context.console.debug("Received PLAY action and changed to PLAYING state");
                _state = PLAYING;
                break;
            case PAUSE:
                _context.console.debug("Received PAUSE action and changed to PAUSED state");
                _state = PAUSED;
                break;
            case RESUME:
                _context.console.debug("Received RESUME action and changed to PLAYING state");
                _state = PLAYING;
                break;
            case STOP:
                _context.console.debug("Received STOP action and changed to STOPPED state");
                _state = STOPPED;
                break;
            case SEEK:
                switch (_state) {
                    case PAUSED:
                        _context.console.debug("Received SEEK action and changed to SEEKING state");
                        _state = SEEKING;
                        break;
                    case PLAYING:
                    case BUFFERING:
                        _context.console.debug("Received SEEK action and changed to PLAYING state");
                        _state = PLAYING;
                        break;
                }
                break;
            case BUFFER:
                _context.console.debug("Received BUFFER action and changed to BUFFERING state");
                _state = BUFFERING;
                break;
        }
    }

    private function jump():void {
        _offset = _loader.seek(_offset);
        _loadedTimestamp = 0;

        super.seek(_offset);

        appendBytesAction(NetStreamAppendBytesAction.RESET_SEEK);

        _loader.loadFirstFragment();
    }

    private function notifyPlayStart():void {
        dispatchEvent(new NetStatusEvent(NetStatusEvent.NET_STATUS, false, false,
                { code: NetStreamCodes.NETSTREAM_PLAY_START, level: "status" }));
    }

    private function notifyPlayStop():void {
        dispatchEvent(new NetStatusEvent(NetStatusEvent.NET_STATUS, false, false,
                { code: NetStreamCodes.NETSTREAM_PLAY_STOP, level: "status" }));
    }

    private function notifyPlayUnpublish():void {
        dispatchEvent(new NetStatusEvent(NetStatusEvent.NET_STATUS, false, false,
                { code: NetStreamCodes.NETSTREAM_PLAY_UNPUBLISH_NOTIFY, level: "status" }));
    }

    private function notifyBufferFull():void {
        dispatchEvent(new NetStatusEvent(NetStatusEvent.NET_STATUS, false, false,
                { code: NetStreamCodes.NETSTREAM_BUFFER_FULL, level: "status" }));
    }

    private function notifyBufferEmpty():void {
        dispatchEvent(new NetStatusEvent(NetStatusEvent.NET_STATUS, false, false,
                { code: NetStreamCodes.NETSTREAM_BUFFER_EMPTY, level: "status" }));
    }

    private function reset():void {
        _offset = 0;
        _loadedTimestamp = 0;
        _loaded = false;
    }

    private function onReady(event:StreamEvent):void {
		if (_state == PLAYING)
		{
			play();
		} else
		{
			_state = STOPPED;
		}

		dispatchEvent(event);
    }

    private function onLoaded(event:FragmentEvent):void {
        _loadedTimestamp = event.endTimestamp;
        appendBytes(event.bytes);
        onFragmentTimer();
    }

    private function onError(event:SegmentEvent):void {
        if (_state == INITIALIZING) {
            dispatchEvent(_context.buildStreamEvent(StreamEvent.ERROR));
        } else {
            dispatchEvent(new NetStatusEvent(NetStatusEvent.NET_STATUS, false, false,
                    { code: NetStreamCodes.NETSTREAM_FAILED, level: "status" }));
        }
    }

    private function onFragmentTimer(timerEvent:TimerEvent = null):void {
        _fragmentTimer.stop();

        if ((_loadedTimestamp - time) < MAX_BUFFER_TIME) {
            _loader.loadNextFragment();
        } else {
            _fragmentTimer.start();
        }
    }

    private function onNetStatus(event:NetStatusEvent):void {
        switch(event.info.code) {
            case NetStreamCodes.NETSTREAM_BUFFER_EMPTY:
                if  (_loaded) {
                    close();
                    notifyPlayUnpublish();
                }
                break;
            case NetStreamCodes.NETSTREAM_PLAY_STREAMNOTFOUND:
                close();
                break;
        }
    }

    private function onEnd(event:StreamEvent):void {
        _loaded = true;
        _loadedTimestamp = _duration;
    }
}
}

/*
 * Copyright (c) 2014 castLabs GmbH
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

package com.castlabs.dash {
import com.castlabs.dash.events.FragmentEvent;
import com.castlabs.dash.events.ManifestEvent;
import com.castlabs.dash.events.SegmentEvent;
import com.castlabs.dash.events.StreamEvent;
import com.castlabs.dash.handlers.ManifestHandler;
import com.castlabs.dash.loaders.FragmentLoader;
import com.castlabs.dash.loaders.ManifestLoader;

import flash.events.NetStatusEvent;
import flash.events.TimerEvent;
import flash.net.NetConnection;
import flash.net.NetStream;
import flash.net.NetStreamAppendBytesAction;
import flash.utils.ByteArray;
import flash.utils.Timer;

import com.castlabs.dash.utils.NetStreamCodes;

public class DashNetStream extends NetStream {
    private const MIN_BUFFER_TIME:Number = 5;
    private const MAX_BUFFER_TIME:Number = 30;

    // actions
    private const PLAY:uint = 1;
    private const PAUSE:uint = 2;
    private const RESUME:uint = 3;
    private const STOP:uint = 4;
    private const SEEK:uint = 5;
    private const BUFFER:uint = 6;

    // states
    private const INITIALIZING:uint = 0;
    private const PLAYING:uint = 1;
    private const BUFFERING:uint = 2;
    private const SEEKING:uint = 3;
    private const PAUSED:uint = 4;
    private const STOPPED:uint = 5;

    protected var _context:DashContext;

    private var _state:uint = INITIALIZING;

    private var _loader:FragmentLoader;

    private var _loaded:Boolean = false;

    private var _offset:Number = 0;
    private var _loadedTimestamp:Number = 0;
    private var _duration:Number = 0;
    private var _live:Boolean;

    private var _bufferTimer:Timer;
    private var _fragmentTimer:Timer;

    public function DashNetStream(context:DashContext, connection:NetConnection) {
        super(connection);

        _context = context;

        addEventListener(NetStatusEvent.NET_STATUS, onNetStatus);

        _bufferTimer = new Timer(250); // 250 ms
        _bufferTimer.addEventListener(TimerEvent.TIMER, onBufferTimer);

        _fragmentTimer = new Timer(250); // 250 ms
        _fragmentTimer.addEventListener(TimerEvent.TIMER, onFragmentTimer);

        inBufferSeek = false;
        bufferTime = 0;
        bufferTimeMax = 0;
        maxPauseBufferTime = 0;
        useHardwareDecoder = true;
    }

    override public function play(...rest):void {
		if (typeof(rest[0]) == 'string' && rest[0] != '')
		{
			loadManifest(rest[0]);
			updateState(PLAY);
			return;
		}

        super.play(null);

        appendBytesAction(NetStreamAppendBytesAction.RESET_BEGIN);
        appendFileHeader();

        notifyPlayStart();

        _bufferTimer.start();

        jump();

        updateState(PLAY);
    }

    private function onBufferTimer(timerEvent:TimerEvent):void {
        var bufferTime:Number = _loadedTimestamp - time;

        switch(_state) {
            case PLAYING:
                if (!_loaded && bufferTime < MIN_BUFFER_TIME) {
                    pause();
                    notifyBufferEmpty();
                    updateState(BUFFER);
                    return;
                }
                break;
            case BUFFERING:
                if (bufferTime > MIN_BUFFER_TIME) {
                    resume();
                    notifyBufferFull();
                    return;
                }
                break;
        }
    }

	override public function togglePause(): void {
		if (time >= _duration)
			return;

		if (_state == PLAYING)
			pause();
		else
			resume();
	}

    override public function pause():void {
        super.pause();
        updateState(PAUSE);
    }

    override public function resume():void {
        switch (_state) {
            case PAUSED:
            case BUFFERING:
                super.resume();
                break;
            case STOPPED:
                play();
                break;
            case SEEKING:
                jump();
                break;
        }

        updateState(RESUME);
    }

    override public function seek(offset:Number):void {
		if (offset >= MIN_BUFFER_TIME)
			offset = offset - MIN_BUFFER_TIME - 1;

        switch (_state) {
            case PAUSED:
            case SEEKING:
            case STOPPED:
                _fragmentTimer.stop();
                _loader.close();
                _offset = offset;
                super.seek(_offset);
                break;
            case PLAYING:
            case BUFFERING:
                _fragmentTimer.stop();
                _loader.close();
                _offset = offset;
                super.seek(_offset);
                jump();
                break;
        }

        updateState(SEEK);
    }

    override public function get time():Number {
        return super.time + _offset;
    }

    override public function close():void {
        super.close();

        appendBytesAction(NetStreamAppendBytesAction.END_SEQUENCE);
        appendBytesAction(NetStreamAppendBytesAction.RESET_SEEK);

        _bufferTimer.stop();

        notifyPlayStop();

        reset();

        updateState(STOP);
    }

    override public function get bytesLoaded():uint {
        if (_live) {
            return 1;
        } else {
            if (_loadedTimestamp == 0) {

                //WORKAROUND ScrubBar:531 ignores zero value
                return 1;
            }

            // seconds
            return _loadedTimestamp;
        }
    }

    override public function get bytesTotal():uint {
        if (_live) {
            return 1;
        } else {
            if (_loadedTimestamp == 0) {

                //WORKAROUND ScrubBar:531 ignore zero value; generate smallest possible fraction
                return uint.MAX_VALUE;
            }

            // seconds
            return _duration;
        }
    }

	public function loadManifest(url:String):void
	{
		var thisStream:DashNetStream = this;
        var loader:ManifestLoader = _context.buildManifestLoader(url);

        loader.addEventListener(ManifestEvent.LOADED, onLoad);
        loader.addEventListener(ManifestEvent.ERROR, onError);

        function onLoad(event:ManifestEvent):void {
            _context.console.info("Creating manifest...");

            var manifest:ManifestHandler = _context.createManifestHandler(event.url, event.xml);
            _context.console.info("Created manifest, " + manifest.toString());

            thisStream.init();
        }

        function onError(event:ManifestEvent):void {
            /*loadTrait.dispatchEvent(new MediaErrorEvent(MediaErrorEvent.MEDIA_ERROR, false, false,
                    new MediaError(MediaErrorCodes.MEDIA_LOAD_FAILED)));*/
        }

        loader.load();
    }

    public function init():void {
        _live = _context.manifestHandler.live;
        _duration = _context.manifestHandler.duration;

		if (client && client.hasOwnProperty('onMetaData'))
		{
			client.onMetaData({
				canSeekToEnd : !_live,
				videocodecid : 0,
				framerate : 24,
				videodatarate : 0,
				height : 0,
				width : 0,
				duration : _duration,
				dash: true
			});
		}

        _loader = _context.fragmentLoader;
        _loader.addEventListener(StreamEvent.READY, onReady);
        _loader.addEventListener(FragmentEvent.LOADED, onLoaded);
        _loader.addEventListener(StreamEvent.END, onEnd);
        _loader.addEventListener(SegmentEvent.ERROR, onError);
        _loader.init();
    }

    protected function appendFileHeader():void {
        var output:ByteArray = new ByteArray();
        output.writeByte(0x46);	// 'F'
        output.writeByte(0x4c); // 'L'
        output.writeByte(0x56); // 'V'
        output.writeByte(0x01); // version 0x01

        var flags:uint = 0;

        flags |= 0x01;

        output.writeByte(flags);

        var offsetToWrite:uint = 9; // minimum file header byte count

        output.writeUnsignedInt(offsetToWrite);

        var previousTagSize0:uint = 0;

        output.writeUnsignedInt(previousTagSize0);

        appendBytes(output);
    }

    private function updateState(action:Number):void {
        switch (action) {
            case PLAY:
                _context.console.debug("Received PLAY action and changed to PLAYING state");
                _state = PLAYING;
                break;
            case PAUSE:
                _context.console.debug("Received PAUSE action and changed to PAUSED state");
                _state = PAUSED;
                break;
            case RESUME:
                _context.console.debug("Received RESUME action and changed to PLAYING state");
                _state = PLAYING;
                break;
            case STOP:
                _context.console.debug("Received STOP action and changed to STOPPED state");
                _state = STOPPED;
                break;
            case SEEK:
                switch (_state) {
                    case PAUSED:
                        _context.console.debug("Received SEEK action and changed to SEEKING state");
                        _state = SEEKING;
                        break;
                    case PLAYING:
                    case BUFFERING:
                        _context.console.debug("Received SEEK action and changed to PLAYING state");
                        _state = PLAYING;
                        break;
                }
                break;
            case BUFFER:
                _context.console.debug("Received BUFFER action and changed to BUFFERING state");
                _state = BUFFERING;
                break;
        }
    }

    private function jump():void {
        _offset = _loader.seek(_offset);
        _loadedTimestamp = 0;

        super.seek(_offset);

        appendBytesAction(NetStreamAppendBytesAction.RESET_SEEK);

        _loader.loadFirstFragment();
    }

    private function notifyPlayStart():void {
        dispatchEvent(new NetStatusEvent(NetStatusEvent.NET_STATUS, false, false,
                { code: NetStreamCodes.NETSTREAM_PLAY_START, level: "status" }));
    }

    private function notifyPlayStop():void {
        dispatchEvent(new NetStatusEvent(NetStatusEvent.NET_STATUS, false, false,
                { code: NetStreamCodes.NETSTREAM_PLAY_STOP, level: "status" }));
    }

    private function notifyPlayUnpublish():void {
        dispatchEvent(new NetStatusEvent(NetStatusEvent.NET_STATUS, false, false,
                { code: NetStreamCodes.NETSTREAM_PLAY_UNPUBLISH_NOTIFY, level: "status" }));
    }

    private function notifyBufferFull():void {
        dispatchEvent(new NetStatusEvent(NetStatusEvent.NET_STATUS, false, false,
                { code: NetStreamCodes.NETSTREAM_BUFFER_FULL, level: "status" }));
    }

    private function notifyBufferEmpty():void {
        dispatchEvent(new NetStatusEvent(NetStatusEvent.NET_STATUS, false, false,
                { code: NetStreamCodes.NETSTREAM_BUFFER_EMPTY, level: "status" }));
    }

    private function reset():void {
        _offset = 0;
        _loadedTimestamp = 0;
        _loaded = false;
    }

    private function onReady(event:StreamEvent):void {
		if (_state == PLAYING)
		{
			play();
		} else
		{
			_state = STOPPED;
		}

		dispatchEvent(event);
    }

    private function onLoaded(event:FragmentEvent):void {
        _loadedTimestamp = event.endTimestamp;
        appendBytes(event.bytes);
        onFragmentTimer();
    }

    private function onError(event:SegmentEvent):void {
        if (_state == INITIALIZING) {
            dispatchEvent(_context.buildStreamEvent(StreamEvent.ERROR));
        } else {
            dispatchEvent(new NetStatusEvent(NetStatusEvent.NET_STATUS, false, false,
                    { code: NetStreamCodes.NETSTREAM_FAILED, level: "status" }));
        }
    }

    private function onFragmentTimer(timerEvent:TimerEvent = null):void {
        _fragmentTimer.stop();

        if ((_loadedTimestamp - time) < MAX_BUFFER_TIME) {
            _loader.loadNextFragment();
        } else {
            _fragmentTimer.start();
        }
    }

    private function onNetStatus(event:NetStatusEvent):void {
        switch(event.info.code) {
            case NetStreamCodes.NETSTREAM_BUFFER_EMPTY:
                if  (_loaded) {
                    close();
                    notifyPlayUnpublish();
                }
                break;
            case NetStreamCodes.NETSTREAM_PLAY_STREAMNOTFOUND:
                close();
                break;
        }
    }

    private function onEnd(event:StreamEvent):void {
        _loaded = true;
        _loadedTimestamp = _duration;
    }
}
}

Add togglePause function and temporary fix function seek on end range


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

    /**
     *  The ContainerView class is the default view for
     *  the org.apache.flex.core.ContainerBase classes.
     *  It lets you use some CSS styles to manage the border, background
     *  and padding around the content area.
     *
     *  @langversion 3.0
     *  @playerversion Flash 10.2
     *  @playerversion AIR 2.6
     *  @productversion FlexJS 0.0
     */
	public class ContainerView extends BeadViewBase implements IBeadView, ILayoutParent
	{
        /**
         *  Constructor.
         *
         *  @langversion 3.0
         *  @playerversion Flash 10.2
         *  @playerversion AIR 2.6
         *  @productversion FlexJS 0.0
         */
		public function ContainerView()
		{
		}

        /**
         *  The actual parent that parents the children.
         *
         *  @langversion 3.0
         *  @playerversion Flash 10.2
         *  @playerversion AIR 2.6
         *  @productversion FlexJS 0.0
         */
		protected var actualParent:UIBase;

        /**
         *  The layout.  The layout may actually layout
         *  the children of the internal content area
         *  and not the pieces of the "chrome" like titlebars
         *  and borders.  The ContainerView or its subclass will have some
         *  baked-in logic for handling the chrome.
         *
         *  @langversion 3.0
         *  @playerversion Flash 10.2
         *  @playerversion AIR 2.6
         *  @productversion FlexJS 0.0
         */
        protected var layout:IBeadLayout;

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

            var host:UIBase = value as UIBase;

            if (host.isWidthSizedToContent() && host.isHeightSizedToContent())
            {
                // if both dimensions are sized to content, then only draw the
                // borders, etc, after a child is added.  The children in an MXML
                // document don't send this event until the last child is added.
                host.addEventListener("childrenAdded", changeHandler);
                host.addEventListener("layoutNeeded", changeHandler);
                // listen for width and height changes as well in case the app
                // switches away from content sizing via binding or other code
                host.addEventListener("widthChanged", changeHandler);
                host.addEventListener("heightChanged", changeHandler);
            }
            else
            {
                // otherwise, listen for size changes before drawing
                // borders and laying out children.
                host.addEventListener("widthChanged", changeHandler);
                host.addEventListener("heightChanged", changeHandler);
                host.addEventListener("sizeChanged", sizeChangeHandler);
                // if we have fixed size in both dimensions, wait for children
                // to be added then run a layout pass right then as the
                // parent won't kick off any other event in the child
                if (!isNaN(host.explicitWidth) && !isNaN(host.explicitHeight))
                    host.addEventListener("childrenAdded", changeHandler);
            }
            checkActualParent();
        }

        private function checkActualParent():Boolean
        {
            var host:UIBase = UIBase(_strand);
            if (contentAreaNeeded())
            {
                if (actualParent == null || actualParent == host)
                {
                    actualParent = new ContainerContentArea();
					actualParent.className = "ActualParent";
                    host.addElement(actualParent, false);
                    ContainerBase(host).setActualParent(actualParent);
                }
                return true;
            }
            else
            {
                actualParent = host;
            }
            return false;
        }

        private function sizeChangeHandler(event:Event):void
        {
            var host:UIBase = UIBase(_strand);
            host.addEventListener("childrenAdded", changeHandler);
            host.addEventListener("layoutNeeded", changeHandler);
            host.addEventListener("itemsCreated", changeHandler);
            changeHandler(event);
        }

        private var inChangeHandler:Boolean;

        /**
         *  React if the size changed or content changed
         *
         *  @langversion 3.0
         *  @playerversion Flash 10.2
         *  @playerversion AIR 2.6
         *  @productversion FlexJS 0.0
         */
        protected function changeHandler(event:Event):void
        {
            if (inChangeHandler) return;

            inChangeHandler = true;

            var host:UIBase = UIBase(_strand);

            if (layout == null)
            {
                layout = _strand.getBeadByType(IBeadLayout) as IBeadLayout;
                if (layout == null)
                {
                    var c:Class = ValuesManager.valuesImpl.getValue(host, "iBeadLayout");
                    if (c)
                    {
                        layout = new c() as IBeadLayout;
                        _strand.addBead(layout);
                    }
                }
            }

			var padding:Object = determinePadding();

			if (checkActualParent())
			{
				actualParent.x = padding.paddingLeft;
				actualParent.y = padding.paddingTop;
            }
            var pb:Number = padding.paddingBottom;
            if (isNaN(pb))
                pb = 0;
            var pr:Number = padding.paddingRight;
            if (isNaN(pr))
                pr = 0;
            // if the width is dictated by the parent
            if (!host.isWidthSizedToContent())
            {
                if (actualParent != host)
                {
                    // force the width of the internal content area as desired.
                    actualParent.setWidth(host.width - padding.paddingLeft - pr);
                }
                // run the layout
                layout.layout();
            }
            else
            {
                // if the height is dictated by the parent
                if (!host.isHeightSizedToContent())
                {
                    if (actualParent != host)
                    {
                        // force the height
                        actualParent.setHeight(host.height - padding.paddingTop - pb);
                    }
                }
                layout.layout();
                if (actualParent != host)
                {
                    // actualParent.width should be the new width after layout.
                    // set the host's width.  This should send a widthChanged event and
                    // have it blocked at the beginning of this method
                    host.setWidth(padding.paddingLeft + pr + actualParent.width);
                }
            }
            // and if the height is sized to content, set the height now as well.
            if (host != actualParent)
            {
                if (host.isHeightSizedToContent())
                    host.setHeight(padding.paddingTop + pb + actualParent.height);
                else
                    actualParent.setHeight(host.height - padding.paddingTop - pb);
            }

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

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

            inChangeHandler = false;
		}

		/**
		 *  Determines the top and left padding values, if any, as set by
		 *  padding style values. This includes "padding" for all padding values
		 *  as well as "padding-left" and "padding-top".
		 *
		 *  Returns an object with paddingLeft and paddingTop properties.
		 *
		 *  @langversion 3.0
		 *  @playerversion Flash 10.2
		 *  @playerversion AIR 2.6
		 *  @productversion FlexJS 0.0
		 */
		protected function determinePadding():Object
		{
			var paddingLeft:Object;
			var paddingTop:Object;
			var paddingRight:Object;
			var paddingBottom:Object;
			var padding:Object = ValuesManager.valuesImpl.getValue(_strand, "padding");
			if (padding is Array)
			{
				if (padding.length == 1)
					paddingLeft = paddingTop = padding[0];
				else if (padding.length <= 3)
				{
					paddingLeft = padding[1];
					paddingTop = padding[0];
				}
				else if (padding.length == 4)
				{
					paddingLeft = padding[3];
					paddingTop = padding[0];
				}
			}
			else if (padding == null)
			{
				paddingLeft = ValuesManager.valuesImpl.getValue(_strand, "padding-left");
				paddingTop = ValuesManager.valuesImpl.getValue(_strand, "padding-top");
				paddingRight = ValuesManager.valuesImpl.getValue(_strand, "padding-right");
				paddingBottom = ValuesManager.valuesImpl.getValue(_strand, "padding-bottom");
			}
			else
			{
				paddingLeft = paddingTop = padding;
				paddingRight = paddingBottom = padding;
			}
			var pl:Number = Number(paddingLeft);
			var pt:Number = Number(paddingTop);
			var pr:Number = Number(paddingRight);
			var pb:Number = Number(paddingBottom);

			return {paddingLeft:pl, paddingTop:pt, paddingRight:pr, paddingBottom:pb};
		}

		/**
		 *  Returns true if container to create a separate ContainerContentArea.
		 *
		 *  @langversion 3.0
		 *  @playerversion Flash 10.2
		 *  @playerversion AIR 2.6
		 *  @productversion FlexJS 0.0
		 */
		protected function contentAreaNeeded():Boolean
		{
			var padding:Object = determinePadding();

			return (!isNaN(padding.paddingLeft) && padding.paddingLeft > 0 ||
				    !isNaN(padding.paddingTop) && padding.paddingTop > 0);
		}

        /**
         *  The parent of the children.
         *
         *  @langversion 3.0
         *  @playerversion Flash 10.2
         *  @playerversion AIR 2.6
         *  @productversion FlexJS 0.0
         */
		public function get contentView():IParentIUIBase
		{
			return actualParent;
		}

        /**
         *  The host component, which can resize to different slots.
         *
         *  @langversion 3.0
         *  @playerversion Flash 10.2
         *  @playerversion AIR 2.6
         *  @productversion FlexJS 0.0
         */
		public function get resizableView():IUIBase
		{
			return _strand as IUIBase;
		}

        private var inGetViewHeight:Boolean;

		/**
		 *  @copy org.apache.flex.core.IBeadView#viewHeight
		 *
		 *  @langversion 3.0
		 *  @playerversion Flash 10.2
		 *  @playerversion AIR 2.6
		 *  @productversion FlexJS 0.0
		 */
		override public function get viewHeight():Number
		{
            if (inGetViewHeight)
            {
                trace("ContainerView: no height set for " + host);
                return host["$height"];
            }
            inGetViewHeight = true;
			var vh:Number = contentView.height;
            inGetViewHeight = false;
            return vh;
		}

        private var inGetViewWidth:Boolean;

		/**
		 *  @copy org.apache.flex.core.IBeadView#viewWidth
		 *
		 *  @langversion 3.0
		 *  @playerversion Flash 10.2
		 *  @playerversion AIR 2.6
		 *  @productversion FlexJS 0.0
		 */
		override public function get viewWidth():Number
		{
            if (inGetViewWidth)
            {
                trace("ContainerView: no width set for " + host);
                return host["$width"];
            }
            inGetViewWidth = true;
			var vw:Number = contentView.width;
            inGetViewWidth = false;
			return vw;
		}

	}
}

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

    /**
     *  The ContainerView class is the default view for
     *  the org.apache.flex.core.ContainerBase classes.
     *  It lets you use some CSS styles to manage the border, background
     *  and padding around the content area.
     *
     *  @langversion 3.0
     *  @playerversion Flash 10.2
     *  @playerversion AIR 2.6
     *  @productversion FlexJS 0.0
     */
	public class ContainerView extends BeadViewBase implements IBeadView, ILayoutParent
	{
        /**
         *  Constructor.
         *
         *  @langversion 3.0
         *  @playerversion Flash 10.2
         *  @playerversion AIR 2.6
         *  @productversion FlexJS 0.0
         */
		public function ContainerView()
		{
		}

        /**
         *  The actual parent that parents the children.
         *
         *  @langversion 3.0
         *  @playerversion Flash 10.2
         *  @playerversion AIR 2.6
         *  @productversion FlexJS 0.0
         */
		protected var actualParent:UIBase;

        /**
         *  The layout.  The layout may actually layout
         *  the children of the internal content area
         *  and not the pieces of the "chrome" like titlebars
         *  and borders.  The ContainerView or its subclass will have some
         *  baked-in logic for handling the chrome.
         *
         *  @langversion 3.0
         *  @playerversion Flash 10.2
         *  @playerversion AIR 2.6
         *  @productversion FlexJS 0.0
         */
        protected var layout:IBeadLayout;

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

            var host:UIBase = value as UIBase;

            if (host.isWidthSizedToContent() && host.isHeightSizedToContent())
            {
                // if both dimensions are sized to content, then only draw the
                // borders, etc, after a child is added.  The children in an MXML
                // document don't send this event until the last child is added.
                host.addEventListener("childrenAdded", changeHandler);
                host.addEventListener("layoutNeeded", changeHandler);
                // listen for width and height changes as well in case the app
                // switches away from content sizing via binding or other code
                host.addEventListener("widthChanged", changeHandler);
                host.addEventListener("heightChanged", changeHandler);
            }
            else
            {
                // otherwise, listen for size changes before drawing
                // borders and laying out children.
                host.addEventListener("widthChanged", changeHandler);
                host.addEventListener("heightChanged", changeHandler);
                host.addEventListener("sizeChanged", sizeChangeHandler);
                // if we have fixed size in both dimensions, wait for children
                // to be added then run a layout pass right then as the
                // parent won't kick off any other event in the child
                if (!isNaN(host.explicitWidth) && !isNaN(host.explicitHeight))
                    host.addEventListener("childrenAdded", changeHandler);
            }
            checkActualParent();
        }

        private function checkActualParent():Boolean
        {
            var host:UIBase = UIBase(_strand);
            if (contentAreaNeeded())
            {
                if (actualParent == null || actualParent == host)
                {
                    actualParent = new ContainerContentArea();
					actualParent.className = "ActualParent";
                    host.addElement(actualParent, false);
                    ContainerBase(host).setActualParent(actualParent);
                }
                return true;
            }
            else
            {
                actualParent = host;
            }
            return false;
        }

        private function sizeChangeHandler(event:Event):void
        {
            var host:UIBase = UIBase(_strand);
            host.addEventListener("childrenAdded", changeHandler);
            host.addEventListener("layoutNeeded", changeHandler);
            host.addEventListener("itemsCreated", changeHandler);
            changeHandler(event);
        }

        private var inChangeHandler:Boolean;

        /**
         *  React if the size changed or content changed
         *
         *  @langversion 3.0
         *  @playerversion Flash 10.2
         *  @playerversion AIR 2.6
         *  @productversion FlexJS 0.0
         */
        protected function changeHandler(event:Event):void
        {
            if (inChangeHandler) return;

            inChangeHandler = true;

            var host:UIBase = UIBase(_strand);

            if (layout == null)
            {
                layout = _strand.getBeadByType(IBeadLayout) as IBeadLayout;
                if (layout == null)
                {
                    var c:Class = ValuesManager.valuesImpl.getValue(host, "iBeadLayout");
                    if (c)
                    {
                        layout = new c() as IBeadLayout;
                        _strand.addBead(layout);
                    }
                }
            }

			var padding:Object = determinePadding();

			if (checkActualParent())
			{
				actualParent.x = padding.paddingLeft;
				actualParent.y = padding.paddingTop;
            }
            var pb:Number = padding.paddingBottom;
            if (isNaN(pb))
                pb = 0;
            var pr:Number = padding.paddingRight;
            if (isNaN(pr))
                pr = 0;
            // if the width is dictated by the parent
            if (!host.isWidthSizedToContent())
            {
                if (actualParent != host)
                {
                    // force the width of the internal content area as desired.
                    actualParent.setWidth(host.width - padding.paddingLeft - pr);
                }
                // run the layout
                layout.layout();
            }
            else
            {
                // if the height is dictated by the parent
                if (!host.isHeightSizedToContent())
                {
                    if (actualParent != host)
                    {
                        // force the height
                        actualParent.setHeight(host.height - padding.paddingTop - pb);
                    }
                }
                layout.layout();
                if (actualParent != host)
                {
                    // actualParent.width should be the new width after layout.
                    // set the host's width.  This should send a widthChanged event and
                    // have it blocked at the beginning of this method
                    host.setWidth(padding.paddingLeft + pr + actualParent.width);
                }
            }
            // and if the height is sized to content, set the height now as well.
            if (host != actualParent)
            {
                if (host.isHeightSizedToContent())
                    host.setHeight(padding.paddingTop + pb + actualParent.height);
                else
                    actualParent.setHeight(host.height - padding.paddingTop - pb);
            }

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

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

            inChangeHandler = false;
		}

		/**
		 *  Determines the top and left padding values, if any, as set by
		 *  padding style values. This includes "padding" for all padding values
		 *  as well as "padding-left" and "padding-top".
		 *
		 *  Returns an object with paddingLeft and paddingTop properties.
		 *
		 *  @langversion 3.0
		 *  @playerversion Flash 10.2
		 *  @playerversion AIR 2.6
		 *  @productversion FlexJS 0.0
		 */
		protected function determinePadding():Object
		{
			var paddingLeft:Object;
			var paddingTop:Object;
			var paddingRight:Object;
			var paddingBottom:Object;
			var padding:Object = ValuesManager.valuesImpl.getValue(_strand, "padding");
			if (padding is Array)
			{
				if (padding.length == 1)
					paddingLeft = paddingTop = padding[0];
				else if (padding.length <= 3)
				{
					paddingLeft = padding[1];
					paddingTop = padding[0];
				}
				else if (padding.length == 4)
				{
					paddingLeft = padding[3];
					paddingTop = padding[0];
				}
			}
			else if (padding == null)
			{
				paddingLeft = ValuesManager.valuesImpl.getValue(_strand, "padding-left");
				paddingTop = ValuesManager.valuesImpl.getValue(_strand, "padding-top");
				paddingRight = ValuesManager.valuesImpl.getValue(_strand, "padding-right");
				paddingBottom = ValuesManager.valuesImpl.getValue(_strand, "padding-bottom");
			}
			else
			{
				paddingLeft = paddingTop = padding;
				paddingRight = paddingBottom = padding;
			}
			var pl:Number = Number(paddingLeft);
			var pt:Number = Number(paddingTop);
			var pr:Number = Number(paddingRight);
			var pb:Number = Number(paddingBottom);

			return {paddingLeft:pl, paddingTop:pt, paddingRight:pr, paddingBottom:pb};
		}

		/**
		 *  Returns true if container to create a separate ContainerContentArea.
		 *
		 *  @langversion 3.0
		 *  @playerversion Flash 10.2
		 *  @playerversion AIR 2.6
		 *  @productversion FlexJS 0.0
		 */
		protected function contentAreaNeeded():Boolean
		{
			var padding:Object = determinePadding();

			return (!isNaN(padding.paddingLeft) && padding.paddingLeft > 0 ||
				    !isNaN(padding.paddingTop) && padding.paddingTop > 0);
		}

        /**
         *  The parent of the children.
         *
         *  @langversion 3.0
         *  @playerversion Flash 10.2
         *  @playerversion AIR 2.6
         *  @productversion FlexJS 0.0
         */
		public function get contentView():IParentIUIBase
		{
			return actualParent;
		}

        /**
         *  The host component, which can resize to different slots.
         *
         *  @langversion 3.0
         *  @playerversion Flash 10.2
         *  @playerversion AIR 2.6
         *  @productversion FlexJS 0.0
         */
		public function get resizableView():IUIBase
		{
			return _strand as IUIBase;
		}

        private var inGetViewHeight:Boolean;

		/**
		 *  @copy org.apache.flex.core.IBeadView#viewHeight
		 *
		 *  @langversion 3.0
		 *  @playerversion Flash 10.2
		 *  @playerversion AIR 2.6
		 *  @productversion FlexJS 0.0
		 */
		override public function get viewHeight():Number
		{
            if (inGetViewHeight)
            {
                //trace("ContainerView: no height set for " + host);
                return host["$height"];
            }
            inGetViewHeight = true;
			var vh:Number = contentView.height;
            inGetViewHeight = false;
            return vh;
		}

        private var inGetViewWidth:Boolean;

		/**
		 *  @copy org.apache.flex.core.IBeadView#viewWidth
		 *
		 *  @langversion 3.0
		 *  @playerversion Flash 10.2
		 *  @playerversion AIR 2.6
		 *  @productversion FlexJS 0.0
		 */
		override public function get viewWidth():Number
		{
            if (inGetViewWidth)
            {
                //trace("ContainerView: no width set for " + host);
                return host["$width"];
            }
            inGetViewWidth = true;
			var vw:Number = contentView.width;
            inGetViewWidth = false;
			return vw;
		}

	}
}

remove trace

remove trace


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

package org.apache.flex.effects
{

import flash.geom.Rectangle;

import org.apache.flex.core.IDocument;
import org.apache.flex.core.IUIBase;

/**
 *  The Fade effect animates a UI component's alpha or opacity.
 *
 *  @langversion 3.0
 *  @playerversion Flash 10.2
 *  @playerversion AIR 2.6
 *  @productversion FlexJS 0.0
 */
public class Wipe extends Tween implements IDocument
{

    //--------------------------------------------------------------------------
    //
    //  Constructor
    //
    //--------------------------------------------------------------------------

    /**
     *  Constructor.
     *
     *  @param target Object ID or reference to an object that will
	 *  have its x and/or y property animated.
     *
     *  @langversion 3.0
     *  @playerversion Flash 9
     *  @playerversion AIR 1.1
     *  @productversion Flex 3
     */
    public function Wipe(target:IUIBase = null)
    {
        super();

		this.actualTarget = target;

		listener = this;
    }

    //--------------------------------------------------------------------------
    //
    //  Variables
    //
    //--------------------------------------------------------------------------

	/**
	 *  @private
	 *  The document.
	 */
	private var document:Object;

	/**
	 *  @private
	 *  The target.
	 */
	private var actualTarget:IUIBase;

    /**
     *  The target as the String id
     *  of a widget in an MXML Document.
     */
    public var target:String;

	/**
	 *  The direction of the Wipe.  "up" means the top will be the last
     *  part to disappear. "down" will reveal from the top down.
     */
    public var direction:String;

    private var wiper:PlatformWiper;

    //--------------------------------------------------------------------------
    //
    //  Properties
    //
    //--------------------------------------------------------------------------

    //--------------------------------------------------------------------------
    //
    //  Methods
    //
    //--------------------------------------------------------------------------

	public function setDocument(document:Object, id:String = null):void
	{
		this.document = document;
	}

	/**
	 *  @private
	 */
	override public function play():void
	{
        if (target != null)
            actualTarget = document[target];

        wiper.target = actualTarget;
        if (direction == "up")
        {
            startValue = actualTarget.height;
            endValue = 0;
        }
        else
        {
            startValue = 0;
            endValue = actualTarget.height;
            wiper.visibleRect = new Rectangle(0, 0, actualTarget.width, 0);
        }

		super.play();
	}

	public function onTweenUpdate(value:Number):void
	{
		wiper.visibleRect = new Rectangle(0, 0, actualTarget.width, value);
	}

	public function onTweenEnd(value:Number):void
	{
        wiper.target = null;
	}
}

}

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

package org.apache.flex.effects
{

import flash.geom.Rectangle;

import org.apache.flex.core.IDocument;
import org.apache.flex.core.IUIBase;

/**
 *  The Fade effect animates a UI component's alpha or opacity.
 *
 *  @langversion 3.0
 *  @playerversion Flash 10.2
 *  @playerversion AIR 2.6
 *  @productversion FlexJS 0.0
 */
public class Wipe extends Tween implements IDocument
{

    //--------------------------------------------------------------------------
    //
    //  Constructor
    //
    //--------------------------------------------------------------------------

    /**
     *  Constructor.
     *
     *  @param target Object ID or reference to an object that will
	 *  have its x and/or y property animated.
     *
     *  @langversion 3.0
     *  @playerversion Flash 9
     *  @playerversion AIR 1.1
     *  @productversion Flex 3
     */
    public function Wipe(target:IUIBase = null)
    {
        super();

		this.actualTarget = target;

		listener = this;
    }

    //--------------------------------------------------------------------------
    //
    //  Variables
    //
    //--------------------------------------------------------------------------

	/**
	 *  @private
	 *  The document.
	 */
	private var document:Object;

	/**
	 *  @private
	 *  The target.
	 */
	private var actualTarget:IUIBase;

    /**
     *  The target as the String id
     *  of a widget in an MXML Document.
     */
    public var target:String;

	/**
	 *  The direction of the Wipe.  "up" means the top will be the last
     *  part to disappear. "down" will reveal from the top down.
     */
    public var direction:String;

    private var wiper:PlatformWiper = new PlatformWiper();

    //--------------------------------------------------------------------------
    //
    //  Properties
    //
    //--------------------------------------------------------------------------

    //--------------------------------------------------------------------------
    //
    //  Methods
    //
    //--------------------------------------------------------------------------

	public function setDocument(document:Object, id:String = null):void
	{
		this.document = document;
	}

	/**
	 *  @private
	 */
	override public function play():void
	{
        if (target != null)
            actualTarget = document[target];

        wiper.target = actualTarget;
        if (direction == "up")
        {
            startValue = actualTarget.height;
            endValue = 0;
        }
        else
        {
            startValue = 0;
            endValue = actualTarget.height;
            // WipeDown makes something appear
            actualTarget.visible = true;
            wiper.visibleRect = new Rectangle(0, 0, actualTarget.width, 0);
        }

		super.play();
	}

	public function onTweenUpdate(value:Number):void
	{
        trace(actualTarget, value);
		wiper.visibleRect = new Rectangle(0, 0, actualTarget.width, value);
	}

	public function onTweenEnd(value:Number):void
	{
        // WipeUp makes something disappear
        if (direction == "up")
            actualTarget.visible = false;
        wiper.target = null;
	}
}

}

fix wipe effect

fix wipe effect