/**
* Copyright (c) 2007 - 2009 Adobe
* All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
package samples
{
import com.adobe.cairngorm.task.ITaskGroup;
import com.adobe.cairngorm.task.TaskEvent;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.ProgressEvent;
import flash.events.TimerEvent;
import flash.text.TextField;
import flash.utils.Timer;
import mx.events.FlexEvent;
import mx.preloaders.IPreloaderDisplay;
public class TaskFlowPreloader extends Sprite implements IPreloaderDisplay
{
private var labelText:TextField;
public function TaskFlowPreloader()
{
super();
}
//------------------------------------------------------------------------
//
// Implementation : IPreloaderDisplay
//
//------------------------------------------------------------------------
// Define a Loader control to load the SWF file.
// Specify the event listeners.
public function set preloader(preloader:Sprite):void
{
// Listen for the relevant events
preloader.addEventListener(ProgressEvent.PROGRESS, handleProgress);
preloader.addEventListener(Event.COMPLETE, handleComplete);
preloader.addEventListener(FlexEvent.INIT_PROGRESS, handleInitProgress);
preloader.addEventListener(FlexEvent.INIT_COMPLETE, handleInitComplete);
}
// Initialize the Loader control in the override
// of IPreloaderDisplay.initialize().
public function initialize():void
{
labelText = new TextField();
labelText.scaleX = 5;
labelText.scaleY = 5;
labelText.width = 600;
labelText.y = 330;
labelText.x = 300;
addChild(labelText);
labelText.text = "Loading Flex Framework";
addEventListener(Event.ENTER_FRAME, onEnterFrame);
}
private var counter:Number = 0;
private function onEnterFrame(event:Event):void
{
counter += 0.09;
graphics.clear();
var angle:Number = counter;
var color:Number = 0x000000;
for (var i:uint = 0; i < 60; i++)
{
angle -= 0.03;
color += 0x040404;
graphics.lineStyle(1, color);
graphics.moveTo(Math.cos(angle) * stageWidth + stageWidth / 2, Math.sin(angle) * stageHeight + stageHeight / 2);
graphics.lineTo(Math.cos(angle + 10) * stageWidth + stageWidth / 2,
Math.sin(angle + 10) * stageHeight + stageHeight / 2);
}
}
public function get backgroundColor():uint
{
return 0;
}
public function set backgroundColor(value:uint):void
{
}
public function get backgroundAlpha():Number
{
return 0;
}
public function set backgroundAlpha(value:Number):void
{
}
public function get backgroundImage():Object
{
return undefined;
}
public function set backgroundImage(value:Object):void
{
}
public function get backgroundSize():String
{
return "";
}
public function set backgroundSize(value:String):void
{
}
public function get stageWidth():Number
{
return _stageWidth;
}
private var _stageWidth:Number;
public function set stageWidth(value:Number):void
{
_stageWidth = value;
}
private var _stageHeight:Number;
public function get stageHeight():Number
{
return _stageHeight;
}
public function set stageHeight(value:Number):void
{
_stageHeight = value;
}
//------------------------------------------------------------------------
//
// Event Handlers
//
//------------------------------------------------------------------------
private function handleProgress(event:ProgressEvent):void
{
}
private function handleComplete(event:Event):void
{
}
private function handleInitProgress(event:Event):void
{
}
private function handleInitComplete(event:Event):void
{
var taskgroup:ITaskGroup = new ExampleTasks();
taskgroup.addEventListener(TaskEvent.CHILD_START, onChildStart);
taskgroup.addEventListener(TaskEvent.TASK_PROGRESS, onTaskProgress);
taskgroup.addEventListener(TaskEvent.TASK_COMPLETE, onTaskComplete);
taskgroup.start();
}
private function onChildStart(event:TaskEvent):void
{
labelText.text = event.task.label ? event.task.label : "";
}
private function onTaskProgress(event:TaskEvent):void
{
}
private function onTaskComplete(event:TaskEvent):void
{
dispatchEvent(new Event(Event.COMPLETE));
}
}
}