├── .gitignore
├── LICENSE.txt
├── README.md
├── bin
└── bumpslide-as3.swc
├── build.sample.properties
├── build.xml
├── libs
├── as3corelib.swc
├── as3corelib_json.swc
├── flexUnitTasks.jar
├── flexunit-cilistener-4.1.0-RC1.61-sdk4.0.0.14159.swc
├── flexunit-core-as3-4.1.0-RC1.61-sdk4.0.0.14159.swc
├── greensock.swc
└── robotlegs-framework-v1.4.0.swc
├── src
├── assets
│ ├── button_bg.png
│ ├── calendar_icon.png
│ ├── calendar_icon2.png
│ └── pf_ronda_seven.ttf
├── com
│ └── bumpslide
│ │ ├── command
│ │ ├── Command.as
│ │ ├── CommandEvent.as
│ │ ├── CommandEventDispatcher.as
│ │ ├── CommandQueue.as
│ │ ├── FrontController.as
│ │ ├── ICommand.as
│ │ ├── MapCommand.as
│ │ ├── Pause.as
│ │ ├── PendingCommand.as
│ │ ├── ServiceCall.as
│ │ └── robotlegs
│ │ │ ├── BumpslideCommandMap.as
│ │ │ ├── BumpslideContext.as
│ │ │ ├── CommandSequence.as
│ │ │ ├── DisplayApplicationStartupInfo.as
│ │ │ ├── HideStartupLog.as
│ │ │ ├── InitStartupLog.as
│ │ │ ├── StartupMessage.as
│ │ │ └── StartupMessageEvent.as
│ │ ├── data
│ │ ├── Action.as
│ │ ├── ActionQueue.as
│ │ ├── BindableModel.as
│ │ ├── Binding.as
│ │ ├── Callback.as
│ │ ├── IBindable.as
│ │ ├── ILazyItemProvider.as
│ │ ├── IPrioritizable.as
│ │ ├── IValueObject.as
│ │ ├── LazyArrayCollection.as
│ │ ├── LazyDataProvider.as
│ │ ├── LoopedDataProvider.as
│ │ ├── PriorityQueue.as
│ │ ├── ValueObject.as
│ │ ├── constant
│ │ │ ├── AspectRatio.as
│ │ │ ├── Direction.as
│ │ │ ├── Position.as
│ │ │ └── Unit.as
│ │ └── type
│ │ │ ├── Gradient.as
│ │ │ ├── Padding.as
│ │ │ └── RGB.as
│ │ ├── events
│ │ ├── DragEvent.as
│ │ ├── ModelChangeEvent.as
│ │ ├── UIEvent.as
│ │ └── ViewChangeEvent.as
│ │ ├── media
│ │ └── Mp3Player.as
│ │ ├── net
│ │ ├── AMFRequest.as
│ │ ├── AbstractRequest.as
│ │ ├── BrowseSelectRequest.as
│ │ ├── FileRequest.as
│ │ ├── HTTPRequest.as
│ │ ├── IRequest.as
│ │ ├── IResponder.as
│ │ ├── JSONRequest.as
│ │ ├── LoaderQueue.as
│ │ ├── LoaderRequest.as
│ │ ├── RequestPoller.as
│ │ ├── RequestQueue.as
│ │ ├── SocketConnection.as
│ │ ├── UploadRequest.as
│ │ ├── XMLRequest.as
│ │ ├── cache
│ │ │ ├── CachedDataRequest.as
│ │ │ ├── CachedFile.as
│ │ │ ├── FileCache.as
│ │ │ ├── ICache.as
│ │ │ └── ICachedItem.as
│ │ └── deprecated
│ │ │ ├── ServiceEvent.as
│ │ │ ├── URLEvent.as
│ │ │ ├── URLLoadRequest.as
│ │ │ └── URLLoaderQueue.as
│ │ ├── preloader
│ │ ├── PreloadEvent.as
│ │ ├── PreloaderApp.as
│ │ └── ProgressBar.as
│ │ ├── tween
│ │ ├── Ease.as
│ │ ├── FTween.as
│ │ ├── FTweenOptions.as
│ │ └── Fade.as
│ │ ├── ui
│ │ ├── AbstractScrollPanel.as
│ │ ├── Application.as
│ │ ├── BaseClip.as
│ │ ├── Box.as
│ │ ├── Button.as
│ │ ├── Calendar.as
│ │ ├── CheckBox.as
│ │ ├── ComboBox.as
│ │ ├── Component.as
│ │ ├── Container.as
│ │ ├── DatePicker.as
│ │ ├── Draw.as
│ │ ├── FramerateMonitor.as
│ │ ├── Grid.as
│ │ ├── GridItem.as
│ │ ├── HBox.as
│ │ ├── IGridItem.as
│ │ ├── IResizable.as
│ │ ├── IScrollable.as
│ │ ├── ISelectable.as
│ │ ├── ISkin.as
│ │ ├── ISkinnable.as
│ │ ├── IZoomable.as
│ │ ├── Image.as
│ │ ├── Label.as
│ │ ├── Lightbox.as
│ │ ├── MovieClipButton.as
│ │ ├── Panel.as
│ │ ├── PixelIcon.as
│ │ ├── Reflection.as
│ │ ├── ScrollPanel.as
│ │ ├── Skin.as
│ │ ├── Slider.as
│ │ ├── TextInput.as
│ │ ├── TextPanel.as
│ │ ├── ThumbnailItem.as
│ │ ├── TouchList.as
│ │ ├── VBox.as
│ │ ├── VSlider.as
│ │ ├── Wrapper.as
│ │ ├── ZoomPanel.as
│ │ ├── ZoomableContent.as
│ │ ├── behavior
│ │ │ ├── DragBehavior.as
│ │ │ ├── DragScrollBehavior.as
│ │ │ ├── DragZoomBehavior.as
│ │ │ ├── DropDownBehavior.as
│ │ │ ├── GridKeyboardFocusBehavior.as
│ │ │ ├── IBehavior.as
│ │ │ ├── RepeaterButtonBehavior.as
│ │ │ ├── TooltipBehavior.as
│ │ │ └── TouchBehavior.as
│ │ └── skin
│ │ │ ├── BasicButtonSkin.as
│ │ │ ├── BasicSliderSkin.as
│ │ │ ├── ImageButtonSkin.as
│ │ │ ├── MovieClipSkin.as
│ │ │ ├── MovieClipSliderSkin.as
│ │ │ ├── defaults
│ │ │ ├── DefaultButtonSkin.as
│ │ │ ├── DefaultCheckboxSkin.as
│ │ │ ├── DefaultComboBoxSkin.as
│ │ │ ├── DefaultDatePickerSkin.as
│ │ │ ├── DefaultPanelSkin.as
│ │ │ ├── DefaultSliderSkin.as
│ │ │ ├── DefaultTextInputSkin.as
│ │ │ └── Style.as
│ │ │ └── touch
│ │ │ └── TouchScrollSkin.as
│ │ ├── util
│ │ ├── ActivityMonitor.as
│ │ ├── Align.as
│ │ ├── ArrayUtil.as
│ │ ├── Console.as
│ │ ├── DateUtil.as
│ │ ├── Delegate.as
│ │ ├── DisplayUtil.as
│ │ ├── Dump.as
│ │ ├── GridLayout.as
│ │ ├── ImageUtil.as
│ │ ├── KeyTracker.as
│ │ ├── Link.as
│ │ ├── LoremIpsum.as
│ │ ├── MacMouseWheel.as
│ │ ├── Num.as
│ │ ├── ObjectPool.as
│ │ ├── ObjectUtil.as
│ │ ├── StageProxy.as
│ │ └── StringUtil.as
│ │ └── view
│ │ ├── BasicView.as
│ │ ├── ComponentView.as
│ │ ├── IView.as
│ │ ├── ViewLoader.as
│ │ ├── ViewStack.as
│ │ └── ViewState.as
├── fl
│ ├── data
│ │ └── DataProvider.as
│ └── events
│ │ ├── DataChangeEvent.as
│ │ └── DataChangeType.as
└── net
│ └── hires
│ └── debug
│ └── Stats.as
└── test
├── TestRunner.mxml
└── unit
├── BumpslideTestSuite.as
├── TestBindableModel.as
└── TestHTTPRequest.as
/.gitignore:
--------------------------------------------------------------------------------
1 | /doc
2 | /build.properties
3 | /.project
4 | /bin/*.cache
5 | Bumpslide_as3.iml
6 | .idea
7 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | Except where otherwise noted, the Bumpslide Library source code and
2 | supporting materials are Copyright (c) 2006, 2007, 2008, 2009, 2010, 2011 by Bumpslide, Inc.
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy
5 | of this software and associated documentation files (the "Software"), to deal
6 | in the Software without restriction, including without limitation the rights
7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | copies of the Software, and to permit persons to whom the Software is
9 | furnished to do so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in
12 | all copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 | THE SOFTWARE.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Bumpslide AS3 Library
2 | =====================
3 |
4 | This is the new home for the latest bumpslide as3 libs.
5 |
6 | * com.bumpslide.net
7 | * AS3-only Request/Response interfaces
8 | * AMF, XML, JSON, Request classes
9 | * Service Proxy
10 | * Request Queue
11 | * Socket/FMS Utils
12 |
13 | * com.bumpslide.ui
14 | * Skinnable UI Component model
15 | * MXML-friendly (without-flex)
16 | * Support Virtualized, Smooth-scrolling, Lists and Data grids
17 | * Page/View stack management
18 | * Re-usable behaviors
19 |
20 | * com.bumpslide.util
21 | * Common data types and structures
22 | * Non-Flex data binding
23 | * Static utilities
24 | * etc.
25 |
26 | * com.bumpslide.command
27 | * Front Controller and Command Pattern
28 | * Nestable Asynchronous Command Queues
29 |
--------------------------------------------------------------------------------
/bin/bumpslide-as3.swc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tkdave/bumpslide_as3/e3a0eb53c8fa22a95bf25bc797cd4c3061b7c5be/bin/bumpslide-as3.swc
--------------------------------------------------------------------------------
/build.sample.properties:
--------------------------------------------------------------------------------
1 | # IMPORTANT Change to your local system paths before using ANT
2 |
3 | #Toggle on/off specific targets
4 | run.test = true
5 | run.asdoc = true
6 | autolaunch.url = true
7 |
8 | # Build paths
9 | FLEX_HOME=/Users/tkdave/resources/flash/lib/flex45_sdk
10 |
11 | #Properties file for build.xml
12 | project.name=Bumpslide AS3 Library
13 | project.filename=bumpslide-as3
14 |
15 |
16 | #browser
17 | browser = Safari
18 | report.url = ${report.loc}/html/index.html
19 |
20 |
21 | ## Don't change these settings ###
22 |
23 | #build locations
24 | main.src.loc=${basedir}/src
25 | test.src.loc=${basedir}/test
26 | doc.src.loc=${basedir}/src/com/bumpslide
27 | swc.src.loc=${basedir}/src/com/bumpslide
28 | doc.loc=${basedir}/doc
29 | lib.loc=${basedir}/libs
30 | bin.loc=${basedir}/bin
31 | report.loc=${basedir}/report
32 | template.loc=${basedir}/build/templates
--------------------------------------------------------------------------------
/libs/as3corelib.swc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tkdave/bumpslide_as3/e3a0eb53c8fa22a95bf25bc797cd4c3061b7c5be/libs/as3corelib.swc
--------------------------------------------------------------------------------
/libs/as3corelib_json.swc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tkdave/bumpslide_as3/e3a0eb53c8fa22a95bf25bc797cd4c3061b7c5be/libs/as3corelib_json.swc
--------------------------------------------------------------------------------
/libs/flexUnitTasks.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tkdave/bumpslide_as3/e3a0eb53c8fa22a95bf25bc797cd4c3061b7c5be/libs/flexUnitTasks.jar
--------------------------------------------------------------------------------
/libs/flexunit-cilistener-4.1.0-RC1.61-sdk4.0.0.14159.swc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tkdave/bumpslide_as3/e3a0eb53c8fa22a95bf25bc797cd4c3061b7c5be/libs/flexunit-cilistener-4.1.0-RC1.61-sdk4.0.0.14159.swc
--------------------------------------------------------------------------------
/libs/flexunit-core-as3-4.1.0-RC1.61-sdk4.0.0.14159.swc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tkdave/bumpslide_as3/e3a0eb53c8fa22a95bf25bc797cd4c3061b7c5be/libs/flexunit-core-as3-4.1.0-RC1.61-sdk4.0.0.14159.swc
--------------------------------------------------------------------------------
/libs/greensock.swc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tkdave/bumpslide_as3/e3a0eb53c8fa22a95bf25bc797cd4c3061b7c5be/libs/greensock.swc
--------------------------------------------------------------------------------
/libs/robotlegs-framework-v1.4.0.swc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tkdave/bumpslide_as3/e3a0eb53c8fa22a95bf25bc797cd4c3061b7c5be/libs/robotlegs-framework-v1.4.0.swc
--------------------------------------------------------------------------------
/src/assets/button_bg.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tkdave/bumpslide_as3/e3a0eb53c8fa22a95bf25bc797cd4c3061b7c5be/src/assets/button_bg.png
--------------------------------------------------------------------------------
/src/assets/calendar_icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tkdave/bumpslide_as3/e3a0eb53c8fa22a95bf25bc797cd4c3061b7c5be/src/assets/calendar_icon.png
--------------------------------------------------------------------------------
/src/assets/calendar_icon2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tkdave/bumpslide_as3/e3a0eb53c8fa22a95bf25bc797cd4c3061b7c5be/src/assets/calendar_icon2.png
--------------------------------------------------------------------------------
/src/assets/pf_ronda_seven.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tkdave/bumpslide_as3/e3a0eb53c8fa22a95bf25bc797cd4c3061b7c5be/src/assets/pf_ronda_seven.ttf
--------------------------------------------------------------------------------
/src/com/bumpslide/command/Command.as:
--------------------------------------------------------------------------------
1 | /**
2 | * This code is part of the Bumpslide Library maintained by David Knape
3 | * Fork me at http://github.com/tkdave/bumpslide_as3
4 | *
5 | * Copyright (c) 2010 by Bumpslide, Inc.
6 | * http://www.bumpslide.com/
7 | *
8 | * This code is released under the open-source MIT license.
9 | * See LICENSE.txt for full license terms.
10 | * More info at http://www.opensource.org/licenses/mit-license.php
11 | */
12 |
13 | package com.bumpslide.command {
14 | import com.bumpslide.command.ICommand;
15 | import com.bumpslide.net.IResponder;
16 |
17 | import flash.events.Event;
18 | import flash.events.EventDispatcher;
19 | import flash.utils.getQualifiedClassName;
20 |
21 | /**
22 | * This is similar to a Cairngorm Command
23 | *
24 | * We've added some callback functionality
25 | * that was inspired by the UM Cairngorm extensions
26 | *
27 | * Basically, a CommandEvent can also be a responder which gives
28 | * views components a way to get called back directly when
29 | * a service call finishes or failts (result and fault, respectively)
30 | *
31 | * The notifyComplete and notifyError methods here facilitate these
32 | * callback notifications. They also dispatch Event.COMPLETE events
33 | * which are used to advance the CommandQueue if it is being used.
34 | *
35 | * If you are not using the CommandEvent as a responder, and are not using
36 | * the command queue, you can safely ignore the notify methods and all
37 | * references to the callback responder.
38 | *
39 | * @author David Knape
40 | */
41 | public class Command extends EventDispatcher implements ICommand {
42 |
43 |
44 | public var debugEnabled:Boolean=false;
45 |
46 | protected var _callback:IResponder;
47 |
48 | public function execute(event:CommandEvent=null):void {
49 | debug('execute() ' + (event ? 'event.data=' + event.data : '' ));
50 | callback = event;
51 | notifyComplete();
52 | }
53 |
54 | public function cancel() : void {
55 | debug('cancel()');
56 | notifyComplete();
57 | }
58 |
59 | /**
60 | * Notifies callback of successful completion
61 | */
62 | public function notifyComplete(data:Object=null) : void {
63 | debug('notifyComplete()');
64 | dispatchEvent( new Event(Event.COMPLETE) ); // used by CommandQueue to know when to advance
65 | if(callback) callback.result( data );
66 | }
67 |
68 | /**
69 | * Notifies callback of error
70 | */
71 | public function notifyError(info:Error) : void {
72 | dispatchEvent( new Event(Event.COMPLETE) ); // used by CommandQueue to know when to advance
73 | if(callback) callback.fault( info );
74 | }
75 |
76 | public function debug( s:String ) : void {
77 | if(debugEnabled) trace( this + " " + s );
78 | }
79 |
80 | override public function toString():String {
81 | return "[Command:"+getQualifiedClassName(this).split('::').pop()+"] ";
82 | }
83 |
84 | public function get callback():IResponder {
85 | return _callback;
86 | }
87 |
88 | public function set callback(callback:IResponder):void {
89 | _callback = callback;
90 | }
91 | }
92 | }
93 |
--------------------------------------------------------------------------------
/src/com/bumpslide/command/CommandEvent.as:
--------------------------------------------------------------------------------
1 | /**
2 | * This code is part of the Bumpslide Library maintained by David Knape
3 | * Fork me at http://github.com/tkdave/bumpslide_as3
4 | *
5 | * Copyright (c) 2010 by Bumpslide, Inc.
6 | * http://www.bumpslide.com/
7 | *
8 | * This code is released under the open-source MIT license.
9 | * See LICENSE.txt for full license terms.
10 | * More info at http://www.opensource.org/licenses/mit-license.php
11 | */
12 |
13 | package com.bumpslide.command
14 | {
15 | import com.bumpslide.net.IResponder;
16 |
17 | import flash.events.Event;
18 |
19 | /**
20 | * This is like a CairngormEvent. It triggers an application command.
21 | *
22 | * We've added built a responder interface for notifying views directly
23 | * when an asynchronous process has finished.
24 | *
25 | * Commands must store the event as it's callback in order to make this work.
26 | *
27 | * @author David Knape
28 | */
29 | public class CommandEvent extends Event implements IResponder
30 | {
31 |
32 | public var data:*;
33 |
34 | public var resultHandler:Function = null;
35 | public var faultHandler:Function = null;
36 |
37 |
38 | public function CommandEvent(type:String, data:Object = null, resultHandler:Function = null, faultHandler:Function = null )
39 | {
40 | super(type, true);
41 | this.data = data;
42 | this.resultHandler = resultHandler;
43 | this.faultHandler = faultHandler;
44 | }
45 |
46 |
47 | override public function clone():Event
48 | {
49 | return new CommandEvent(type, data);
50 | }
51 |
52 | override public function toString():String
53 | {
54 | return '[CommandEvent] "' + type + '" data=' + data;
55 | }
56 |
57 |
58 | public function fault(info:Error):void
59 | {
60 | if(faultHandler != null) {
61 | try {
62 | faultHandler.call(null, info);
63 | } catch (e:ArgumentError) {
64 | faultHandler.call(null);
65 | }
66 | }
67 | }
68 |
69 |
70 | public function result(data:Object):void
71 | {
72 | if(resultHandler != null) {
73 | try {
74 | resultHandler.call(null, data);
75 | } catch (e:ArgumentError) {
76 | resultHandler.call(null);
77 | }
78 | }
79 | }
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/src/com/bumpslide/command/CommandEventDispatcher.as:
--------------------------------------------------------------------------------
1 | /**
2 | * This code is part of the Bumpslide Library maintained by David Knape
3 | * Fork me at http://github.com/tkdave/bumpslide_as3
4 | *
5 | * Copyright (c) 2010 by Bumpslide, Inc.
6 | * http://www.bumpslide.com/
7 | *
8 | * This code is released under the open-source MIT license.
9 | * See LICENSE.txt for full license terms.
10 | * More info at http://www.opensource.org/licenses/mit-license.php
11 | */
12 |
13 | package com.bumpslide.command {
14 | import flash.events.EventDispatcher;
15 |
16 | /**
17 | * Event Dispatcher reserved for sending command events
18 | *
19 | * The controller is the only one listening to this.
20 | * This is very much like the CairngormEventDispatcher
21 | *
22 | * @author David Knape
23 | */
24 | public class CommandEventDispatcher extends EventDispatcher {
25 |
26 | public function CommandEventDispatcher(singletonEnforcer:PrivacyToken) {
27 | super();
28 | }
29 |
30 | private static var instance : CommandEventDispatcher;
31 |
32 | /**
33 | * Returns the single instance of the dispatcher
34 | */
35 | public static function getInstance() : CommandEventDispatcher {
36 | if(instance==null) {
37 | instance = new CommandEventDispatcher(new PrivacyToken());
38 | }
39 | return instance;
40 | }
41 |
42 |
43 | }
44 | }
45 |
46 | class PrivacyToken {}
47 |
--------------------------------------------------------------------------------
/src/com/bumpslide/command/FrontController.as:
--------------------------------------------------------------------------------
1 | /**
2 | * This code is part of the Bumpslide Library maintained by David Knape
3 | * Fork me at http://github.com/tkdave/bumpslide_as3
4 | *
5 | * Copyright (c) 2010 by Bumpslide, Inc.
6 | * http://www.bumpslide.com/
7 | *
8 | * This code is released under the open-source MIT license.
9 | * See LICENSE.txt for full license terms.
10 | * More info at http://www.opensource.org/licenses/mit-license.php
11 | */
12 | package com.bumpslide.command
13 | {
14 |
15 | import flash.utils.Dictionary;
16 | [DefaultProperty(name='mappedCommands')]
17 |
/**
* A base class for an application specific front controller.
*
* This is a Cairngorm Front Controller with flex dependencies removed.
*/
public class FrontController {
protected var commands:Dictionary=new Dictionary();
/**
* Registers a ICommand class with the Front Controller, against an event name
* and listens for events with that name.
*/
public function addCommand( commandName:String, commandRef:Class, useWeakReference:Boolean=true ):void {
if( commands[ commandName ] != null ) {
throw new Error("Command already registered: " + commandName);
}
commands[ commandName ] = commandRef;
CommandEventDispatcher.getInstance().addEventListener(commandName, executeCommand, false, 0, useWeakReference);
}
/**
* Deregisters an ICommand class with the given event name from the Front Controller
*/
public function removeCommand( commandName:String ):void {
if( commands[ commandName ] === null) {
throw new Error("Unable to remove command, not registered: " + commandName);
}
CommandEventDispatcher.getInstance().removeEventListener(commandName, executeCommand);
commands[ commandName ] = null;
delete commands[ commandName ];
}
/**
* Executes the command
*/
protected function executeCommand( event:CommandEvent ):void {
var commandClass:Class=getCommand(event.type);
var commandToExecute:ICommand=new commandClass();
commandToExecute.execute(event);
}
/**
* Returns the command class registered with the command name.
*/
protected function getCommand( commandName:String ):Class {
var command:Class=commands[ commandName ];
if ( command == null ) {
throw new Error("Command not found: " + commandName);
}
return command;
}
18 |
19 | public function set mappedCommands( a:Array ):void {
20 | for each (var map:* in a) {
21 | if( map is MapCommand) {
22 | var m:MapCommand = (map as MapCommand);
23 | addCommand( m.name, m.commandClass );
24 | }
25 | }
26 | }
27 |
28 |
}
}
--------------------------------------------------------------------------------
/src/com/bumpslide/command/ICommand.as:
--------------------------------------------------------------------------------
1 | /**
2 | * This code is part of the Bumpslide Library maintained by David Knape
3 | * Fork me at http://github.com/tkdave/bumpslide_as3
4 | *
5 | * Copyright (c) 2010 by Bumpslide, Inc.
6 | * http://www.bumpslide.com/
7 | *
8 | * This code is released under the open-source MIT license.
9 | * See LICENSE.txt for full license terms.
10 | * More info at http://www.opensource.org/licenses/mit-license.php
11 | */
12 |
13 | package com.bumpslide.command {
14 |
15 | import flash.events.IEventDispatcher;
16 |
17 | /**
18 | * Comand Interface
19 | *
20 | * @author David Knape
21 | */
22 | public interface ICommand extends IEventDispatcher {
23 |
24 | // run the command
25 | function execute( event:CommandEvent=null ) : void;
26 |
27 | // cancels pending activity (for asynchronous commands)
28 | function cancel() : void;
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/com/bumpslide/command/MapCommand.as:
--------------------------------------------------------------------------------
1 | package com.bumpslide.command
2 | {
3 | /**
4 | * Value used by FrontController in MXML mode
5 | *
6 | * @author David Knape
7 | */
8 | public class MapCommand
9 | {
10 | public var commandClass:Class;
11 | public var name:String;
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/src/com/bumpslide/command/Pause.as:
--------------------------------------------------------------------------------
1 | package com.bumpslide.command
2 | {
3 |
4 | import com.bumpslide.util.Delegate;
5 |
6 | import flash.utils.Timer;
7 |
8 | /**
9 | * Pause Command
10 | *
11 | * Useful in MXML startup sequence
12 | *
13 | * Example:
14 | *
15 | *
16 | *
17 | * @author David Knape
18 | */
19 | public class Pause extends Command
20 | {
21 |
22 | public var time:Number = 1000;
23 |
24 | private var delay:Timer;
25 |
26 | override public function execute( event:CommandEvent = null ):void
27 | {
28 | if (event.data is Number) {
29 | time = event.data as Number;
30 | }
31 |
32 | delay = Delegate.callLater( time, notifyComplete );
33 | }
34 |
35 |
36 | override public function cancel():void
37 | {
38 | Delegate.cancel( delay );
39 | super.cancel();
40 | }
41 |
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/com/bumpslide/command/PendingCommand.as:
--------------------------------------------------------------------------------
1 | package com.bumpslide.command
2 | {
3 |
4 | import com.bumpslide.data.Action;
5 |
6 | /**
7 | * PendingCommand
8 | *
9 | * @author David Knape
10 | */
11 | public class PendingCommand extends Action
12 | {
13 |
14 | public var command:ICommand;
15 |
16 | public function PendingCommand( command:ICommand, executeAction:Function, priority:uint=-1)
17 | {
18 | this.command = command;
19 | super( executeAction, priority);
20 | }
21 |
22 |
23 | override public function toString():String
24 | {
25 | return String( command );
26 | }
27 |
28 |
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/com/bumpslide/command/ServiceCall.as:
--------------------------------------------------------------------------------
1 | /**
2 | * This code is part of the Bumpslide Library maintained by David Knape
3 | * Fork me at http://github.com/tkdave/bumpslide_as3
4 | *
5 | * Copyright (c) 2010 by Bumpslide, Inc.
6 | * http://www.bumpslide.com/
7 | *
8 | * This code is released under the open-source MIT license.
9 | * See LICENSE.txt for full license terms.
10 | * More info at http://www.opensource.org/licenses/mit-license.php
11 | */
12 |
13 | package com.bumpslide.command {
14 | import com.bumpslide.command.Command;
15 | import com.bumpslide.net.HTTPRequest;
16 | import com.bumpslide.net.IRequest;
17 | import com.bumpslide.net.IResponder;
18 |
19 | import flash.net.URLRequest;
20 |
21 | /**
22 | * This is an example command that makes a service call using an RPC request
23 | *
24 | * In this case, the event.data is the url we want to load
25 | *
26 | * This can be extended if you want, but it's more of a template/example.
27 | *
28 | * @author David Knape
29 | */
30 | public class ServiceCall extends Command implements IResponder {
31 |
32 | protected var rpc:IRequest;
33 |
34 | override public function execute(event:CommandEvent=null):void {
35 | callback = event;
36 | var url:String = event.data as String; // event.data is the URL
37 | rpc = new HTTPRequest( new URLRequest( url ), this );
38 | rpc.load();
39 | }
40 |
41 | override public function cancel() : void {
42 | rpc.cancel();
43 | }
44 |
45 | public function fault(info:Error):void {
46 | debug( String( info ) );
47 | notifyError( info );
48 | }
49 |
50 | public function result(data:Object):void {
51 | notifyComplete( data );
52 | }
}
53 | }
54 |
--------------------------------------------------------------------------------
/src/com/bumpslide/command/robotlegs/BumpslideCommandMap.as:
--------------------------------------------------------------------------------
1 | package com.bumpslide.command.robotlegs
2 | {
3 |
4 | import com.bumpslide.command.CommandEvent;
5 | import com.bumpslide.command.ICommand;
6 | import org.robotlegs.base.CommandMap;
7 | import org.robotlegs.core.IInjector;
8 | import org.robotlegs.core.IReflector;
9 |
10 | import flash.events.IEventDispatcher;
11 |
12 | /**
13 | * Robotlegs command map that support bumpslide MVC commands
14 | *
15 | * @author David Knape
16 | */
17 | public class BumpslideCommandMap extends CommandMap
18 | {
19 |
20 | public function BumpslideCommandMap( eventDispatcher:IEventDispatcher, injector:IInjector, reflector:IReflector )
21 | {
22 | super( eventDispatcher, injector, reflector );
23 | }
24 |
25 |
26 | /**
27 | * @inheritDoc
28 | */
29 | override public function execute( commandClass:Class, payload:Object = null, payloadClass:Class = null, named:String = '' ):void
30 | {
31 | verifyCommandClass( commandClass );
32 |
33 | if (payload != null || payloadClass != null) {
34 | payloadClass ||= reflector.getClass( payload );
35 | injector.mapValue( payloadClass, payload, named );
36 | }
37 |
38 | var command:Object = injector.instantiate( commandClass );
39 |
40 | if (payload !== null || payloadClass != null)
41 | injector.unmap( payloadClass, named );
42 |
43 | if(command is ICommand && payload is CommandEvent) {
44 | var bumpslide_command:ICommand = command as ICommand;
45 | bumpslide_command.execute( payload as CommandEvent );
46 | } else {
47 | command.execute();
48 | }
49 | }
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/src/com/bumpslide/command/robotlegs/BumpslideContext.as:
--------------------------------------------------------------------------------
1 | package com.bumpslide.command.robotlegs
2 | {
3 |
4 | import org.robotlegs.core.ICommandMap;
5 | import org.robotlegs.mvcs.Context;
6 |
7 | import flash.display.DisplayObjectContainer;
8 |
9 | /**
10 | * Robotlegs context that enables support for Bumpslide command map and Bumpslide commands
11 | *
12 | * @author David Knape, http://bumpslide.com/
13 | */
14 | public class BumpslideContext extends Context
15 | {
16 |
17 | public function BumpslideContext( contextView:DisplayObjectContainer = null, autoStartup:Boolean = true )
18 | {
19 | super( contextView, autoStartup );
20 | }
21 |
22 |
23 | /**
24 | * Use custom Bumpslide-MVC CommandMap
25 | */
26 | override protected function get commandMap():ICommandMap {
27 | return _commandMap || (_commandMap = new BumpslideCommandMap( eventDispatcher, injector.createChild(), reflector ));
28 | }
29 |
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/com/bumpslide/command/robotlegs/CommandSequence.as:
--------------------------------------------------------------------------------
1 | package com.bumpslide.command.robotlegs
2 | {
3 |
4 | import com.bumpslide.command.CommandEvent;
5 | import com.bumpslide.command.CommandQueue;
6 | import com.bumpslide.command.ICommand;
7 |
8 | import org.robotlegs.core.IInjector;
9 |
10 | /**
11 | * Robotlegs-friendly Command Queue
12 | *
13 | * Supports Dependency Injection into each command being run.
14 | *
15 | * This class can be used in MXML or Actionscript.
16 | *
17 | * @author David Knape
18 | */
19 | public class CommandSequence extends CommandQueue
20 | {
21 |
22 | [Inject]
23 | public var injector:IInjector;
24 |
25 | // inject dependencies just before we execute the command
26 | override protected function doExecute( command:ICommand, event:CommandEvent = null ):void
27 | {
28 | debug( 'Running command ' + command );
29 | injector.injectInto( command );
30 | super.doExecute( command, event );
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/com/bumpslide/command/robotlegs/DisplayApplicationStartupInfo.as:
--------------------------------------------------------------------------------
1 | package com.bumpslide.command.robotlegs
2 | {
3 |
4 | import com.bumpslide.command.Command;
5 | import com.bumpslide.command.CommandEvent;
6 |
7 | import flash.desktop.NativeApplication;
8 | import flash.events.IEventDispatcher;
9 |
10 | /**
11 | * Displays AIR app info (pulled from app xml) in the startup log display
12 | *
13 | * @author David Knape
14 | */
15 | public class DisplayApplicationStartupInfo extends Command
16 | {
17 | [Inject]
18 | public var dispatcher:IEventDispatcher;
19 |
20 | override public function execute( event:CommandEvent = null ):void
21 | {
22 | var app:XML = NativeApplication.nativeApplication.applicationDescriptor;
23 | var ns:Namespace = app.namespace();
24 | var msg:String = "Loading " + app.ns::name[0] + " version " + app.ns::versionNumber[0] +"\n\n";
25 |
26 | dispatcher.dispatchEvent( new StartupMessageEvent( msg ) );
27 |
28 | super.execute( event );
29 | }
30 |
31 |
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/com/bumpslide/command/robotlegs/HideStartupLog.as:
--------------------------------------------------------------------------------
1 | package com.bumpslide.command.robotlegs
2 | {
3 | import com.bumpslide.command.Command;
4 | import com.bumpslide.command.CommandEvent;
5 | import com.bumpslide.tween.FTween;
6 | import com.bumpslide.ui.Label;
7 |
8 | import org.robotlegs.core.IInjector;
9 |
10 | /**
11 | * Hide the startup log created by the InitStartupLog command
12 | *
13 | * @author David Knape, http://bumpslide.com/
14 | */
15 | public class HideStartupLog extends Command
16 | {
17 |
18 | [Inject]
19 | public var injector:IInjector;
20 |
21 | [Inject(name='startupLogDisplay')]
22 | public var label:Label;
23 |
24 | override public function execute( event:CommandEvent = null ):void
25 | {
26 | if(label) FTween.fadeOut( label, 500, .3, notifyComplete );
27 | else notifyComplete();
28 | }
29 |
30 |
31 | override public function notifyComplete( data:Object = null ):void
32 | {
33 | if(label && label.parent && label.parent.contains(label)) {
34 | label.parent.removeChild( label );
35 | }
36 |
37 | injector.unmap( Label, 'startupLogDisplay');
38 |
39 | super.notifyComplete( data );
40 | }
41 |
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/com/bumpslide/command/robotlegs/InitStartupLog.as:
--------------------------------------------------------------------------------
1 | package com.bumpslide.command.robotlegs
2 | {
3 |
4 | import com.bumpslide.command.Command;
5 | import com.bumpslide.command.CommandEvent;
6 | import com.bumpslide.data.type.Padding;
7 | import com.bumpslide.ui.Label;
8 | import com.bumpslide.util.ObjectUtil;
9 |
10 | import org.robotlegs.core.ICommandMap;
11 | import org.robotlegs.core.IInjector;
12 | import org.robotlegs.core.IViewMap;
13 |
14 | import flash.text.TextFormat;
15 |
16 | /**
17 | * Command that creates a startup log
18 | *
19 | * This creates a label in the contextView of this Robotlegs context.
20 | * The label is used to display startup messages.
21 | *
22 | * Start messages are posted using the StartMessage command which is
23 | * triggered by the StartupLogEvent.
24 | *
25 | * @author David Knape, http://bumpslide.com/
26 | */
27 | public class InitStartupLog extends Command
28 | {
29 |
30 | [Inject]
31 | public var injector:IInjector;
32 |
33 | [Inject]
34 | public var viewMap:IViewMap;
35 |
36 | [Inject]
37 | public var commandMap:ICommandMap;
38 |
39 | public var fontName:String = "Courier New";
40 | public var fontSize:Number = 14;
41 | public var color:* = "#999999";
42 | public var padding:* = 20;
43 | public var bold:Boolean = false;
44 |
45 | override public function execute(event:CommandEvent=null):void
46 | {
47 | if(isNaN(color)) color = parseInt( String(color).replace('#',''), 16 );
48 | if(!padding is Padding) padding = Padding.create(padding);
49 |
50 | var format:TextFormat = new TextFormat( fontName, fontSize, color, bold );
51 |
52 | // create a label to display the text
53 | var label:Label = ObjectUtil.create( Label, { padding:padding, width:1280, height:720, textFormat:format} );
54 |
55 | // add it as a child to this context views
56 | viewMap.contextView.addChild( label );
57 |
58 | // let other commands access this label
59 | injector.mapValue( Label, label, 'startupLogDisplay' );
60 |
61 | commandMap.mapEvent( StartupMessageEvent.LOG_MESSAGE, StartupMessage, StartupMessageEvent );
62 |
63 | notifyComplete();
64 |
65 | }
66 |
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/src/com/bumpslide/command/robotlegs/StartupMessage.as:
--------------------------------------------------------------------------------
1 | package com.bumpslide.command.robotlegs
2 | {
3 |
4 | import com.bumpslide.command.Command;
5 | import com.bumpslide.command.CommandEvent;
6 | import com.bumpslide.ui.Label;
7 | import com.bumpslide.util.Delegate;
8 |
9 | /**
10 | * Post message to startup log
11 | *
12 | * @author David Knape
13 | */
14 | public class StartupMessage extends Command
15 | {
16 |
17 | [Inject(name='startupLogDisplay')]
18 | public var startupLogDisplay:Label;
19 |
20 | public var text:String = "";
21 | public var pause:uint = 200;
22 |
23 | override public function execute( event:CommandEvent = null ):void
24 | {
25 | if (event.data) {
26 | text = event.data as String;
27 | }
28 |
29 | startupLogDisplay.text += "\n" + text;
30 | startupLogDisplay.updateNow();
31 |
32 | Delegate.callLater( 10 + pause, super.execute, event );
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/com/bumpslide/command/robotlegs/StartupMessageEvent.as:
--------------------------------------------------------------------------------
1 | package com.bumpslide.command.robotlegs
2 | {
3 |
4 | import flash.events.Event;
5 | import com.bumpslide.command.CommandEvent;
6 |
7 | /**
8 | * Log a message to the startup log
9 | *
10 | * @author David Knape, http://bumpslide.com/
11 | */
12 | public class StartupMessageEvent extends CommandEvent
13 | {
14 |
15 | static public const LOG_MESSAGE:String = "startupLogMessage";
16 |
17 | public function StartupMessageEvent(message:String)
18 | {
19 | super(LOG_MESSAGE, message, resultHandler, faultHandler );
20 | }
21 |
22 | public function get message():String {
23 | return data as String;
24 | }
25 |
26 |
27 | override public function clone():Event
28 | {
29 | return new StartupMessageEvent(message);
30 | }
31 |
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/com/bumpslide/data/Action.as:
--------------------------------------------------------------------------------
1 | /**
2 | * This code is part of the Bumpslide Library maintained by David Knape
3 | * Fork me at http://github.com/tkdave/bumpslide_as3
4 | *
5 | * Copyright (c) 2010 by Bumpslide, Inc.
6 | * http://www.bumpslide.com/
7 | *
8 | * This code is released under the open-source MIT license.
9 | * See LICENSE.txt for full license terms.
10 | * More info at http://www.opensource.org/licenses/mit-license.php
11 | */
12 |
13 | package com.bumpslide.data {
14 |
15 | import com.bumpslide.data.IPrioritizable;
16 |
17 | /**
18 | * This is just an action and a priority as well as a creation index
19 | * used to preserve queue order in case priority is not used.
20 | *
21 | * @author David Knape
22 | */
23 | public class Action implements IPrioritizable {
24 |
25 | static private var lastNum:int =0;
26 |
27 | private var _action:Function;
28 | private var _priority:int;
29 | private var _creationIndex:int;
30 | private var _name:String="";
31 |
32 | public function Action(action:Function, priority:int=-1, name:String="") {
33 | _priority = priority;
34 | _action = action;
35 | _creationIndex = lastNum++;
36 | _name = name;
37 | }
38 |
39 | public function get action():Function {
40 | return _action;
41 | }
42 |
43 | public function set action(action:Function):void {
44 | _action = action;
45 | }
46 |
47 | public function execute() : void {
48 | action.call();
49 | }
50 |
51 | public function get priority():int {
52 | return _priority;
53 | }
54 |
55 | public function set priority(priority:int):void {
56 | _priority = priority;
57 | }
58 |
59 | public function toString() : String {
60 | return "[Action "+_creationIndex + " "+name+"]";
61 | }
62 |
63 | public function get creationIndex():int {
64 | return _creationIndex;
65 | }
66 |
67 |
68 | public function get name():String {
69 | return _name;
70 | }
71 |
72 |
73 | public function set name( name:String ):void {
74 | _name = name;
75 | }
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/src/com/bumpslide/data/Callback.as:
--------------------------------------------------------------------------------
1 | /**
2 | * This code is part of the Bumpslide Library maintained by David Knape
3 | * Fork me at http://github.com/tkdave/bumpslide_as3
4 | *
5 | * Copyright (c) 2010 by Bumpslide, Inc.
6 | * http://www.bumpslide.com/
7 | *
8 | * This code is released under the open-source MIT license.
9 | * See LICENSE.txt for full license terms.
10 | * More info at http://www.opensource.org/licenses/mit-license.php
11 | */
12 |
13 | package com.bumpslide.data {
import com.bumpslide.net.IResponder;
/**
* Barebones IResponder implementation
*
* @author David Knape
*/
public class Callback implements IResponder {
private var _resultHandler:Function;
private var _faultHandler:Function;
private var _passThruData:Object;
public function Callback( result_handler:Function, fault_handler:Function=null, pass_thru_data:Object=null) {
_resultHandler = result_handler;
_faultHandler = fault_handler;
_passThruData = pass_thru_data;
}
public function fault(info:Error):void {
if(_faultHandler is Function) {
try {
_faultHandler.call( null, info, _passThruData );
} catch (e1:ArgumentError) {
try {
_faultHandler.call( null, info );
} catch (e:ArgumentError) {
_faultHandler.call( null );
}
}
}
}
public function result(data:Object):void {
if(_resultHandler is Function) {
try {
_resultHandler.call( null, data, _passThruData );
} catch (e1:ArgumentError) {
try {
_resultHandler.call( null, data );
} catch (e:ArgumentError) {
_resultHandler.call( null );
}
}
}
}
}
}
--------------------------------------------------------------------------------
/src/com/bumpslide/data/IBindable.as:
--------------------------------------------------------------------------------
1 | /**
2 | * This code is part of the Bumpslide Library maintained by David Knape
3 | * Fork me at http://github.com/tkdave/bumpslide_as3
4 | *
5 | * Copyright (c) 2010 by Bumpslide, Inc.
6 | * http://www.bumpslide.com/
7 | *
8 | * This code is released under the open-source MIT license.
9 | * See LICENSE.txt for full license terms.
10 | * More info at http://www.opensource.org/licenses/mit-license.php
11 | */
12 |
13 | package com.bumpslide.data {
14 |
15 | /**
16 | * Represents bindable things.
17 | *
18 | * This interface is just a suggested API for advertising the fact
19 | * that a specific class dispatches events of the type ModelChangeEvent
20 | *
21 | * Example implementations are in data.BindableModel and ui.Component
22 | *
23 | * @see BindableModel for implementation.
24 | *
25 | * @author David Knape
26 | */
27 | public interface IBindable {
28 |
29 | function bind( property:String, target:Object, setterOrFunction:*=null ):Binding ;
30 |
31 | function unbind( target:Object, property:String=null ):void;
32 |
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/com/bumpslide/data/ILazyItemProvider.as:
--------------------------------------------------------------------------------
1 | /**
2 | * This code is part of the Bumpslide Library maintained by David Knape
3 | * Fork me at http://github.com/tkdave/bumpslide_as3
4 | *
5 | * Copyright (c) 2010 by Bumpslide, Inc.
6 | * http://www.bumpslide.com/
7 | *
8 | * This code is released under the open-source MIT license.
9 | * See LICENSE.txt for full license terms.
10 | * More info at http://www.opensource.org/licenses/mit-license.php
11 | */
12 |
13 | package com.bumpslide.data
14 | {
15 |
16 | import com.bumpslide.net.IRequest;
17 |
18 | /**
19 | * Lazy Loading Item Provider interface
20 | *
21 | * @author David Knape
22 | */
23 | public interface ILazyItemProvider
24 | {
25 | function getItems(start:int, length:int):IRequest;
26 |
27 | function getTotal():IRequest;
28 |
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/com/bumpslide/data/IPrioritizable.as:
--------------------------------------------------------------------------------
1 | /**
2 | * This code is part of the Bumpslide Library maintained by David Knape
3 | * Fork me at http://github.com/tkdave/bumpslide_as3
4 | *
5 | * Copyright (c) 2010 by Bumpslide, Inc.
6 | * http://www.bumpslide.com/
7 | *
8 | * This code is released under the open-source MIT license.
9 | * See LICENSE.txt for full license terms.
10 | * More info at http://www.opensource.org/licenses/mit-license.php
11 | */
12 |
13 | package com.bumpslide.data {
14 |
15 | /**
16 | * Pritoritiziable Interface for use with hacked version of polygonal.de PriorityQueue
17 | *
18 | * @author David Knape
19 | */
20 | public interface IPrioritizable {
21 | function get priority():int;
22 | function set priority(p:int):void;
23 | function get creationIndex() : int;
24 |
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/com/bumpslide/data/IValueObject.as:
--------------------------------------------------------------------------------
1 | /**
2 | * This code is part of the Bumpslide Library maintained by David Knape
3 | * Fork me at http://github.com/tkdave/bumpslide_as3
4 | *
5 | * Copyright (c) 2010 by Bumpslide, Inc.
6 | * http://www.bumpslide.com/
7 | *
8 | * This code is released under the open-source MIT license.
9 | * See LICENSE.txt for full license terms.
10 | * More info at http://www.opensource.org/licenses/mit-license.php
11 | */
12 |
13 | package com.bumpslide.data {
14 |
15 | /**
16 | * Basic Value object interface
17 | *
18 | * @author David Knape
19 | */
20 | public interface IValueObject {
21 |
22 | function equals(value:Object):Boolean;
23 |
24 | function clone():Object;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/com/bumpslide/data/LoopedDataProvider.as:
--------------------------------------------------------------------------------
1 | /**
2 | * This code is part of the Bumpslide Library maintained by David Knape
3 | * Fork me at http://github.com/tkdave/bumpslide_as3
4 | *
5 | * Copyright (c) 2010 by Bumpslide, Inc.
6 | * http://www.bumpslide.com/
7 | *
8 | * This code is released under the open-source MIT license.
9 | * See LICENSE.txt for full license terms.
10 | * More info at http://www.opensource.org/licenses/mit-license.php
11 | */
12 |
13 | package com.bumpslide.data {
/**
* @author David Knape
*/
public class LoopedDataProvider {
private var data:Array;
private var _length:Number = uint.MAX_VALUE;
public function LoopedDataProvider( a:Array, dp_length:Number=uint.MAX_VALUE) {
data = a;
length = dp_length;
}
public function getItemAt(n:Number) : * {
if(data.length==0) return undefined;
return data[ n%data.length ];
}
public function get length () : Number {
return _length;
}
public function set length (max_length:Number) : void {
_length = max_length;
}
public function getArray():Array {
var a:Array = new Array();
for(var n:Number=0; n= 0 && val <= 0xFFFFFF ) {
var color:RGB = new RGB();
color.red = val >> 16 & 0xFF;
color.green = val >> 8 & 0xFF;
color.blue = val & 0xFF;
} else {
throw new Error( "the number parameter to create an rgb object has to be between 0 and 0xFFFFFF not: " + val );
}
return color;
}
/**
* returns a copy of the rgb object
*/
public function clone():RGB {
return new RGB( red, green, blue);
}
/**
* returns true if the rgb object to compare has the same colorvalue as the current.
*/
public function equals( compare:RGB ):Boolean {
return number == compare.number;
}
/**
* sets the single color values ( 0 - 255 )
*/
public function set red( val:int ):void {
if( !isNaN( val ) ) r = Math.max( Math.min( val, 255 ), 0 );
}
public function set green( val:int ):void {
if( !isNaN( val ) ) g = Math.max( Math.min( val, 255 ), 0 );
}
public function set blue( val:int ):void {
if( !isNaN( val ) ) b = Math.max( Math.min( val, 255 ), 0 );
}
/**
* returns the single color values ( 0 - 255 )
*/
public function get red():int {
return r;
}
public function get green():int {
return g;
}
public function get blue():int {
return b;
}
/**
* returns the rgb value as a 16mio number
*/
public function get number():uint {
return (r << 16 | g << 8 | b);
}
/**
* returns the hex code as a string
*/
public function get hex():String {
return "0x" + red.toString( 16 ) + green.toString( 16 ) + blue.toString( 16 );
}
public function toString() : String{
return 'RGB('+red+','+green+','+blue+')';
15 | }
16 |
17 | /**
18 | * Interpolate from one color to another. val is 0 to 1.0;
19 | */
20 | public static function interpolate( rgb1:RGB, rgb2:RGB, val:Number ):RGB
21 | {
22 | return new RGB( (rgb2.red - rgb1.red ) * val + rgb1.red, (rgb2.green - rgb1.green ) * val + rgb1.green, (rgb2.blue - rgb1.blue ) * val + rgb1.blue);
23 | }
24 | }
}
--------------------------------------------------------------------------------
/src/com/bumpslide/events/DragEvent.as:
--------------------------------------------------------------------------------
1 | /**
2 | * This code is part of the Bumpslide Library maintained by David Knape
3 | * Fork me at http://github.com/tkdave/bumpslide_as3
4 | *
5 | * Copyright (c) 2010 by Bumpslide, Inc.
6 | * http://www.bumpslide.com/
7 | *
8 | * This code is released under the open-source MIT license.
9 | * See LICENSE.txt for full license terms.
10 | * More info at http://www.opensource.org/licenses/mit-license.php
11 | */
12 |
13 | package com.bumpslide.events {
14 | import flash.geom.Point;
15 | import flash.events.Event;
16 |
17 | /**
18 | * Drag Event dispatched by the Bumpslide DragBehavior
19 | *
20 | * @author David Knape
21 | */
22 | public class DragEvent extends Event {
23 |
24 | public static var EVENT_DRAG_START:String = "bumpslideDragStart";
public static var EVENT_DRAG_MOVE:String = "bumpslideDragMove";
public static var EVENT_DRAG_STOP:String = "bumpslideDragStop";
25 |
26 | // location of drag target when drag was started
public var start:Point;
27 |
28 | // current location of drag target relative to drag start
public var delta:Point;
29 |
30 | // current location of drag target
31 | public var current:Point;
32 |
33 | // distance dragged on this move
34 | public var velocity:Point;
35 |
36 | public function DragEvent(type:String, sprite_start:Point, current_loc:Point, drag_velocity:Point=null) {
37 | super(type, true, true);
38 | start = sprite_start;
39 | current = current_loc!=null ? current_loc : start.clone();
40 | delta = current.subtract( start );
41 | velocity = drag_velocity;
42 | }
43 |
44 |
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/src/com/bumpslide/events/ModelChangeEvent.as:
--------------------------------------------------------------------------------
1 | /**
2 | * This code is part of the Bumpslide Library maintained by David Knape
3 | * Fork me at http://github.com/tkdave/bumpslide_as3
4 | *
5 | * Copyright (c) 2010 by Bumpslide, Inc.
6 | * http://www.bumpslide.com/
7 | *
8 | * This code is released under the open-source MIT license.
9 | * See LICENSE.txt for full license terms.
10 | * More info at http://www.opensource.org/licenses/mit-license.php
11 | */
12 |
13 | package com.bumpslide.events {
import flash.events.Event;
/**
* Property Change Event for Bindable Models
*
* @author David Knape
*/
public class ModelChangeEvent extends Event {
public static const PROPERTY_CHANGED:String = "onPropertyChanged";
private var _source:Object;
private var _property:String;
private var _oldValue:*;
private var _newValue:*;
public function ModelChangeEvent( src:Object, prop:String, newVal:*, oldVal:*=null)
{
super(PROPERTY_CHANGED, bubbles, cancelable);
_source = src;
_property = prop;
_oldValue = oldVal;
_newValue = newVal;
//trace( this );
}
public function get source():Object
{
return _source;
}
public function set source( o:Object ):void
{
_source = o;
}
public function get property():String
{
return _property;
}
public function get oldValue():*
{
return _oldValue;
}
public function get newValue():*
{
return _newValue;
}
override public function toString () : String {
return '[ModelChangeEvent] '+property+'='+newValue;
}
override public function clone():Event
{
return new ModelChangeEvent( source, property, newValue, oldValue);
}
}
}
--------------------------------------------------------------------------------
/src/com/bumpslide/events/UIEvent.as:
--------------------------------------------------------------------------------
1 | /**
* This code is part of the Bumpslide Library maintained by David Knape
* Fork me at http://github.com/tkdave/bumpslide_as3
*
* Copyright (c) 2010 by Bumpslide, Inc.
* http://www.bumpslide.com/
*
* This code is released under the open-source MIT license.
* See LICENSE.txt for full license terms.
* More info at http://www.opensource.org/licenses/mit-license.php
*/
package com.bumpslide.events {
import flash.events.Event;
import flash.events.IEventDispatcher;
/**
* Generic Bubbling Event to be broadcast from UI Components
*
* - bubbles by default (to send from display objects)
* - contains generic data object
* - unlike a cairngorm event, there is no central dispatcher
* (helps us keep views components decoupled form underlying framework)
*
* @author David Knape
*/
public class UIEvent extends Event {
static public var debug:Boolean = false;
public var data:*;
public function UIEvent(type:String, data:Object=null ) {
super(type, true);
if(debug && type!='onComponentRedraw') trace('[UIEvent] "'+type+'" ('+data+')');
this.data = data;
}
override public function clone():Event {
return new UIEvent( type, data );
}
// Send Bubbling UIEvent
static public function send( dispatcher:IEventDispatcher, type:String, data:Object=null ) : void {
dispatcher.dispatchEvent( new UIEvent( type, data) );
}
override public function toString() : String {
return '[UIEvent] "' + type + '" data=' + data;
}
}
}
--------------------------------------------------------------------------------
/src/com/bumpslide/events/ViewChangeEvent.as:
--------------------------------------------------------------------------------
1 | /**
2 | * This code is part of the Bumpslide Library maintained by David Knape
3 | * Fork me at http://github.com/tkdave/bumpslide_as3
4 | *
5 | * Copyright (c) 2010 by Bumpslide, Inc.
6 | * http://www.bumpslide.com/
7 | *
8 | * This code is released under the open-source MIT license.
9 | * See LICENSE.txt for full license terms.
10 | * More info at http://www.opensource.org/licenses/mit-license.php
11 | */
12 |
13 | package com.bumpslide.events {
14 | import flash.events.Event;
15 |
16 | /**
17 | * Transtion In/Out Events
18 | *
19 | * Note: These should not be bubbled if you want ot support hiearchical views
20 | *
21 | * @author David Knape
22 | */
23 | public class ViewChangeEvent extends Event {
24 |
25 | public static const TRANSITION_OUT:String = "transitionOut";
26 | public static const TRANSITION_IN:String = "transitionIn";
27 |
28 | public static const TRANSITION_OUT_COMPLETE:String = "transitionOutComplete";
29 | public static const TRANSITION_IN_COMPLETE:String = "transitionInComplete";
30 |
31 | public function ViewChangeEvent(type:String, bubbles:Boolean = false, cancelable:Boolean = false) {
32 | super(type, bubbles, cancelable);
33 | }
34 |
35 | override public function clone():Event {
36 | return new ViewChangeEvent( type, bubbles, cancelable );
37 | }
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/com/bumpslide/net/BrowseSelectRequest.as:
--------------------------------------------------------------------------------
1 | package com.bumpslide.net
2 | {
3 |
4 | import flash.events.Event;
5 | import flash.net.FileReference;
6 |
7 |
8 | /**
9 | * Wraps a File Browse operation
10 | *
11 | * @author David Knape
12 | */
13 | public class BrowseSelectRequest extends AbstractRequest
14 | {
15 |
16 | public var fileReference:FileReference;
17 | public var typeFilter:Array;
18 |
19 | public function BrowseSelectRequest( file_reference:FileReference, type_filter:Array = null, responder:IResponder = null )
20 | {
21 | super( responder);
22 | fileReference = file_reference;
23 | typeFilter = type_filter;
24 | retryCount = 1;
25 | }
26 |
27 |
28 | override protected function initRequest():void
29 | {
30 | fileReference.addEventListener( Event.SELECT, handleSelect );
31 | fileReference.addEventListener( Event.CANCEL, handleCancel );
32 | fileReference.browse( typeFilter );
33 | }
34 |
35 |
36 | private function handleCancel( event:Event ):void
37 | {
38 | cancel();
39 | }
40 |
41 |
42 | private function handleSelect( event:Event ):void
43 | {
44 | finishCompletedRequest( fileReference );
45 | }
46 |
47 | override protected function killRequest():void
48 | {
49 | fileReference.removeEventListener( Event.CANCEL, handleCancel );
50 | try { fileReference.cancel(); } catch (e:Error) {}
51 | }
52 |
53 |
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/src/com/bumpslide/net/FileRequest.as:
--------------------------------------------------------------------------------
1 | /**
2 | * This code is part of the Bumpslide Library maintained by David Knape
3 | * Fork me at http://github.com/tkdave/bumpslide_as3
4 | *
5 | * Copyright (c) 2010 by Bumpslide, Inc.
6 | * http://www.bumpslide.com/
7 | *
8 | * This code is released under the open-source MIT license.
9 | * See LICENSE.txt for full license terms.
10 | * More info at http://www.opensource.org/licenses/mit-license.php
11 | */
12 |
13 | package com.bumpslide.net {
14 |
15 | import flash.errors.IOError;
16 | import flash.events.Event;
17 | import flash.events.IOErrorEvent;
18 | import flash.filesystem.File;
19 | import flash.filesystem.FileMode;
20 | import flash.filesystem.FileStream;
21 | import flash.utils.ByteArray;
22 |
23 | /**
24 | * Reads raw bytes from the file system in an AIR application
25 | *
26 | * @author David Knape
27 | */
28 | public class FileRequest extends AbstractRequest {
29 |
30 | public var file:File;
31 | private var _stream:FileStream;
32 |
33 | public function FileRequest(file:File, responder:IResponder = null) {
34 | this.file = file;
35 | super(responder);
36 | }
37 |
38 | override protected function initRequest() : void {
39 | _stream = new FileStream();
40 | debug('Opening File Stream ' + file );
41 | _stream.addEventListener(Event.COMPLETE, handleFileReadComplete);
42 | _stream.addEventListener(IOErrorEvent.IO_ERROR, handleIOError);
43 | _stream.openAsync(file, FileMode.READ);
44 | }
45 |
46 | override protected function killRequest() : void {
47 | _stream.removeEventListener(Event.COMPLETE, handleFileReadComplete);
48 | _stream.removeEventListener(IOErrorEvent.IO_ERROR, handleIOError);
49 | try {
50 | debug('Closing File Stream ' + file );
51 | _stream.close();
52 | } catch (error:Error) {
53 | }
54 | }
55 |
56 | protected function handleFileReadComplete(event:Event) : void {
57 | debug('File Read Complete ('+ _stream.bytesAvailable+' bytes available)');
58 | var bytes:ByteArray = new ByteArray();
59 | _stream.readBytes(bytes, 0, _stream.bytesAvailable);
60 | finishCompletedRequest(bytes);
61 | }
62 |
63 | protected function handleIOError(event:IOErrorEvent) : void {
64 | debug('IOError opening file ' + file );
65 | raiseError(new IOError(event.text));
66 | }
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/src/com/bumpslide/net/IRequest.as:
--------------------------------------------------------------------------------
1 | /**
2 | * This code is part of the Bumpslide Library maintained by David Knape
3 | * Fork me at http://github.com/tkdave/bumpslide_as3
4 | *
5 | * Copyright (c) 2010 by Bumpslide, Inc.
6 | * http://www.bumpslide.com/
7 | *
8 | * This code is released under the open-source MIT license.
9 | * See LICENSE.txt for full license terms.
10 | * More info at http://www.opensource.org/licenses/mit-license.php
11 | */
12 |
13 | package com.bumpslide.net {
14 |
15 | /**
16 | * Interface for asynchronous commands such as web API calls and requests for assets
17 | *
18 | * All methods are chainable
19 | *
20 | * @author David Knape
21 | */
22 | public interface IRequest {
23 |
24 | /**
25 | * Load the request
26 | */
27 | function load():IRequest;
28 |
29 | /**
30 | * Cancel the request
31 | */
32 | function cancel():IRequest;
33 |
34 | /**
35 | * Cancel and reset so request can be reused. Optionally remove all responders.
36 | */
37 | function reset( remove_responders:Boolean = false ):IRequest;
38 |
39 | /**
40 | * Add responder with result and fault handlers
41 | */
42 | function addResponder( responder:IResponder ):IRequest;
43 |
44 | /**
45 | * Remove responder
46 | */
47 | function removeResponder( responder:IResponder ):IRequest;
48 |
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/src/com/bumpslide/net/IResponder.as:
--------------------------------------------------------------------------------
1 | /**
2 | * This code is part of the Bumpslide Library maintained by David Knape
3 | * Fork me at http://github.com/tkdave/bumpslide_as3
4 | *
5 | * Copyright (c) 2010 by Bumpslide, Inc.
6 | * http://www.bumpslide.com/
7 | *
8 | * This code is released under the open-source MIT license.
9 | * See LICENSE.txt for full license terms.
10 | * More info at http://www.opensource.org/licenses/mit-license.php
11 | */
12 |
13 | package com.bumpslide.net {
14 |
/**
15 | * Like the mx.rpc.responder interface
16 | *
17 | * Represents a pair of callback functions (result and fault) used to
18 | * handle the results and/or errors coming from asynchronous calls
19 | *
20 | * @author David Knape
21 | */
22 | public interface IResponder {
23 | function fault(info : Error) : void;
24 | function result(data : Object) : void;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/com/bumpslide/net/JSONRequest.as:
--------------------------------------------------------------------------------
1 | /**
2 | * This code is part of the Bumpslide Library maintained by David Knape
3 | * Fork me at http://github.com/tkdave/bumpslide_as3
4 | *
5 | * Copyright (c) 2010 by Bumpslide, Inc.
6 | * http://www.bumpslide.com/
7 | *
8 | * This code is released under the open-source MIT license.
9 | * See LICENSE.txt for full license terms.
10 | * More info at http://www.opensource.org/licenses/mit-license.php
11 | */
12 |
13 | package com.bumpslide.net {
14 | import com.adobe.serialization.json.JSON;
15 | import com.bumpslide.net.HTTPRequest;
16 |
17 | import flash.net.URLRequest;
18 |
19 | /**
20 | * JSON Request - requires adobe corelib JSON decoder
21 | *
22 | * @author David Knape
23 | */
24 | public class JSONRequest extends HTTPRequest {
25 |
26 | public function JSONRequest(request:URLRequest, responder:IResponder = null) {
27 | super(request, responder);
28 | }
29 |
30 | override protected function getResult():* {
31 | return com.adobe.serialization.json.JSON.decode(data, false);
32 | }
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/com/bumpslide/net/LoaderRequest.as:
--------------------------------------------------------------------------------
1 | /**
2 | * This code is part of the Bumpslide Library maintained by David Knape
3 | * Fork me at http://github.com/tkdave/bumpslide_as3
4 | *
5 | * Copyright (c) 2010 by Bumpslide, Inc.
6 | * http://www.bumpslide.com/
7 | *
8 | * This code is released under the open-source MIT license.
9 | * See LICENSE.txt for full license terms.
10 | * More info at http://www.opensource.org/licenses/mit-license.php
11 | */
12 |
13 | package com.bumpslide.net
14 | {
15 | import flash.display.Loader;
16 | import flash.events.Event;
17 | import flash.net.URLRequest;
18 | import flash.system.LoaderContext;
19 |
20 | /**
21 | * IRequest implementation for Loaders
22 | *
23 | * No more need for LoaderQueue. Just use RequestQueue.
24 | *
25 | * This extends HTTPRequest so we can re-use the event listeners, but we are
26 | * loading with a Loader instead of a URLLoader
27 | *
28 | * @author David Knape
29 | */
30 | public class LoaderRequest extends HTTPRequest implements IRequest
31 | {
32 |
33 | protected var _loader:Loader;
34 | protected var _loaderContext:LoaderContext;
35 |
36 |
37 | public function LoaderRequest(loader:Loader, content_url:String, loader_context:LoaderContext=null, responder:IResponder = null)
38 | {
39 | _loader = loader;
40 | _loaderContext = loader_context;
41 | super(new URLRequest(content_url), responder);
42 | }
43 |
44 |
45 | /**
46 | * Cancel pending request and unload image
47 | *
48 | * (alias for cancel)
49 | */
50 | public function unload():void
51 | {
52 | if(complete) doUnloadContent();
53 | else cancel();
54 | }
55 |
56 |
57 | /**
58 | * Cancel pending request and unload image
59 | */
60 | override public function cancel():IRequest
61 | {
62 | super.cancel();
63 | if(cancelled) doUnloadContent();
64 | return this;
65 | }
66 |
67 |
68 | protected function doUnloadContent():void
69 | {
70 | // unload
71 | try {
72 | loader.unload(); /* trace('unloaded');*/
73 | } catch ( error1:Error ) {
74 | }
75 | try {
76 | // in case content is a swf, and we have FP10, unload and stop to be safe
77 | if(loader['unloadAndStop'] is Function) {
78 | (loader['unloadAndStop'] as Function).call(loader);
79 | }
80 | } catch (error2:Error) {
81 | }
82 | }
83 |
84 |
85 | /**
86 | * starts listening to LoaderInfo events, and starts the load
87 | */
88 | override protected function initRequest():void
89 | {
90 | debug('loading ' + urlRequest.url);
91 | addLoaderEventListeners(loader.contentLoaderInfo);
92 | loader.load(urlRequest, loaderContext);
93 | }
94 |
95 |
96 | /**
97 | * closes the Loader and stops listening to LoaderInfo events
98 | *
99 | * does not unload the content
100 | */
101 | override protected function killRequest():void
102 | {
103 | removeLoaderEventListeners(loader.contentLoaderInfo);
104 | try {
105 | loader.close();
106 | } catch ( e:Error ) {
107 | }
108 | }
109 |
110 |
111 | override protected function handleCompleteEvent(event:Event):void
112 | {
113 | finishCompletedRequest( loader.content );
114 | }
115 |
116 |
117 | public function get loader():Loader {
118 | return _loader;
119 | }
120 |
121 |
122 | public function get loaderContext():LoaderContext {
123 | return _loaderContext;
124 | }
125 |
126 |
127 | override protected function getResult():* {
128 | return loader;
129 | }
130 |
131 |
132 |
133 | }
134 | }
135 |
--------------------------------------------------------------------------------
/src/com/bumpslide/net/RequestPoller.as:
--------------------------------------------------------------------------------
1 | package com.bumpslide.net
2 | {
3 |
4 | import com.bumpslide.data.Callback;
5 | import flash.events.TimerEvent;
6 | import flash.utils.Timer;
7 |
8 |
9 | /**
10 | * Make a request repeatedly and provide conditions for an exit
11 | *
12 | * @author David Knape, http://bumpslide.com/
13 | */
14 | public class RequestPoller extends AbstractRequest
15 | {
16 | public static const DEFAULT_POLL_INTERVAL:uint = 5000;
17 |
18 | private var pollInterval:uint = DEFAULT_POLL_INTERVAL;
19 | private var request:IRequest;
20 | private var timer:Timer;
21 | private var stopWhen:Function;
22 | private var responder:Callback;
23 |
24 | public function RequestPoller( the_request:IRequest, poll_interval:uint = DEFAULT_POLL_INTERVAL, stop_when:Function = null, responder:IResponder = null )
25 | {
26 |
27 |
28 | debugEnabled = true;
29 |
30 | debug('created');
31 | request = the_request;
32 | pollInterval = poll_interval;
33 | stopWhen = stop_when==null ? NeverStop : stop_when;
34 |
35 | super( responder );
36 |
37 | if (the_request == null) {
38 | throw new Error( 'Request cannot be null' );
39 | }
40 | }
41 |
42 |
43 | static public function NeverStop( result:Object ):Boolean
44 | {
45 | return false;
46 | }
47 |
48 |
49 | override protected function initRequest():void
50 | {
51 | debug('initRequest()');
52 |
53 | killRequest();
54 |
55 | responder = new Callback( handleRequestResult, handleRequestError );
56 |
57 | request.reset(true);
58 | request.addResponder( responder );
59 |
60 | timer = new Timer( pollInterval, 0 );
61 | timer.addEventListener( TimerEvent.TIMER, doRequest );
62 | timer.start();
63 | }
64 |
65 |
66 | override protected function killRequest():void
67 | {
68 | if(timer) {
69 | timer.stop();
70 | timer.removeEventListener( TimerEvent.TIMER, doRequest );
71 | timer = null;
72 | }
73 |
74 | if(request && responder) {
75 | request.removeResponder( responder );
76 | }
77 | }
78 |
79 |
80 | private function doRequest( event:TimerEvent ):void
81 | {
82 | debug('reloading service');
83 | request.load();
84 | }
85 |
86 |
87 | override public function cancel():IRequest
88 | {
89 | request.cancel();
90 | return super.cancel();
91 | }
92 |
93 |
94 | public function handleRequestError( info:Error ):void
95 | {
96 | raiseError( info );
97 | }
98 |
99 | public function handleRequestResult( data:Object ):void
100 | {
101 | debug('poll result:'+data);
102 |
103 | if (stopWhen.call( null, data )) {
104 |
105 | debug('all done');
106 | finishCompletedRequest( data )
107 |
108 | } else {
109 |
110 | }
111 | }
112 | }
113 | }
114 |
--------------------------------------------------------------------------------
/src/com/bumpslide/net/RequestQueue.as:
--------------------------------------------------------------------------------
1 | /**
2 | * This code is part of the Bumpslide Library maintained by David Knape
3 | * Fork me at http://github.com/tkdave/bumpslide_as3
4 | *
5 | * Copyright (c) 2010 by Bumpslide, Inc.
6 | * http://www.bumpslide.com/
7 | *
8 | * This code is released under the open-source MIT license.
9 | * See LICENSE.txt for full license terms.
10 | * More info at http://www.opensource.org/licenses/mit-license.php
11 | */
12 |
13 | package com.bumpslide.net
{
import com.bumpslide.data.Action;
import com.bumpslide.data.ActionQueue;
import com.bumpslide.data.Callback;
import com.bumpslide.util.Delegate;
import com.bumpslide.util.StringUtil;
import flash.events.Event;
import flash.events.EventDispatcher;
import flash.utils.Dictionary;
14 |
[Event(name="complete", type="flash.events.Event")]
/**
* Prioritized and 'multi-threaded' loading queue for RPC requests
*
* Built on top of the ActionQueue.
*
* @author David Knape
*/
public class RequestQueue extends EventDispatcher
{
// the queue
protected var _actionQueue:ActionQueue;
// actions indexed by request
protected var _actions:Dictionary;
// trace log?
public var debugEnabled:Boolean = false;
public function RequestQueue(threadCount:uint = 1)
{
_actionQueue = new ActionQueue();
_actionQueue.threads = threadCount;
_actions = new Dictionary(true);
// Note to self:
// We can't just listen for queue complete, beacause actionqueue is
// not aware of asynchronous nature of our actions
// Thus, we can't do this...
// _actionQueue.addEventListener(Event.COMPLETE, function(event:Event):void {
// dispatchEvent( event );
// } );
}
public function clear():void
{
var req:IRequest;
for( var o:Object in _actions) {
req = (o as IRequest);
req.cancel();
remove(req);
}
_actionQueue.clear();
}
public function load( req:IRequest, priority:Number = 1 ):void
{
// remove existing
if(_actions[req]) remove(req);
debug('load() - enqueuing ' + req);
15 | // create action
16 | var a:Action = new Action( req.load, priority, String(req));
req.addResponder(new Callback(Delegate.create(handleResult, req), Delegate.create(handleError, req)));
// save reference to action so it can be cancelled using the req as a key
_actions[req] = a;
_actionQueue.enqueue(a);
}
protected function handleError( info:Object, req:IRequest ):void
{
debug('handleError() ' + String(req) + String(info));
remove(req);
}
protected function handleResult(result:Object, req:IRequest):void
{
debug('handleResult() ' + req + StringUtil.abbreviate(String(result), 20));
remove(req);
}
protected function remove( req:IRequest ):void
{
if(req == null) return;
var a:Action = _actions[req];
_actionQueue.remove(a);
delete _actions[req];
if(actionQueue.currentActions.length==0 && actionQueue.size==0) {
// dispatch complete event if there are no more actions running
debug('Queue complete');
dispatchEvent( new Event(Event.COMPLETE) );
}
}
public function get threads():uint {
return _actionQueue.threads;
}
public function set threads(threads:uint):void {
_actionQueue.threads = threads;
}
public function get size():uint {
return _actionQueue.size;
}
protected function debug( s:* ):void
{
if(debugEnabled) trace('[RequestQueue] ' + s);
}
public function get actionQueue():ActionQueue {
return _actionQueue;
}
}
}
--------------------------------------------------------------------------------
/src/com/bumpslide/net/SocketConnection.as:
--------------------------------------------------------------------------------
1 | /**
2 | * This code is part of the Bumpslide Library maintained by David Knape
3 | * Fork me at http://github.com/tkdave/bumpslide_as3
4 | *
5 | * Copyright (c) 2010 by Bumpslide, Inc.
6 | * http://www.bumpslide.com/
7 | *
8 | * This code is released under the open-source MIT license.
9 | * See LICENSE.txt for full license terms.
10 | * More info at http://www.opensource.org/licenses/mit-license.php
11 | */
12 |
13 | package com.bumpslide.net {
14 | import com.bumpslide.util.Delegate;
15 |
16 | import flash.events.DataEvent;
17 | import flash.events.Event;
18 | import flash.events.EventDispatcher;
19 | import flash.events.IOErrorEvent;
20 | import flash.net.XMLSocket;
21 | import flash.utils.Timer;
22 |
23 | /**
24 | * Persistent XML/Data Socket Connection
25 | *
26 | * - if connection drops, it will keep trying to reconnect
27 | * - nice for kiosks and things of that sort
28 | *
29 | * @author David Knape
30 | */
31 | public class SocketConnection extends EventDispatcher {
32 |
33 | private var _port:uint;
34 | private var _host:String;
35 | private var _socket:XMLSocket;
36 |
37 | private var updateDelay:Timer;
38 | private var retryTimer:Timer;
39 |
40 | public function SocketConnection() {
41 | super();
42 | }
43 |
44 | public function reset() : void {
45 | if(_socket!=null && _socket.connected) {
46 | if(_socket.connected) _socket.close();
47 | _socket.removeEventListener(Event.CONNECT, onConnect);
48 | _socket.removeEventListener(Event.CLOSE, onClose);
49 | _socket.removeEventListener(DataEvent.DATA, onData);
50 | _socket.removeEventListener(IOErrorEvent.IO_ERROR, onError);
51 | }
52 |
53 | trace('[XMLSocket] Connecting to '+_host+' port '+_port +' ... ');
54 | _socket = new XMLSocket(_host, _port);
55 | _socket.addEventListener(Event.CONNECT, onConnect);
56 | _socket.addEventListener(Event.CLOSE, onClose);
57 | _socket.addEventListener(DataEvent.DATA, onData);
58 | _socket.addEventListener(IOErrorEvent.IO_ERROR, onError);
59 | }
60 |
61 | /**
62 | * Retry to connect after waiting for 5 seconds
63 | */
64 | private function retryConnection() :void {
65 | Delegate.cancel( retryTimer );
66 | retryTimer = Delegate.callLater( 5000, reset );
67 | }
68 |
69 | private function onError(event:IOErrorEvent):void {
70 | trace('[XMLSocket] Error="'+event.text+'"' );
71 | retryConnection();
72 | }
73 |
74 | private function onData(event:DataEvent):void {
75 | //trace('[XMLSocket] Data="'+event.data+'"' );
76 | var e:DataEvent = event.clone() as DataEvent;
77 | dispatchEvent( e );
78 | }
79 |
80 | private function onClose(event:Event):void {
81 | trace('[XMLSocket] Connection Closed.');
82 | retryConnection();
83 | }
84 |
85 | private function onConnect(event:Event):void {
86 | trace('[XMLSocket] Socket Connected.');
87 | //_socket.send("Hello");
88 | }
89 |
90 | public function send(data:*):void {
91 | _socket.send( data );
92 | }
93 |
94 |
95 | public function get host():String {
96 | return _host;
97 | }
98 |
99 | public function set host(s_host:String):void {
100 | _host = s_host;
101 | invalidate();
102 | }
103 |
104 | public function get port():uint {
105 | return _port;
106 | }
107 |
108 | public function set port(n_port:uint):void {
109 | _port = n_port;
110 | invalidate();
111 | }
112 |
113 | private function invalidate():void {
114 | Delegate.cancel(updateDelay);
115 | updateDelay = Delegate.callLater(100, reset);
116 | }
117 | }
118 | }
119 |
120 | class SingletonEnforcer {}
--------------------------------------------------------------------------------
/src/com/bumpslide/net/XMLRequest.as:
--------------------------------------------------------------------------------
1 | /**
2 | * This code is part of the Bumpslide Library maintained by David Knape
3 | * Fork me at http://github.com/tkdave/bumpslide_as3
4 | *
5 | * Copyright (c) 2010 by Bumpslide, Inc.
6 | * http://www.bumpslide.com/
7 | *
8 | * This code is released under the open-source MIT license.
9 | * See LICENSE.txt for full license terms.
10 | * More info at http://www.opensource.org/licenses/mit-license.php
11 | */
12 |
13 | package com.bumpslide.net {
14 | import flash.net.URLRequest;
15 |
16 | import com.bumpslide.net.HTTPRequest;
17 |
18 | /**
19 | * Basic XML request, returns result as XML object
20 | *
21 | * @author David Knape
22 | */
23 | public class XMLRequest extends HTTPRequest {
24 |
25 | public function XMLRequest(request:URLRequest, responder:IResponder = null) {
26 | super(request, responder);
27 | }
28 |
29 | override protected function getResult():* {
30 | XML.ignoreWhitespace=true;
31 | try {
32 | return new XML( data );
33 | } catch (e:Error) {
34 | raiseError( e );
35 | }
36 | return null;
37 | }
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/com/bumpslide/net/cache/CachedFile.as:
--------------------------------------------------------------------------------
1 | /**
2 | * This code is part of the Bumpslide Library maintained by David Knape
3 | * Fork me at http://github.com/tkdave/bumpslide_as3
4 | *
5 | * Copyright (c) 2010 by Bumpslide, Inc.
6 | * http://www.bumpslide.com/
7 | *
8 | * This code is released under the open-source MIT license.
9 | * See LICENSE.txt for full license terms.
10 | * More info at http://www.opensource.org/licenses/mit-license.php
11 | */
12 | package com.bumpslide.net.cache
13 | {
14 |
15 | import flash.filesystem.File;
16 |
17 | /**
18 | * Reference to a cached file
19 | *
20 | * @author David Knape
21 | */
22 | public class CachedFile implements ICachedItem
23 | {
24 |
25 | public var file:File;
26 |
27 | public var expireTime:Number = 0;
28 |
29 | public function CachedFile( f:File, expires:Number = 0 )
30 | {
31 | file = f;
32 | expireTime = expires;
33 | }
34 |
35 |
36 | public function get isExpired():Boolean {
37 | var t:Number = new Date().time;
38 | return expireTime != 0 && t >= expireTime;
39 | }
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/src/com/bumpslide/net/cache/ICache.as:
--------------------------------------------------------------------------------
1 | /**
2 | * This code is part of the Bumpslide Library maintained by David Knape
3 | * Fork me at http://github.com/tkdave/bumpslide_as3
4 | *
5 | * Copyright (c) 2010 by Bumpslide, Inc.
6 | * http://www.bumpslide.com/
7 | *
8 | * This code is released under the open-source MIT license.
9 | * See LICENSE.txt for full license terms.
10 | * More info at http://www.opensource.org/licenses/mit-license.php
11 | */
12 |
13 | package com.bumpslide.net.cache {
14 |
15 | import flash.utils.ByteArray;
16 |
17 | /**
18 | * ICache
19 | *
20 | * @author David Knape
21 | */
22 | public interface ICache {
23 |
24 | /**
25 | * Saves data in the cache
26 | *
27 | * @param key - unique key name
28 | * @param data - ByteArray of data to save
29 | * @param expireTime - AS3 timestamp (milliseconds since Jan 1, 1970)
30 | */
31 | function store(key:String, data:ByteArray, expireTime:Number = 0):ICachedItem;
32 |
33 | /**
34 | * Retrieves most recent version from cache and deletes any old copies in the process
35 | *
36 | * @param key - unique key name
37 | */
38 | function retrieve(key:String):ICachedItem;
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/com/bumpslide/net/cache/ICachedItem.as:
--------------------------------------------------------------------------------
1 | /**
2 | * This code is part of the Bumpslide Library maintained by David Knape
3 | * Fork me at http://github.com/tkdave/bumpslide_as3
4 | *
5 | * Copyright (c) 2010 by Bumpslide, Inc.
6 | * http://www.bumpslide.com/
7 | *
8 | * This code is released under the open-source MIT license.
9 | * See LICENSE.txt for full license terms.
10 | * More info at http://www.opensource.org/licenses/mit-license.php
11 | */
12 |
13 | package com.bumpslide.net.cache {
14 | /**
15 | * ICachedItem
16 | *
17 | * @author David Knape
18 | */
19 | public interface ICachedItem {
20 |
21 | function get isExpired():Boolean;
22 |
23 |
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/com/bumpslide/net/deprecated/ServiceEvent.as:
--------------------------------------------------------------------------------
1 | /**
2 | * This code is part of the Bumpslide Library maintained by David Knape
3 | * Fork me at http://github.com/tkdave/bumpslide_as3
4 | *
5 | * Copyright (c) 2010 by Bumpslide, Inc.
6 | * http://www.bumpslide.com/
7 | *
8 | * This code is released under the open-source MIT license.
9 | * See LICENSE.txt for full license terms.
10 | * More info at http://www.opensource.org/licenses/mit-license.php
11 | */
12 |
13 | package com.bumpslide.net.deprecated
14 | {
15 | import flash.events.Event;
16 |
17 | /**
18 | * Custom Event for service results
19 | *
20 | * @author David Knape
21 | */
22 | public class ServiceEvent extends Event
23 | {
24 |
25 | private var _params:Array;
26 | private var _result:Object;
27 |
28 | public function ServiceEvent( type:String, service_result:Object=null, input_params:Array=null ) {
29 | super(type, false, false);
30 | _params = input_params==null ? new Array() : input_params;
31 | _result = service_result==null ? new Object() : service_result;
32 | }
33 |
34 | /**
35 | * This object contains data loaded in response
36 | * to remote service calls
37 | */
38 | public function get result():Object
39 | {
40 | return _result;
41 | }
42 |
43 | /**
44 | * This is an array of parameters that were sent as
45 | * input to the remote service (optional)
46 | */
47 | public function get params():Array
48 | {
49 | return _params;
50 | }
51 |
52 | override public function toString() : String {
53 | return '[ServiceEvent:'+this.type+'] ';
54 | }
55 | }
56 | }
--------------------------------------------------------------------------------
/src/com/bumpslide/net/deprecated/URLEvent.as:
--------------------------------------------------------------------------------
1 | /**
2 | * This code is part of the Bumpslide Library maintained by David Knape
3 | * Fork me at http://github.com/tkdave/bumpslide_as3
4 | *
5 | * Copyright (c) 2010 by Bumpslide, Inc.
6 | * http://www.bumpslide.com/
7 | *
8 | * This code is released under the open-source MIT license.
9 | * See LICENSE.txt for full license terms.
10 | * More info at http://www.opensource.org/licenses/mit-license.php
11 | */
12 |
13 | package com.bumpslide.net.deprecated {
import flash.events.Event;
/**
* Events fired from URLLoaderQueue
*
* @author David Knape
*/
public class URLEvent extends Event {
static public const ERROR:String = "urlError";
static public const PROGRESS:String = "urlProgress";
static public const COMPLETE:String = "urlComplete";
private var _result:String;
private var _message:String;
private var _url:String;
private var _data:*;
private var _percentLoaded:*;
public function URLEvent(type:String, url:String, result:String="", data:*=null, message:String="", percentLoaded:Number=1)
{
super(type, false, false);
_url = url;
_result = result;
_data = data;
_message = message;
_percentLoaded = percentLoaded;
}
// requested url
public function get url():String
{
return _url;
}
// http result
public function get result ():String
{
return _result;
}
// app-specific data
public function get data ():String
{
return _data;
}
// Error Message
public function get message ():String
{
return _message;
}
public function get percentLoaded() : Number {
return _percentLoaded;
}
}
}
--------------------------------------------------------------------------------
/src/com/bumpslide/net/deprecated/URLLoadRequest.as:
--------------------------------------------------------------------------------
1 | /**
2 | * This code is part of the Bumpslide Library maintained by David Knape
3 | * Fork me at http://github.com/tkdave/bumpslide_as3
4 | *
5 | * Copyright (c) 2010 by Bumpslide, Inc.
6 | * http://www.bumpslide.com/
7 | *
8 | * This code is released under the open-source MIT license.
9 | * See LICENSE.txt for full license terms.
10 | * More info at http://www.opensource.org/licenses/mit-license.php
11 | */
12 |
13 | package com.bumpslide.net.deprecated {
import flash.net.URLLoader;
import flash.net.URLRequest;
/**
* Encapsulates a UrlLoader along with data and callback info for use with URLLoaderQueue
*
* @author David Knape
*/
public class URLLoadRequest extends Object {
private var _urlLoader:URLLoader;
private var _urlRequest:URLRequest;
private var _callback:Function;
private var _data:*;
private var _id:String;
public var httpStatus:int;
function URLLoadRequest( url_loader:URLLoader, url_request:URLRequest, callback_func:Function=null, misc_data:*=null, unique_id:String=null ) {
_urlLoader = url_loader;
_urlRequest = url_request;
_callback = callback_func;
_data = misc_data;
// use URL as default id string
_id = (unique_id==null) ? urlRequest.url.split('/').pop() : unique_id;
}
// read-only access to properties...
//-------------------------------------
public function get urlLoader () : URLLoader { return _urlLoader; }
public function get urlRequest () : URLRequest { return _urlRequest; }
public function get callback () : Function { return _callback; }
public function get data () : * { return _data; }
public function get id () : String { return _id; }
public function get url () : String { return _urlRequest.url; }
public function load() : void {
urlLoader.load( urlRequest );
}
public function cancel() : void {
try { urlLoader.close(); } catch (e:Error) {}
}
public function get percentLoaded () : Number {
return urlLoader.bytesLoaded / urlLoader.bytesTotal;
}
public function toString() : String {
return '[URLLoadRequest: '+id+']';
}
}
}
--------------------------------------------------------------------------------
/src/com/bumpslide/preloader/PreloadEvent.as:
--------------------------------------------------------------------------------
1 | /**
2 | * This code is part of the Bumpslide Library maintained by David Knape
3 | * Fork me at http://github.com/tkdave/bumpslide_as3
4 | *
5 | * Copyright (c) 2010 by Bumpslide, Inc.
6 | * http://www.bumpslide.com/
7 | *
8 | * This code is released under the open-source MIT license.
9 | * See LICENSE.txt for full license terms.
10 | * More info at http://www.opensource.org/licenses/mit-license.php
11 | */
12 |
13 | package com.bumpslide.preloader {
14 | import flash.events.Event;
15 |
/**
16 | * Events to be dispatched by the main app for communicating with the preloader
17 | *
18 | * @author David Knape
19 | */
20 | public class PreloadEvent extends Event {
21 |
22 | // if preloader was instructed to waitForStartup, this is the event it's waiting for
public static const STARTUP_COMPLETE:String = "preloadStartupComplete";
23 |
24 | // tells preloader to display a text message
public static const MESSAGE:String = "preloadMessage";
25 |
26 |
27 | // the message (for use with PreloadEvent.MESSAGE)
public var messageText:String = "";
28 |
29 |
30 |
31 | public function PreloadEvent(type:String, message_text:String = "") {
32 | super(type, true, false);
33 | messageText = message_text;
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/com/bumpslide/preloader/ProgressBar.as:
--------------------------------------------------------------------------------
1 | /**
2 | * This code is part of the Bumpslide Library maintained by David Knape
3 | * Fork me at http://github.com/tkdave/bumpslide_as3
4 | *
5 | * Copyright (c) 2010 by Bumpslide, Inc.
6 | * http://www.bumpslide.com/
7 | *
8 | * This code is released under the open-source MIT license.
9 | * See LICENSE.txt for full license terms.
10 | * More info at http://www.opensource.org/licenses/mit-license.php
11 | */
12 |
13 | package com.bumpslide.preloader
{
import flash.display.*;
import flash.text.*;
import flash.utils.getTimer;
/**
* ProgressBar for Preloader
*
* @author David Knape
*/
public class ProgressBar extends MovieClip {
14 |
// timeline movieclips
public var display_txt:TextField;
public var bar_mc:MovieClip;
public var border:MovieClip;
public var background:MovieClip;
15 |
// properties
protected var _start:int;
protected var _delay:int = 750;
protected var _offset:Number = 0;
protected var _fullwidth:Number = 176;
16 |
public function ProgressBar() {
stop();
init();
reset();
}
protected function init():void {
display_txt.autoSize = TextFieldAutoSize.LEFT;
}
public function reset():void {
visible = false;
_start = getTimer();
_offset = 0;
if(background) {
_fullwidth = background.width - ( bar_mc.x - background.x ) * 2;
}
if(bar_mc) bar_mc.width = 0;
setText('');
}
17 |
public function setDelay(d:Number):void {
_delay = d;
}
18 |
public function setPercent( pct:Number ):void {
// make sure percent is a float
if(pct > 1) pct /= 100;
// validate
if(pct < 0) return;
// wait for delay before displaying
if((getTimer() - _start) < _delay) {
return;
}
if(!visible) {
_offset = pct;
visible = true;
}
pct = (pct - _offset) / (1 - _offset);
updateDisplay(pct);
}
19 |
protected function updateDisplay(pct:Number):void {
//setText('Loading... ' + Math.round( pct * 100 ) + '%' );
if(bar_mc) bar_mc.width = Math.round(_fullwidth * pct);
}
20 |
public function setText(s:String):void {
if((getTimer() - _start) > _delay && !visible) {
visible = true;
}
if(display_txt) display_txt.text = s;
}
21 |
public function hide():void {
visible = false;
}
}
}
--------------------------------------------------------------------------------
/src/com/bumpslide/tween/FTweenOptions.as:
--------------------------------------------------------------------------------
1 | /**
2 | * This code is part of the Bumpslide Library maintained by David Knape
3 | * Fork me at http://github.com/tkdave/bumpslide_as3
4 | *
5 | * Copyright (c) 2010 by Bumpslide, Inc.
6 | * http://www.bumpslide.com/
7 | *
8 | * This code is released under the open-source MIT license.
9 | * See LICENSE.txt for full license terms.
10 | * More info at http://www.opensource.org/licenses/mit-license.php
11 | */
12 |
13 | package com.bumpslide.tween {
/**
* These are the FTween options
*
* @author David Knape
*/
public class FTweenOptions {
// default values
// how close we need to get to the target before we stop
public var minDelta:Number = .01;
// how slow we must be going before we stop (when springing)
public var minVelocity:Number = .01;
14 |
15 | // maximum speed regardless of tween equation
16 | public var maxVelocity:Number = 0;
// whether or not to check velocity
// (calling FTween.spring automatically sets this to false)
public var ignoreVelocity:Boolean = true;
// time after which we stop trying to update (default 20 seconds)
public var maxTime:int = 20000;
// whether or not to round results
// note that internal value (_current) is never rounded
// we only round the value when it is applied to the object being tweened
public var keepRounded:Boolean = false;
// animation loop interval in ms
public var updateDelay:uint = 30;
// delay before start
public var delay:uint = 0;
// show debug messages while tweening (warning, slows things down)
public var debug:Boolean = false;
// callbacks
public var onUpdate:Function;
public var onComplete:Function;
public function clone() : FTweenOptions {
var o:FTweenOptions=new FTweenOptions();
o.debug = debug;
o.delay = delay;
o.ignoreVelocity = ignoreVelocity;
o.keepRounded = keepRounded;
o.maxTime = maxTime;
o.minDelta = minDelta;
o.minVelocity = minVelocity;
o.maxVelocity = maxVelocity;
o.onComplete = onComplete;
o.onUpdate = onUpdate;
o.updateDelay = updateDelay;
return o;
}
public function FTweenOptions( delay:uint=0, min_delta:Number=.01, min_velocity:Number=.01,
update_delay:uint=30, keep_rounded:Boolean=false, debug:Boolean=false,
on_complete:Function=null, on_update:Function=null )
{
keepRounded = keep_rounded;
minDelta = min_delta;
minVelocity = min_velocity;
updateDelay = update_delay;
onComplete = on_complete;
onUpdate = on_update;
this.debug = debug;
this.delay = delay;
}
}
}
--------------------------------------------------------------------------------
/src/com/bumpslide/tween/Fade.as:
--------------------------------------------------------------------------------
1 | /**
2 | * This code is part of the Bumpslide Library maintained by David Knape
3 | * Fork me at http://github.com/tkdave/bumpslide_as3
4 | *
5 | * Copyright (c) 2010 by Bumpslide, Inc.
6 | * http://www.bumpslide.com/
7 | *
8 | * This code is released under the open-source MIT license.
9 | * See LICENSE.txt for full license terms.
10 | * More info at http://www.opensource.org/licenses/mit-license.php
11 | */
12 |
13 | package com.bumpslide.tween
14 | {
15 |
16 | import com.greensock.TweenLite;
17 | import com.greensock.easing.Quad;
18 | import com.greensock.plugins.AutoAlphaPlugin;
19 | import com.greensock.plugins.TweenPlugin;
20 |
21 | import flash.display.DisplayObject;
22 |
23 | /**
24 | * FadeIn/FadeOut shortcuts using TweenLite
25 | *
26 | * These are the functions that were in BaseClip.
27 | * They have been moved here to remove the dependencies
28 | * on an external tweening engine.
29 | *
30 | * @author David Knape
31 | */
32 | public class Fade {
33 |
34 | static public var Easing:Class = Quad;
35 |
36 | static private var __autoAlphaInit:Boolean = function():Boolean{ TweenPlugin.activate( [ AutoAlphaPlugin ] ); return true; }();
37 |
38 | /**
39 | * fade in - with onComplete callback which gets run instantaneously if no tween is neded
40 | */
41 | static public function In(target:DisplayObject, delay:Number=0, duration:Number=.4, onComplete:Function=null) : void {
42 | if (target.alpha == 1 && target.visible) {
43 | if(onComplete!=null) onComplete.call(null);
44 | return;
45 | }
46 | if(!target.visible) {
47 | target.visible = true;
48 | target.alpha=0;
49 | }
50 | TweenLite.to( target, duration, { autoAlpha:1.0, ease:Easing.easeOut, delay:delay, onComplete:onComplete, overwrite:2});
51 | }
52 |
53 | /**
54 | * fade out - with onComplete callback which gets run instantaneously if no tween is neded
55 | */
56 | static public function Out(target:DisplayObject, delay:Number=.1, duration:Number=.2, onComplete:Function=null) : void {
57 | if (!target.visible) { target.alpha = 0; if(onComplete!=null) onComplete.call(null); return; }
58 | TweenLite.to( target, duration, { autoAlpha:0, ease:Easing.easeIn, delay:delay, onComplete:onComplete, overwrite:2});
59 | }
60 |
61 | static public function Cancel( target:DisplayObject ) : void {
62 | TweenLite.killTweensOf( target );
63 | }
64 |
65 |
66 |
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/src/com/bumpslide/ui/Application.as:
--------------------------------------------------------------------------------
1 | /**
2 | * This code is part of the Bumpslide Library maintained by David Knape
3 | * Fork me at http://github.com/tkdave/bumpslide_as3
4 | *
5 | * Copyright (c) 2010 by Bumpslide, Inc.
6 | * http://www.bumpslide.com/
7 | *
8 | * This code is released under the open-source MIT license.
9 | * See LICENSE.txt for full license terms.
10 | * More info at http://www.opensource.org/licenses/mit-license.php
11 | */
12 |
13 | package com.bumpslide.ui
14 | {
15 | import com.bumpslide.ui.Component;
16 | import com.bumpslide.util.StageProxy;
17 |
18 | import flash.events.Event;
19 | /**
20 | * Application/Document base class with stage proxy
21 | *
22 | * @author Default
23 | */
24 | public class Application extends Component
25 | {
26 |
27 | protected var stageProxy:StageProxy;
28 |
29 | override protected function init():void
30 | {
31 | log('init');
32 |
33 | // init stage proxy
34 | stageProxy = StageProxy.getInstance();
35 | stageProxy.addEventListener(Event.RESIZE, onStageResize);
36 |
37 | // wait for actual stage
38 | addEventListener(Event.ADDED_TO_STAGE, eventDelegate(initStage));
39 |
40 | // go on adding children. invalidating, and all that
41 | super.init();
42 |
43 | }
44 |
45 | /**
46 | * Called when stage is available
47 | */
48 | protected function initStage():void
49 | {
50 | stageProxy.init(stage); // <-- only need to do this once per app
51 | callLater( 10, updateNow );
52 | }
53 |
54 | /**
55 | * Listen to stage proxy resize events
56 | */
57 | protected function onStageResize(e:Event ):void
58 | {
59 | log('stageProxy resized ' + stageProxy.width + ',' + stageProxy.height);
60 | setSize(stageProxy.width, stageProxy.height);
61 | }
62 |
63 |
64 | override public function get minWidth():Number {
65 | return stageProxy.minWidth;
66 | }
67 |
68 |
69 | override public function set minWidth(val:Number):void {
70 | stageProxy.minWidth = val;
71 | }
72 |
73 |
74 | public function get maxWidth():Number {
75 | return stageProxy.maxWidth;
76 | }
77 |
78 |
79 | public function set maxWidth(val:Number):void {
80 | stageProxy.maxWidth = val;
81 | }
82 |
83 |
84 | override public function get minHeight():Number {
85 | return stageProxy.minHeight;
86 | }
87 |
88 |
89 | override public function set minHeight(val:Number):void {
90 | stageProxy.minHeight = val;
91 | }
92 |
93 |
94 | public function get maxHeight():Number {
95 | return stageProxy.maxHeight;
96 | }
97 |
98 |
99 | public function set maxHeight(val:Number):void {
100 | stageProxy.maxHeight = val;
101 | }
102 | }
103 | }
--------------------------------------------------------------------------------
/src/com/bumpslide/ui/CheckBox.as:
--------------------------------------------------------------------------------
1 | /**
2 | * This code is part of the Bumpslide Library maintained by David Knape
3 | * Fork me at http://github.com/tkdave/bumpslide_as3
4 | *
5 | * Copyright (c) 2010 by Bumpslide, Inc.
6 | * http://www.bumpslide.com/
7 | *
8 | * This code is released under the open-source MIT license.
9 | * See LICENSE.txt for full license terms.
10 | * More info at http://www.opensource.org/licenses/mit-license.php
11 | */
12 |
13 | package com.bumpslide.ui
14 | {
15 |
16 | import com.bumpslide.data.type.Padding;
17 | import com.bumpslide.ui.skin.defaults.DefaultCheckboxSkin;
18 |
19 | import flash.events.Event;
20 |
21 | /**
22 | * A checkbox is just a toggle button
23 | *
24 | * @author David Knape
25 | */
26 | public class CheckBox extends Button {
27 |
28 | static public var DefaultSkinClass:Class = DefaultCheckboxSkin;
29 |
30 | public function CheckBox(width:Number=-1, height:Number=-1, x:Number=0, y:Number=0, lbl:String="", is_selected:Boolean=false, on_change:Function=null )
31 | {
32 | super( width, height, x, y, lbl );
33 |
34 | selected = is_selected;
35 |
36 | if(on_change!=null) {
37 | addEventListener( Event.CHANGE, on_change, false, 0, true);
38 | }
39 | }
40 |
41 | override protected function addChildren():void {
42 | super.addChildren();
43 | toggle = true;
44 | }
45 |
46 | override protected function postConstruct():void
47 | {
48 | super.postConstruct();
49 | initDefaultSkin();
50 | }
51 |
52 | override protected function initDefaultSkin():void {
53 | //if(padding==null) {
54 | padding = new Padding( 0, 0, 0, 25 );
55 | //}
56 |
57 | if(skin==null && skinClass==null) {
58 | skinClass = DefaultSkinClass;
59 | }
60 | }
61 |
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/src/com/bumpslide/ui/Draw.as:
--------------------------------------------------------------------------------
1 | /**
2 | * This code is part of the Bumpslide Library maintained by David Knape
3 | * Fork me at http://github.com/tkdave/bumpslide_as3
4 | *
5 | * Copyright (c) 2010 by Bumpslide, Inc.
6 | * http://www.bumpslide.com/
7 | *
8 | * This code is released under the open-source MIT license.
9 | * See LICENSE.txt for full license terms.
10 | * More info at http://www.opensource.org/licenses/mit-license.php
11 | */
12 |
13 | package com.bumpslide.ui {
14 | import flash.display.Graphics;
15 | import flash.geom.Point;
16 |
17 | /**
18 | * @author David Knape
19 | */
20 | public class Draw {
21 |
22 | /**
23 | * Draw a dashed line using the drawing API line drawing
24 | *
25 | * Use graphics.lineStyle to determine color and tweak other proeprties.
26 | *
27 | * Note that a dash length of 1 will actually show up as more than a pixel due
28 | * to limitations with the drawing API. Use a bitmap fill for pixel perfect stuff.
29 | */
30 | static public function dashedLine( graphics:Graphics, from:Point, to:Point, len:Number=5, gap:Number=5 ) : void {
31 |
32 | var dist:Number = Point.distance(from, to);
33 | if(dist==0) return;
34 | var lStep:Number = (len/dist);
35 | var gStep:Number = (gap/dist);
36 | var n:Number=0;
37 | while( n<1 ) {
38 | var p1:Point = Point.interpolate( to, from, n );
39 | n+=lStep;
40 | // but don't draw past the desired end point
41 | if(n>1.0) n=1.0;
42 | var p2:Point = Point.interpolate( to, from, n );
43 | n+=gStep;
44 | graphics.moveTo( p1.x, p1.y );
45 | graphics.lineTo( p2.x, p2.y );
46 | }
47 | }
48 |
49 | /**
50 | * Draws a dotted line using drawing API circles for each dot
51 | *
52 | * Use graphics.beginFill to determine color
53 | */
54 | static public function dottedLine( graphics:Graphics, from:Point, to:Point, spacing:Number=5, radius:Number=1 ):void {
55 | var dist:Number = Point.distance(from, to);
56 | if(dist==0) return;
57 | var step:Number = ((spacing+radius*2)/dist);
58 | var n:Number=0;
59 | while( n<1 ) {
60 | var p:Point = Point.interpolate( to, from, n );
61 | graphics.drawCircle(p.x, p.y, radius);
62 | n+=step;
63 | }
64 | }
65 |
66 | /**
67 | * Pixel perfect dotted line (each dot is a pixel)
68 | *
69 | * Use graphics.beginFill to determine color
70 | */
71 | static public function pixelDottedLine( graphics:Graphics, from:Point, to:Point, spacing:Number=5 ):void {
72 | var dist:Number = Point.distance(from, to);
73 | if(dist==0) return;
74 | var step:Number = ((spacing+1)/dist);
75 | var n:Number=0;
76 | while( n<1 ) {
77 | var p:Point = Point.interpolate( to, from, n );
78 | graphics.drawRect( Math.round(p.x), Math.round(p.y), 1, 1);
79 | n+=step;
80 | }
81 | }
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/src/com/bumpslide/ui/FramerateMonitor.as:
--------------------------------------------------------------------------------
1 | /**
2 | * This code is part of the Bumpslide Library maintained by David Knape
3 | * Fork me at http://github.com/tkdave/bumpslide_as3
4 | *
5 | * Copyright (c) 2010 by Bumpslide, Inc.
6 | * http://www.bumpslide.com/
7 | *
8 | * This code is released under the open-source MIT license.
9 | * See LICENSE.txt for full license terms.
10 | * More info at http://www.opensource.org/licenses/mit-license.php
11 | */
12 |
13 | package com.bumpslide.ui
{
import flash.display.Sprite;
import flash.events.Event;
import flash.system.System;
import flash.text.AntiAliasType;
import flash.text.GridFitType;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.utils.*;
/**
* FPS and Memory Monitor
*
* @author David Knape
*/
public class FramerateMonitor extends Sprite {
static public const ALIGN_RIGHT:String = "right";
static public const ALIGN_LEFT:String = "left";
public var fpsField:TextField;
public var memField:TextField;
private var fpsCount:int = 0;
private var avgCount:int = 30;
private var previousTime:uint;
private var alignment:String = "right";
// update fps every X frames
private static const UPDATE_FRAMES:int = 10;
public function FramerateMonitor( textColor:Number=0xeeeeee, backgroundColor:Number=0x000000, backgroundAlpha:Number=.5, align:String="right")
{
alignment = align;
// draw background
var bg:Sprite = new Sprite();
//bg.graphics.lineStyle( 1, textColor, backgroundAlpha );
bg.graphics.beginFill(backgroundColor, backgroundAlpha );
bg.graphics.drawRect( 0, 0, 52, 26);
bg.graphics.endFill();
bg.x = bg.y = 1;
// draw text fields
fpsField = createTextField(2,1,50,15);
memField = createTextField(2,12,50,15);
// add to stage
addChild( bg );
addChild( fpsField );
addChild( memField );
// format text fields
var tf:TextFormat = new TextFormat('Verdana', 9, textColor );
fpsField.defaultTextFormat = tf;
memField.defaultTextFormat = tf;
// update on enterframe
addEventListener(Event.ADDED_TO_STAGE, onAddedToStage );
}
private function onAddedToStage(e:Event) : void {
stage.addEventListener( Event.RESIZE, onStageResize );
addEventListener( Event.ENTER_FRAME, update );
onStageResize();
}
private function onStageResize(e:Event=null) : void {
switch( alignment ) {
case ALIGN_RIGHT:
x = (stage.stageWidth-width) - 4;
break;
default:
// don't mess with x's
break;
}
}
private function update(e:Event) : void {
var time:uint = getTimer();
fpsCount += time-previousTime;
if (avgCount < 1){
fpsField.text = String(Math.round(1000/(fpsCount/UPDATE_FRAMES))+" FPS");
avgCount = UPDATE_FRAMES;
fpsCount = 0;
}
avgCount--;
previousTime = time;
memField.text = Math.round(System.totalMemory/(1024*1024)) + " MB";
}
private function createTextField(x:Number, y:Number, width:Number, height:Number ) : TextField {
var tf:TextField = new TextField();
tf.width = width;
tf.height = height;
tf.x = x;
tf.y = y;
tf.selectable = false;
tf.antiAliasType = AntiAliasType.ADVANCED;
tf.gridFitType = GridFitType.PIXEL;
return tf;
}
}
}
--------------------------------------------------------------------------------
/src/com/bumpslide/ui/GridItem.as:
--------------------------------------------------------------------------------
1 | /**
* This code is part of the Bumpslide Library maintained by David Knape
* Fork me at http://github.com/tkdave/bumpslide_as3
*
* Copyright (c) 2010 by Bumpslide, Inc.
* http://www.bumpslide.com/
*
* This code is released under the open-source MIT license.
* See LICENSE.txt for full license terms.
* More info at http://www.opensource.org/licenses/mit-license.php
*/
package com.bumpslide.ui {
import com.bumpslide.util.GridLayout;
/**
* Basic Grid Item including invalidation/update hook and buttonMode init
*
* Use this as a base class for cell renderers in GridLayout grids.
* Or, you can make your own class that implements IGridItem.
*
* If you just want to process grid item clicks, listen for the
* UIEvent of type Grid.EVENT_ITEM_CLICK. This is actually dispatched
* from within GridLayout, and the data attribute of this event is the
* gridItemData for this item.
*
* @author David Knape
* @see com.bumpslide.ui.ListItem
*/
public class GridItem extends Component implements IGridItem {
// our place in line
protected var _gridIndex:Number;
// what defines us
protected var _gridItemData:*;
// ancestral ties
public var layout:GridLayout;
//----------------------------------------------
// Methods to override in GridItem Sub Classes
//----------------------------------------------
/**
* Implement grid item views update here.
*/
protected function drawGridItem():void {
//label = gridItemData;
}
/**
* Called when data is set to null (when clip is recycled)
*
* This isn't as important to override unless you need to remove
* some event listeners that were added during 'drawGridItem'.
*/
protected function clearGridItem():void {
//label = "";
}
//----------------------------------------------
/**
* Sets updateDelay to 0 so we don't have any flicker in our scrolling grids
*/
override protected function addChildren():void {
//delayUpdate = false;
super.addChildren();
}
/**
* Override if you want, but you shouldn't need to.
*/
override protected function draw():void {
if(hasChanged(VALID_DATA)) {
if(gridItemData!=null) {
drawGridItem();
} else {
clearGridItem();
}
validate(VALID_DATA);
}
super.draw();
}
//------------------------------------
// IGridItem Interface implementation
//------------------------------------
/**
* grid index
*/
public function get gridIndex():Number {
return _gridIndex;
}
/**
* the grid dataprovider's item at this index
*/
public function get gridItemData():* {
return _gridItemData;
}
/**
* sets grid index (used by GridLayout)
*/
public function set gridIndex(n:Number):void {
_gridIndex = n;
invalidate(VALID_DATA);
}
/**
* Updates data (used by GridLayout)
*
* This is where we call invalidate to trigger an update process
*/
public function set gridItemData(d:*):void {
_gridItemData = d;
// turn off delayed updates if you need it to clear immediately
// if(_gridItemData==null) {
// // clear it now
// clearGridItem();
// }
invalidate(VALID_DATA);
}
}
}
--------------------------------------------------------------------------------
/src/com/bumpslide/ui/HBox.as:
--------------------------------------------------------------------------------
1 | package com.bumpslide.ui
2 | {
3 |
4 | import com.bumpslide.data.constant.Direction;
5 |
6 |
7 | /**
8 | * HBox
9 | *
10 | * @author David Knape
11 | */
12 | dynamic public class HBox extends Container
13 | {
14 |
15 | public function HBox( children:Array = null, spacing:Number=10)
16 | {
17 | super( Direction.HORIZONTAL, 10 );
18 | if(children) this.children = children;
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/src/com/bumpslide/ui/IGridItem.as:
--------------------------------------------------------------------------------
1 | /**
2 | * This code is part of the Bumpslide Library maintained by David Knape
3 | * Fork me at http://github.com/tkdave/bumpslide_as3
4 | *
5 | * Copyright (c) 2010 by Bumpslide, Inc.
6 | * http://www.bumpslide.com/
7 | *
8 | * This code is released under the open-source MIT license.
9 | * See LICENSE.txt for full license terms.
10 | * More info at http://www.opensource.org/licenses/mit-license.php
11 | */
12 |
13 | package com.bumpslide.ui {
/**
* Grid Item Interface
*
* This interface should be implemented by clips that
* are controlled by a GridLayout instance.
*
* @author David Knape
*/
public interface IGridItem {
// cancel any pending loader activity, remove event listeners, and die
// this is implemented alredy in Component, and thus Button
function destroy () : void;
// setter used to assign grid index to your grid item
function set gridIndex (n:Number):void;
function get gridIndex () : Number;
// setter used to pass in the data for this position in the dataprovider
function set gridItemData (d:*):void;
function get gridItemData () : *;
// standard display object stuff (most likely already implemented)
function set x (n:Number) : void;
function set y (n:Number) : void;
14 |
15 | function get x ():Number;
16 | function get y ():Number;
function set visible (val:Boolean) : void;
function get visible () : Boolean;
}
}
--------------------------------------------------------------------------------
/src/com/bumpslide/ui/IResizable.as:
--------------------------------------------------------------------------------
1 | /**
2 | * This code is part of the Bumpslide Library maintained by David Knape
3 | * Fork me at http://github.com/tkdave/bumpslide_as3
4 | *
5 | * Copyright (c) 2010 by Bumpslide, Inc.
6 | * http://www.bumpslide.com/
7 | *
8 | * This code is released under the open-source MIT license.
9 | * See LICENSE.txt for full license terms.
10 | * More info at http://www.opensource.org/licenses/mit-license.php
11 | */
12 |
13 | package com.bumpslide.ui {
14 |
15 | /**
16 | * @author David Knape
17 | */
18 | public interface IResizable {
19 | function setSize( w:Number, h:Number ) : void;
20 | function get width():Number;
21 | function get height():Number;
22 | function set width(val:Number):void;
23 | function set height(val:Number):void;
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/com/bumpslide/ui/IScrollable.as:
--------------------------------------------------------------------------------
1 | /**
2 | * This code is part of the Bumpslide Library maintained by David Knape
3 | * Fork me at http://github.com/tkdave/bumpslide_as3
4 | *
5 | * Copyright (c) 2010 by Bumpslide, Inc.
6 | * http://www.bumpslide.com/
7 | *
8 | * This code is released under the open-source MIT license.
9 | * See LICENSE.txt for full license terms.
10 | * More info at http://www.opensource.org/licenses/mit-license.php
11 | */
12 |
13 | package com.bumpslide.ui {
/**
* Scrollable Interface Used by Slider Component
*
* @see Slider.scrollTarget
*
* @author David Knape
*/
public interface IScrollable {
/**
* Returns total size of scroll content
*/
function get totalSize () : Number ;
/**
* Returns viewport size
*/
function get visibleSize () : Number ;
/**
* Returns current scroll position
*/
function get scrollPosition () : Number ;
/**
* Set current scroll position
*/
function set scrollPosition ( scrollOffset:Number ) : void;
14 |
15 | /**
16 | * Orientation - horizontal or vertical
*/
17 | function get orientation():String;
18 |
19 | /**
20 | * Convert from native scrollPosition units to pixels
21 | * This is needed for drag scroll implementations
*/
22 | function get pixelsPerUnit():Number;
23 |
}
}
--------------------------------------------------------------------------------
/src/com/bumpslide/ui/ISelectable.as:
--------------------------------------------------------------------------------
1 | /**
2 | * This code is part of the Bumpslide Library maintained by David Knape
3 | * Fork me at http://github.com/tkdave/bumpslide_as3
4 | *
5 | * Copyright (c) 2010 by Bumpslide, Inc.
6 | * http://www.bumpslide.com/
7 | *
8 | * This code is released under the open-source MIT license.
9 | * See LICENSE.txt for full license terms.
10 | * More info at http://www.opensource.org/licenses/mit-license.php
11 | */
12 |
13 | package com.bumpslide.ui
14 | {
15 |
16 | /**
17 | * ISelectable
18 | *
19 | * @author David Knape
20 | * @version SVN: $Id: $
21 | */
22 | public interface ISelectable
23 | {
24 |
25 | function set selected(val:Boolean):void;
26 | function get selected():Boolean;
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/src/com/bumpslide/ui/ISkin.as:
--------------------------------------------------------------------------------
1 | /**
2 | * This code is part of the Bumpslide Library maintained by David Knape
3 | * Fork me at http://github.com/tkdave/bumpslide_as3
4 | *
5 | * Copyright (c) 2010 by Bumpslide, Inc.
6 | * http://www.bumpslide.com/
7 | *
8 | * This code is released under the open-source MIT license.
9 | * See LICENSE.txt for full license terms.
10 | * More info at http://www.opensource.org/licenses/mit-license.php
11 | */
12 |
13 | package com.bumpslide.ui
14 | {
15 | import com.bumpslide.ui.skin.*;
16 | /**
17 | * Interface for component skins
18 | *
19 | * @author David Knape
20 | */
21 | public interface ISkin
22 | {
23 |
24 | /**
25 | * Init Host
26 | */
27 | function initHostComponent( host_component:ISkinnable ):void;
28 |
29 |
30 | /**
31 | * State has changed. Update display list.
32 | */
33 | function renderSkin( skinState:String ):void;
34 |
35 |
36 | /**
37 | * Take down children
38 | */
39 | function destroy():void;
40 |
41 |
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/com/bumpslide/ui/ISkinnable.as:
--------------------------------------------------------------------------------
1 | /**
2 | * This code is part of the Bumpslide Library maintained by David Knape
3 | * Fork me at http://github.com/tkdave/bumpslide_as3
4 | *
5 | * Copyright (c) 2010 by Bumpslide, Inc.
6 | * http://www.bumpslide.com/
7 | *
8 | * This code is released under the open-source MIT license.
9 | * See LICENSE.txt for full license terms.
10 | * More info at http://www.opensource.org/licenses/mit-license.php
11 | */
12 |
13 | package com.bumpslide.ui
14 | {
15 | import com.bumpslide.ui.IResizable;
16 | import flash.display.DisplayObject;
17 |
18 | /**
19 | * Interface for skinnable components
20 | *
21 | * Skins don't have to be ISkin. They just get a few nice hooks if they do.
22 | *
23 | * @author David Knape
24 | */
25 | public interface ISkinnable extends IResizable
26 | {
27 | function set skinClass(c:Class):void;
28 | function get skinClass():Class;
29 |
30 | function set skinState(s:String):void;
31 | function get skinState():String;
32 |
33 | function set skin(mc:DisplayObject):void;
34 | function get skin():DisplayObject;
35 |
36 |
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/com/bumpslide/ui/IZoomable.as:
--------------------------------------------------------------------------------
1 | /**
2 | * This code is part of the Bumpslide Library maintained by David Knape
3 | * Fork me at http://github.com/tkdave/bumpslide_as3
4 | *
5 | * Copyright (c) 2010 by Bumpslide, Inc.
6 | * http://www.bumpslide.com/
7 | *
8 | * This code is released under the open-source MIT license.
9 | * See LICENSE.txt for full license terms.
10 | * More info at http://www.opensource.org/licenses/mit-license.php
11 | */
12 |
13 | package com.bumpslide.ui {
14 |
15 | /**
16 | * Interface for Zoomable content
17 | *
18 | * panX and panY are measured in pixels of content at zoom level 1
19 | * pan (0,0) is centered
20 | * zoom is the same as xscale/yscale of content
21 | *
22 | * @author David Knape
23 | */
24 | public interface IZoomable {
25 |
26 | // set current zoom level without changing position
27 | function set zoom( z:Number ) : void;
28 |
29 | // get current zoom level
30 | function get zoom() : Number;
31 |
32 | // set x pan location
33 | function set panX(x:Number) : void;
34 |
35 | // get x pan location
36 | function get panX() : Number;
37 |
38 | // set y pan location
39 | function set panY(y:Number) : void;
40 |
41 | // get y pan location
42 | function get panY() : Number;
43 |
44 | // set the dimensions of the views rect (mask)
45 | function setSize(w:Number, h:Number) : void;
46 |
47 | // get width of viewing window
48 | function get width () : Number;
49 |
50 | // get height of viewing window
51 | function get height () : Number;
52 |
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/com/bumpslide/ui/PixelIcon.as:
--------------------------------------------------------------------------------
1 | /**
2 | * This code is part of the Bumpslide Library maintained by David Knape
3 | * Fork me at http://github.com/tkdave/bumpslide_as3
4 | *
5 | * Copyright (c) 2010 by Bumpslide, Inc.
6 | * http://www.bumpslide.com/
7 | *
8 | * This code is released under the open-source MIT license.
9 | * See LICENSE.txt for full license terms.
10 | * More info at http://www.opensource.org/licenses/mit-license.php
11 | */
12 |
13 | package com.bumpslide.ui
14 | {
15 |
16 | /**
17 | * Quite ridiculous, actually
18 | *
19 | * example:
20 | *
21 | * // arrow
22 | * addChild( new PixelIcon( [' * ',
23 | * ' *',
* '********',
* ' *',
24 | * ' * '] ) );
25 | *
26 | * @author David Knape
27 | */
28 | public class PixelIcon extends Component {
29 |
30 | private var _data:Array;
31 | private var _color:Number;
32 |
33 | public function PixelIcon(icon_data:*=null, pixel_color:Number=0x000000) {
34 | color = pixel_color;
35 | if(icon_data!=null) data = icon_data;
36 | super();
37 | }
38 |
39 | /**
40 | * Pixel data as an array of strings
41 | */
42 | public function set data(data:*):void {
43 | if(data is String) {
44 | _data = String(data).split(',');
45 | } else if (data is Array) {
46 | _data = data;
47 | }
48 | invalidate();
49 | }
50 |
51 | public function set color(val:*):void {
52 | if(isNaN(val)) val=parseInt(val, 16);
53 | _color = val;
54 | invalidate();
55 | }
56 |
57 |
58 | override public function get width():Number {
59 | return actualWidth;
60 | }
61 |
62 | override public function get height():Number {
63 | return actualHeight;
64 | }
65 |
66 |
67 | override protected function draw() : void {
68 | if(_data==null) return;
69 | graphics.clear();
70 | graphics.beginFill(_color, 1);
71 | var num_rows:int = _data.length;
72 | for ( var row:int=0; row
22 | *
23 | * // init...
24 | * var reflection:Reflection = new Reflection();
25 | * reflection.x = someContent.x;
26 | * reflection.y = someContent.y + someContent.height; *
27 | * addChild( reflection );
28 | *
29 | * // update...
30 | * reflection.reflect( someContent );
31 | *
32 | *
33 | *
34 | * @author David Knape
35 | */
36 | public class Reflection extends Bitmap {
37 |
38 | public var distance:Number = 100;
39 |
40 | public function reflect(source:DisplayObject):void {
41 | if(!bitmapData || bitmapData.height != distance || bitmapData.width != source.width) {
42 | bitmapData = new BitmapData(source.width, distance, true, 0x00000000);
43 | }
44 | // draw reflection
45 | var mtx:Matrix = new Matrix();
46 | mtx.ty = -source.height;
47 | mtx.scale(source.scaleX, -source.scaleY);
48 | bitmapData.draw(source, mtx, source.transform.colorTransform, BlendMode.LAYER);
49 |
50 | // draw gradient with alpha blend mode to fade it out
51 | var gradient:Shape = new Shape();
52 | var matr:Matrix = new Matrix();
53 | matr.createGradientBox(source.width, distance, Math.PI / 2, 0, 0);
54 | gradient.graphics.beginGradientFill(GradientType.LINEAR, [0x000000, 0x000000], [.2, 0], [0, 255], matr);
55 | gradient.graphics.drawRect(0, 0, bitmapData.width, bitmapData.height);
56 | bitmapData.draw(gradient, null, null, BlendMode.ALPHA);
57 | }
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/src/com/bumpslide/ui/Skin.as:
--------------------------------------------------------------------------------
1 | /**
2 | * This code is part of the Bumpslide Library maintained by David Knape
3 | * Fork me at http://github.com/tkdave/bumpslide_as3
4 | *
5 | * Copyright (c) 2010 by Bumpslide, Inc.
6 | * http://www.bumpslide.com/
7 | *
8 | * This code is released under the open-source MIT license.
9 | * See LICENSE.txt for full license terms.
10 | * More info at http://www.opensource.org/licenses/mit-license.php
11 | */
12 |
13 | package com.bumpslide.ui
14 | {
15 | /**
16 | * This is the base class for programmatic stateful skins
17 | *
18 | * The ISkin draw method is implemented in such a way that it looks
19 | * for a method on the skin class with a name like '_'+hostComponent.skinState
20 | *
21 | * If found, this method is called. An example of this can be found in the
22 | * minimal button skin class.
23 | *
24 | * @author David Knape
25 | */
26 | public class Skin extends Component implements ISkin
27 | {
28 | /**
29 | * reference to component that is hosting this skin
30 | */
31 | protected var _hostComponent:ISkinnable;
32 |
33 | /**
34 | *
35 | */
36 | public function initHostComponent(host_component:ISkinnable):void
37 | {
38 | log('initHostComponent ' + host_component);
39 | _hostComponent = host_component;
40 | }
41 |
42 | /**
43 | * Default state change handler
44 | *
45 | * Tries to call a function in this class with a name that is ('_' + currentState).
46 | */
47 | public function renderSkin(skinState:String):void
48 | {
49 | try {
50 | (this['_' + _hostComponent.skinState] as Function).call(this);
51 | } catch (e:Error) {
52 | // whatever
53 | }
54 | invalidate();
55 | }
56 |
57 | override public function get width():Number
58 | {
59 | return _hostComponent ? _hostComponent.width : super.width;
60 | }
61 |
62 | override public function get height():Number
63 | {
64 | return _hostComponent ? _hostComponent.height : super.height;
65 | }
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/src/com/bumpslide/ui/TextPanel.as:
--------------------------------------------------------------------------------
1 | /**
2 | * This code is part of the Bumpslide Library maintained by David Knape
3 | * Fork me at http://github.com/tkdave/bumpslide_as3
4 | *
5 | * Copyright (c) 2010 by Bumpslide, Inc.
6 | * http://www.bumpslide.com/
7 | *
8 | * This code is released under the open-source MIT license.
9 | * See LICENSE.txt for full license terms.
10 | * More info at http://www.opensource.org/licenses/mit-license.php
11 | */
12 |
13 | package com.bumpslide.ui
14 | {
15 |
16 | import flash.text.TextFormat;
17 |
18 | /**
* Simple Scrolling Text Panel
*
* see ScrollPanel docs/samples for info on skinning
*
* @author David Knape
*/
19 | public class TextPanel extends ScrollPanel
20 | {
21 |
22 | override protected function addChildren():void
23 | {
24 | super.addChildren();
25 |
26 | if (content == null) {
27 | var tb:Label = new Label();
28 | tb.textField.mouseEnabled = false;
29 | tb.textField.selectable = false;
30 | tb.x = -1;
31 | content = tb;
32 | }
33 |
34 | // bitmap caching of content sometimes messes up text fields
35 | // turn it off by default here
36 | _holder.cacheAsBitmap = false;
37 | }
38 |
39 |
40 | // Public reference to textbox content
41 | public function get textbox():Label {
42 | return content as Label;
43 | }
44 |
45 |
46 | public function get textFormat():TextFormat {
47 | return textbox.textFormat;
48 | }
49 |
50 |
51 | public function set textFormat( tf:TextFormat ):void {
52 | textbox.textFormat = tf;
53 | invalidate();
54 | }
55 |
56 |
57 | public function set text( s:String ):void {
58 | textbox.text = s;
59 | invalidate();
60 | }
61 |
62 |
63 | public function get text():String {
64 | return textbox.text;
65 | }
66 |
67 |
68 | public function set htmlText( s:String ):void {
69 | // content_txt.condenseWhite = true;
70 | textbox.htmlText = s;
71 | invalidate();
72 | }
73 |
74 |
75 | public function get htmlText():String {
76 | return textbox.htmlText;
77 | }
78 | }
79 | }
--------------------------------------------------------------------------------
/src/com/bumpslide/ui/TouchList.as:
--------------------------------------------------------------------------------
1 | /**
2 | * This code is part of the Bumpslide Library maintained by David Knape
3 | * Fork me at http://github.com/tkdave/bumpslide_as3
4 | *
5 | * Copyright (c) 2012 by Bumpslide, Inc.
6 | * http://www.bumpslide.com/
7 | *
8 | * This code is released under the open-source MIT license.
9 | * See LICENSE.txt for full license terms.
10 | * More info at http://www.opensource.org/licenses/mit-license.php
11 | */
12 | package com.bumpslide.ui
13 | {
14 |
15 | import com.bumpslide.tween.FTween;
16 | import com.bumpslide.ui.behavior.DragScrollBehavior;
17 | import com.bumpslide.ui.skin.touch.TouchScrollSkin;
18 |
19 | import flash.events.Event;
20 |
21 |
22 | /**
23 | * List/Grid Component setup for touch-style interaction
24 | *
25 | * This is still using mouse events.
26 | *
27 | * @author David Knape, http://bumpslide.com/
28 | */
29 | public class TouchList extends Grid
30 | {
31 | private var touchBehavior:DragScrollBehavior;
32 |
33 | public function TouchList()
34 | {
35 | super();
36 |
37 | // enable dragging
38 | touchBehavior = DragScrollBehavior.init(this, layout);
39 |
40 | // add touch-style scroll bar
41 | scrollbarWidth = 6;
42 | scrollbar.skinClass = TouchScrollSkin;
43 |
44 | // tweak the advanced layout options
45 | with (layout) {
46 | scrollTweenEaseFactor = .3;
47 | renderInBatches = true;
48 | renderBatchPageCount = 2;
49 | addEventListener(Event.RENDER, onGridRender);
50 | }
51 | }
52 |
53 | // update scrollbar
54 | private function onGridRender(event:Event):void
55 | {
56 | if (scrollbar.visible) {
57 | scrollbar.value = layout.offset;
58 | FTween.easeOut(scrollbar, 'alpha', .85, .2, { onComplete:fadeOutScrollbar });
59 | }
60 | }
61 |
62 | private function fadeOutScrollbar():void
63 | {
64 | FTween.easeIn(scrollbar, 'alpha', .5, .2, { delay:1000 });
65 | }
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/src/com/bumpslide/ui/VBox.as:
--------------------------------------------------------------------------------
1 | package com.bumpslide.ui
2 | {
3 |
4 | import com.bumpslide.data.constant.Direction;
5 |
6 |
7 | /**
8 | * VBox
9 | *
10 | * @author David Knape
11 | */
12 | dynamic public class VBox extends Container
13 | {
14 |
15 | public function VBox( children:Array = null, spacing:Number=10)
16 | {
17 | super( Direction.VERTICAL, spacing);
18 | if(children) this.children = children;
19 |
20 | }
21 |
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/com/bumpslide/ui/VSlider.as:
--------------------------------------------------------------------------------
1 | /**
2 | * This code is part of the Bumpslide Library maintained by David Knape
3 | * Fork me at http://github.com/tkdave/bumpslide_as3
4 | *
5 | * Copyright (c) 2010 by Bumpslide, Inc.
6 | * http://www.bumpslide.com/
7 | *
8 | * This code is released under the open-source MIT license.
9 | * See LICENSE.txt for full license terms.
10 | * More info at http://www.opensource.org/licenses/mit-license.php
11 | */
12 |
13 | package com.bumpslide.ui {
import com.bumpslide.data.constant.Direction;
import com.bumpslide.ui.Slider;
/**
* This class exists so we can distinquish from normal sliders in a FLA file
*
* @author David Knape
*/
public class VSlider extends Slider {
public function VSlider() { super(Direction.VERTICAL); }
}
}
--------------------------------------------------------------------------------
/src/com/bumpslide/ui/Wrapper.as:
--------------------------------------------------------------------------------
1 | /**
2 | * This code is part of the Bumpslide Library maintained by David Knape
3 | * Fork me at http://github.com/tkdave/bumpslide_as3
4 | *
5 | * Copyright (c) 2010 by Bumpslide, Inc.
6 | * http://www.bumpslide.com/
7 | *
8 | * This code is released under the open-source MIT license.
9 | * See LICENSE.txt for full license terms.
10 | * More info at http://www.opensource.org/licenses/mit-license.php
11 | */
12 |
13 | package com.bumpslide.ui
14 | {
15 | import com.bumpslide.events.UIEvent;
16 |
17 | import mx.core.UIComponent;
18 | import mx.core.mx_internal;
19 |
20 | import flash.display.DisplayObject;
21 | import flash.events.Event;
22 | import flash.system.ApplicationDomain;
23 |
24 | /**
25 | * Component Wrapper for Flex
26 | *
27 | * inspired by gkinner's display object wrapper
28 | * refactored and updated to work with bumpslide UI components
29 | * as well as normal display objects
30 | *
31 | * @author David Knape
32 | */
33 | [DefaultProperty('content')]
34 |
35 | public class Wrapper extends UIComponent
36 | {
37 |
38 | private var _content:DisplayObject;
39 |
40 | private var _watchSize:Boolean = false;
41 |
42 |
43 | /**
44 | * Creates a new wrapper with content passed in as constructor arg
45 | */
46 | public function Wrapper(p_content:*= null, p_watchSize:Boolean = false)
47 | {
48 | content = p_content;
49 | watchSize = p_watchSize;
50 | super();
51 | }
52 |
53 | [Inspectable]
54 | public function set watchSize(value:Boolean):void {
55 | _watchSize = value;
56 |
57 | if (_watchSize) {
58 | addEventListener(Event.ENTER_FRAME, checkSize);
59 | } else {
60 | removeEventListener(Event.ENTER_FRAME, checkSize);
61 | }
62 | }
63 |
64 |
65 | public function get watchSize():Boolean {
66 | return _watchSize;
67 | }
68 |
69 | [Inspectable]
70 | public function set content(p_content:*):void {
71 | if (_content != null && contains(_content)) {
72 | removeChild(_content);
73 | }
74 |
75 | if (p_content is String) {
76 | try {
77 | p_content = ApplicationDomain.currentDomain.getDefinition(p_content);
78 | } catch (e:*) {
79 | }
80 | }
81 | if (p_content is Class) {
82 | p_content = new p_content();
83 | }
84 | _content = p_content as DisplayObject;
85 | if (_content != null) {
86 | addChild(_content);
87 | }
88 |
89 | // list for component redraw and invalidate size
90 | addEventListener( Component.EVENT_SIZE_CHANGED, function( event:UIEvent ):void {
91 | invalidateSize();
92 | });
93 |
94 | invalidateSize();
95 | }
96 |
97 |
98 | public function get content():DisplayObject {
99 | return _content;
100 | }
101 |
102 |
103 | override protected function measure():void
104 | {
105 | measuredWidth = contentWidth;
106 | measuredHeight = contentHeight;
107 | }
108 |
109 |
110 | private function checkSize(evt:Event):void
111 | {
112 | if (mx_internal::_width != contentWidth || mx_internal::_height != contentHeight) {
113 | invalidateSize();
114 | }
115 | }
116 |
117 | private function get contentWidth():Number {
118 | return (_content) ? _content.width : 0;
119 | }
120 |
121 |
122 | private function get contentHeight():Number {
123 | return (_content) ? _content.height : 0;
124 | }
125 |
126 |
127 | override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
128 | {
129 | super.updateDisplayList(unscaledWidth, unscaledHeight);
130 |
131 |
132 | if(content is IResizable) {
133 | (content as IResizable).setSize(unscaledWidth, unscaledHeight);
134 | } else {
135 | content.width = unscaledWidth;
136 | content.height = unscaledHeight;
137 | }
138 | }
139 |
140 |
141 | }
142 | }
143 |
--------------------------------------------------------------------------------
/src/com/bumpslide/ui/behavior/DropDownBehavior.as:
--------------------------------------------------------------------------------
1 | package com.bumpslide.ui.behavior
2 | {
3 |
4 | import flash.events.EventDispatcher;
5 |
6 | /**
7 | * DropDownBehavior
8 | *
9 | * @author David Knape
10 | */
11 | public class DropDownBehavior extends EventDispatcher
12 | {
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/src/com/bumpslide/ui/behavior/IBehavior.as:
--------------------------------------------------------------------------------
1 | /**
2 | * This code is part of the Bumpslide Library maintained by David Knape
3 | * Fork me at http://github.com/tkdave/bumpslide_as3
4 | *
5 | * Copyright (c) 2010 by Bumpslide, Inc.
6 | * http://www.bumpslide.com/
7 | *
8 | * This code is released under the open-source MIT license.
9 | * See LICENSE.txt for full license terms.
10 | * More info at http://www.opensource.org/licenses/mit-license.php
11 | */
12 |
13 | package com.bumpslide.ui.behavior
14 | {
15 | import flash.display.InteractiveObject;
16 |
17 | /**
18 | * IBehavior
19 | *
20 | * @author David Knape
21 | * @version SVN: $Id: $
22 | */
23 | public interface IBehavior
24 | {
25 |
26 |
27 |
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/com/bumpslide/ui/behavior/TooltipBehavior.as:
--------------------------------------------------------------------------------
1 | /**
2 | * This code is part of the Bumpslide Library maintained by David Knape
3 | * Fork me at http://github.com/tkdave/bumpslide_as3
4 | *
5 | * Copyright (c) 2010 by Bumpslide, Inc.
6 | * http://www.bumpslide.com/
7 | *
8 | * This code is released under the open-source MIT license.
9 | * See LICENSE.txt for full license terms.
10 | * More info at http://www.opensource.org/licenses/mit-license.php
11 | */
12 |
13 | package com.bumpslide.ui.behavior {
import com.bumpslide.events.UIEvent;
14 | import com.bumpslide.util.Delegate;
15 |
16 | import flash.display.InteractiveObject;
17 | import flash.events.Event;
18 | import flash.events.EventDispatcher;
19 | import flash.events.MouseEvent;
20 | import flash.events.TimerEvent;
21 | import flash.utils.Dictionary;
22 | import flash.utils.Timer;
23 |
/**
* Tooltip Behavior
*
* Initialize with a target and a handler for hiding and showing the toolip.
*
* @author David Knape
*/
public class TooltipBehavior extends EventDispatcher {
/**
* Create a new tooltip Behavior
*/
function TooltipBehavior(target:InteractiveObject, showHandler:Function, hideHandler:Function, initialDelay:int=500 ) {
_target = target;
_initialDelay = initialDelay;
_showHandler = showHandler;
_hideHandler = hideHandler;
// kill existing behavior if found to avoid duplicate listeners
if(_buttons[target]!=null) (_buttons[target] as RepeaterButtonBehavior).remove();
// add ourself to the registry
_buttons[target] = this;
// add mouse event listeners to target
_target.addEventListener( MouseEvent.ROLL_OVER, onRollOver, false, 0, true);
_target.addEventListener( MouseEvent.ROLL_OUT, onRollOut, false, 0, true);
}
/**
* removes event listeners, thus removing behavior
*/
public function remove() : void {
_target.removeEventListener( MouseEvent.ROLL_OVER, onRollOver);
_target.removeEventListener( MouseEvent.ROLL_OUT, onRollOut);
_showHandler = null;
_hideHandler = null;
delete _buttons[target];
}
/**
* the button to which this behavior has been applied
*/
public function get target () : InteractiveObject {
return _target;
}
24 |
protected function onRollOver(e:MouseEvent):void {
Delegate.cancel( _delayTimer );
_delayTimer = Delegate.callLater( _initialDelay, _showHandler);
}
protected function onRollOut(e:MouseEvent):void {
Delegate.cancel( _delayTimer );
_hideHandler();
}
protected var _target:InteractiveObject;
protected var _delayTimer:Timer;
protected var _initialDelay:int=500;
protected var _showHandler:Function;
protected var _hideHandler:Function;
// track instances locally to aid in event management
static private var _buttons:Dictionary = new Dictionary(true);
}
}
--------------------------------------------------------------------------------
/src/com/bumpslide/ui/behavior/TouchBehavior.as:
--------------------------------------------------------------------------------
1 | package com.bumpslide.ui.behavior
2 | {
3 |
4 | import flash.display.InteractiveObject;
5 | import flash.events.TouchEvent;
6 | import flash.geom.Point;
7 | import flash.utils.Dictionary;
8 |
9 | /**
10 | * TouchBehavior
11 | *
12 | * @author David Knape, http://bumpslide.com/
13 | */
14 | public class TouchBehavior
15 | {
16 |
17 | // track instances locally to aid in event management
18 | static private var _targets:Dictionary = new Dictionary(true);
19 |
20 | public var target:InteractiveObject;
21 |
22 | protected var _enabled:Boolean = true;
23 |
24 |
25 | private var useCapture:Boolean = false;
26 |
27 | public var touchPoints:Dictionary;
28 |
29 |
30 | static public function init( touch_target:InteractiveObject, use_capture:Boolean = false ):TouchBehavior {
31 | return new TouchBehavior(touch_target, use_capture);
32 | }
33 |
34 | static public function destroy(touch_target:InteractiveObject):void {
35 | if(_targets[touch_target] != null) (_targets[touch_target] as DragBehavior).remove();
36 | }
37 |
38 |
39 | public function TouchBehavior( touch_target:InteractiveObject, use_capture:Boolean = false )
40 | {
41 | TouchBehavior.destroy(touch_target);
42 | target = touch_target;
43 | useCapture = use_capture;
44 | _targets[target] = this;
45 |
46 | touchPoints = new Dictionary();
47 |
48 | target.addEventListener( TouchEvent.TOUCH_BEGIN, onTouchBegin, useCapture );
49 | target.addEventListener( TouchEvent.TOUCH_MOVE, onTouchMove, useCapture );
50 | target.addEventListener( TouchEvent.TOUCH_END, onTouchEnd, useCapture );
51 |
52 | }
53 |
54 | /**
55 | * removes event listeners, thus removing behavior
56 | */
57 | public function remove():void {
58 |
59 |
60 | for(var id:String in touchPoints) {
61 | delete touchPoints[id];
62 | }
63 |
64 | touchPoints = null;
65 |
66 | target.removeEventListener( TouchEvent.TOUCH_BEGIN, onTouchBegin, useCapture );
67 | target.removeEventListener( TouchEvent.TOUCH_MOVE, onTouchMove, useCapture );
68 | target.removeEventListener( TouchEvent.TOUCH_END, onTouchEnd, useCapture );
69 |
70 | delete _targets[target];
71 | }
72 |
73 |
74 | protected function init():void {
75 | target.addEventListener( TouchEvent.TOUCH_BEGIN, onTouchBegin );
76 | target.addEventListener( TouchEvent.TOUCH_MOVE, onTouchMove );
77 | target.addEventListener( TouchEvent.TOUCH_END, onTouchEnd );
78 | }
79 |
80 | private function onTouchBegin( event:TouchEvent ):void
81 | {
82 | touchPoints[event.touchPointID] = new Point( event.localX, event.localY );
83 | }
84 |
85 | private function onTouchMove( event:TouchEvent ):void
86 | {
87 | touchPoints[event.touchPointID] = new Point( event.localX, event.localY );
88 | }
89 |
90 | private function onTouchEnd( event:TouchEvent ):void
91 | {
92 | delete touchPoints[event.touchPointID];
93 | }
94 | }
95 | }
96 |
--------------------------------------------------------------------------------
/src/com/bumpslide/ui/skin/BasicSliderSkin.as:
--------------------------------------------------------------------------------
1 | /**
2 | * This code is part of the Bumpslide Library maintained by David Knape
3 | * Fork me at http://github.com/tkdave/bumpslide_as3
4 | *
5 | * Copyright (c) 2010 by Bumpslide, Inc.
6 | * http://www.bumpslide.com/
7 | *
8 | * This code is released under the open-source MIT license.
9 | * See LICENSE.txt for full license terms.
10 | * More info at http://www.opensource.org/licenses/mit-license.php
11 | */
12 | package com.bumpslide.ui.skin
13 | {
14 |
15 | import com.bumpslide.ui.Skin;
16 | import com.bumpslide.ui.Component;
17 | import com.bumpslide.ui.IResizable;
18 | import com.bumpslide.ui.ISkin;
19 | import com.bumpslide.ui.ISkinnable;
20 | import com.bumpslide.ui.Slider;
21 |
22 | import flash.display.MovieClip;
23 |
24 |
25 | /**
26 | * Movie Clip SliderSkin
27 | *
28 | * @author David Knape
29 | */
30 | public class BasicSliderSkin extends Skin implements ISkin
31 | {
32 |
33 | public var handle:MovieClip;
34 |
35 | public var background:MovieClip;
36 |
37 | /**
38 | * Best Practice: create a typed hostComponent getter for type safety
39 | */
40 | public function get hostComponent():Slider {
41 | return _hostComponent as Slider;
42 | }
43 |
44 |
45 | override public function initHostComponent( host_component:ISkinnable ):void
46 | {
47 | super.initHostComponent( host_component );
48 |
49 | if (hostComponent == null) {
50 | throw new Error( 'SliderSkin is meant to be used with a Slider component.' );
51 | }
52 |
53 | background.buttonMode = true;
54 | handle.buttonMode = true;
55 | handle.mouseChildren = false;
56 | }
57 |
58 |
59 | override protected function draw():void
60 | {
61 | drawBack();
62 | drawHandle();
63 | }
64 |
65 |
66 | /**
67 | * Draws the back of the slider.
68 | */
69 | protected function drawBack():void
70 | {
71 | if (background == null || hostComponent==null) return;
72 |
73 | if (background is IResizable) {
74 | (background as IResizable).setSize( hostComponent.width, hostComponent.height );
75 | } else {
76 | background.height = hostComponent.height;
77 | background.width = hostComponent.width;
78 | }
79 | }
80 |
81 |
82 | /**
83 | * Draws the handle of the slider.
84 | */
85 | protected function drawHandle():void
86 | {
87 | // trace('draw handle');
88 |
89 | if (handle == null || hostComponent==null) return;
90 |
91 | var hs:Number = hostComponent.getHandleSize();
92 | if (hostComponent.isVertical) {
93 | handle.height = hs;
94 | handle.width = hostComponent.width - hostComponent.padding.width;
95 | handle.x = hostComponent.padding.left;
96 | handle.y = hostComponent.getCalculatedHandlePosition();
97 | } else {
98 | handle.width = hs;
99 | handle.height = hostComponent.height - hostComponent.padding.height;
100 | handle.x = hostComponent.getCalculatedHandlePosition();
101 | handle.y = hostComponent.padding.top;
102 | }
103 | if (handle is Component) {
104 | Component( handle ).updateNow();
105 | }
106 | }
107 | }
108 | }
109 |
--------------------------------------------------------------------------------
/src/com/bumpslide/ui/skin/ImageButtonSkin.as:
--------------------------------------------------------------------------------
1 | /**
2 | * This code is part of the Bumpslide Library maintained by David Knape
3 | * Fork me at http://github.com/tkdave/bumpslide_as3
4 | *
5 | * Copyright (c) 2010 by Bumpslide, Inc.
6 | * http://www.bumpslide.com/
7 | *
8 | * This code is released under the open-source MIT license.
9 | * See LICENSE.txt for full license terms.
10 | * More info at http://www.opensource.org/licenses/mit-license.php
11 | */
12 |
13 | package com.bumpslide.ui.skin
14 | {
15 |
16 | import com.bumpslide.ui.Skin;
17 | import com.bumpslide.ui.Button;
18 | import com.bumpslide.ui.ISkinnable;
19 |
20 | import flash.display.Sprite;
21 |
22 | /**
23 | * ImageButtonSkin
24 | *
25 | * @author David Knape
26 | */
27 | public class ImageButtonSkin extends Skin
28 | {
29 |
30 | [Embed(source="/assets/button_bg.png",scaleGridTop="5", scaleGridLeft="5", scaleGridRight="35", scaleGridBottom="17")]
31 | private var embeddedImage:Class;
32 |
33 | private var background:Sprite;
34 |
35 | /**
36 | * Assume host component is a button
37 | */
38 | public function get hostComponent():Button {
39 | return _hostComponent as Button;
40 | }
41 |
42 | override protected function addChildren():void
43 | {
44 | addChild( background = new embeddedImage() );
45 | addChild( background );
46 | }
47 | override public function initHostComponent( host_component:ISkinnable ):void
48 | {
49 | super.initHostComponent( host_component );
50 | }
51 |
52 | override protected function draw():void
53 | {
54 | background.width = hostComponent.width;
55 | background.height = hostComponent.height;
56 | }
57 |
58 |
59 | public function _over():void
60 | {
61 | alpha = .8;
62 | }
63 |
64 |
65 | public function _off():void
66 | {
67 | alpha = 1.0;
68 | }
69 |
70 |
71 | public function _down():void
72 | {
73 | alpha = .8;
74 | }
75 |
76 |
77 | public function _disabled():void
78 | {
79 | alpha = .5;
80 | }
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/src/com/bumpslide/ui/skin/MovieClipSkin.as:
--------------------------------------------------------------------------------
1 | /**
2 | * This code is part of the Bumpslide Library maintained by David Knape
3 | * Fork me at http://github.com/tkdave/bumpslide_as3
4 | *
5 | * Copyright (c) 2010 by Bumpslide, Inc.
6 | * http://www.bumpslide.com/
7 | *
8 | * This code is released under the open-source MIT license.
9 | * See LICENSE.txt for full license terms.
10 | * More info at http://www.opensource.org/licenses/mit-license.php
11 | */
12 |
13 | package com.bumpslide.ui.skin
14 | {
15 |
16 | import com.bumpslide.ui.Component;
17 | import com.bumpslide.ui.IResizable;
18 | import com.bumpslide.ui.ISkin;
19 | import com.bumpslide.ui.ISkinnable;
20 | import com.bumpslide.util.Delegate;
21 |
22 | import flash.display.DisplayObject;
23 | import flash.display.MovieClip;
24 | import flash.events.Event;
25 |
26 | /**
27 | * Base class for MovieClip skins
28 | *
29 | * Each skin state should be represented as a frame in a movie clip
30 | * @author David Knape
31 | */
32 | dynamic public class MovieClipSkin extends MovieClip implements ISkin
33 | {
34 |
35 | protected var _host:ISkinnable;
36 |
37 | public function MovieClipSkin()
38 | {
39 | super();
40 | stop();
41 | }
42 |
43 |
44 |
45 | /**
46 | * When state changes, go to a new frame
47 | *
48 | * Override this behavior for more advanced skins that need transitions and such
49 | */
50 | public function renderSkin( skinState:String ):void
51 | {
52 | gotoAndStop(skinState);
53 |
54 | if(stage) {
55 | stage.addEventListener( Event.RENDER, handleStageRender );
56 | stage.invalidate();
57 | } else {
58 | Delegate.onEnterFrame( render );
59 | }
60 |
61 | // and render now just in case - silly flash
62 | render();
63 | }
64 |
65 | protected function handleStageRender( e:Event ):void
66 | {
67 | if(stage)
68 | stage.removeEventListener( Event.RENDER, handleStageRender );
69 | render();
70 | }
71 |
72 | /**
73 | * Called after a redraw
74 | *
75 | * During the draw phase we issue a gotoAndStop command. And, since
76 | * items on the stage are not yet accessible we have to wait for the next
77 | * render event before we can update the label text and background.
78 | *
79 | * This is the function that gets called just before the frame is rendered
80 | * and is a good place to programmatically affect any clips placed on the stage.
81 | */
82 | protected function render():void
83 | {
84 | autosizeBackground();
85 | }
86 |
87 |
88 | /**
89 | * If there is a skin part called 'background', size it to match the component
90 | *
91 | * If you don't want your background auto-sized, don't name it 'background'.
92 | */
93 | protected function autosizeBackground() : void
94 | {
95 | var background:DisplayObject = this['background'] as DisplayObject;
96 | // render background
97 | if(background != null) {
98 | if(background is IResizable) {
99 | (background as IResizable).setSize( hostComponent.width, hostComponent.height );
100 | } else {
101 | background.width = hostComponent.width;
102 | background.height = hostComponent.height;
103 | }
104 | }
105 | }
106 |
107 | public function initHostComponent( host:ISkinnable ):void
108 | {
109 | _host = host;
110 | }
111 |
112 |
113 | public function destroy( ):void
114 | {
115 | // bye bye
116 | }
117 |
118 |
119 | /**
120 | * code in movie clips can reference this.hostComponent
121 | * loosely typed for flexibility
122 | */
123 | public function get hostComponent():*
124 | {
125 | return _host;
126 | }
127 | }
128 | }
129 |
--------------------------------------------------------------------------------
/src/com/bumpslide/ui/skin/MovieClipSliderSkin.as:
--------------------------------------------------------------------------------
1 | /**
2 | * This code is part of the Bumpslide Library maintained by David Knape
3 | * Fork me at http://github.com/tkdave/bumpslide_as3
4 | *
5 | * Copyright (c) 2010 by Bumpslide, Inc.
6 | * http://www.bumpslide.com/
7 | *
8 | * This code is released under the open-source MIT license.
9 | * See LICENSE.txt for full license terms.
10 | * More info at http://www.opensource.org/licenses/mit-license.php
11 | */
12 |
13 | package com.bumpslide.ui.skin
14 | {
15 | import com.bumpslide.data.type.Padding;
16 | import com.bumpslide.ui.ISkinnable;
17 |
18 |
19 | /**
20 | * MovieClipSliderSkin
21 | *
22 | * @author David Knape
23 | */
24 | public class MovieClipSliderSkin extends BasicSliderSkin
25 | {
26 |
27 | override public function initHostComponent(host_component:ISkinnable):void
28 | {
29 | super.initHostComponent(host_component);
30 |
31 | // init padding based on position of handle on the stage
32 |
33 | var p:Padding = new Padding(handle.y, handle.x, handle.y, handle.x);
34 |
35 | if(hostComponent.isVertical) {
36 | p.right = hostComponent.width - handle.getBounds(this).right;
37 | } else {
38 | p.bottom = hostComponent.height - handle.getBounds(this).bottom;
39 | }
40 |
41 |
42 | hostComponent.padding = p;
43 | }
44 |
45 |
46 | override protected function drawBack():void
47 | {
48 | if(background) {
49 | if(hostComponent.isVertical) {
50 | background.height = height;
51 | } else {
52 | background.width = width;
53 | }
54 | }
55 | }
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/src/com/bumpslide/ui/skin/defaults/DefaultButtonSkin.as:
--------------------------------------------------------------------------------
1 | /**
2 | * This code is part of the Bumpslide Library maintained by David Knape
3 | * Fork me at http://github.com/tkdave/bumpslide_as3
4 | *
5 | * Copyright (c) 2010 by Bumpslide, Inc.
6 | * http://www.bumpslide.com/
7 | *
8 | * This code is released under the open-source MIT license.
9 | * See LICENSE.txt for full license terms.
10 | * More info at http://www.opensource.org/licenses/mit-license.php
11 | */
12 |
13 | package com.bumpslide.ui.skin.defaults
14 | {
15 |
16 | import com.bumpslide.ui.skin.BasicButtonSkin;
17 |
18 | /**
19 | * Default button skin with colors defined in Style constants
20 | *
21 | * @author David Knape
22 | */
23 | public class DefaultButtonSkin extends BasicButtonSkin
24 | {
25 |
26 | public function _off():void
27 | {
28 | backgroundBox.backgroundColor = Style.BUTTON_OFF;
29 | labelDisplay.textField.textColor = Style.BUTTON_LABEL;
30 | alpha = 1.0;
31 | }
32 |
33 |
34 | public function _over():void
35 | {
36 | backgroundBox.backgroundColor = Style.BUTTON_OVER;
37 | labelDisplay.textField.textColor = Style.BUTTON_LABEL_OVER;
38 | alpha = 1.0;
39 | }
40 |
41 |
42 | public function _down():void
43 | {
44 | backgroundBox.backgroundColor = Style.BUTTON_DOWN;
45 | labelDisplay.textField.textColor = Style.BUTTON_LABEL_OVER;
46 | alpha = 1.0;
47 | }
48 |
49 |
50 | public function _selected():void
51 | {
52 | backgroundBox.backgroundColor = Style.BUTTON_SELECTED;
53 | labelDisplay.textField.textColor = Style.BUTTON_LABEL_OVER;
54 | alpha = 1.0;
55 | }
56 |
57 |
58 | public function _disabled():void
59 | {
60 | backgroundBox.backgroundColor = Style.BUTTON_OFF;
61 | labelDisplay.textField.textColor = Style.BUTTON_LABEL;
62 | alpha = .5;
63 | }
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/src/com/bumpslide/ui/skin/defaults/DefaultCheckboxSkin.as:
--------------------------------------------------------------------------------
1 | /**
2 | * This code is part of the Bumpslide Library maintained by David Knape
3 | * Fork me at http://github.com/tkdave/bumpslide_as3
4 | *
5 | * Copyright (c) 2010 by Bumpslide, Inc.
6 | * http://www.bumpslide.com/
7 | *
8 | * This code is released under the open-source MIT license.
9 | * See LICENSE.txt for full license terms.
10 | * More info at http://www.opensource.org/licenses/mit-license.php
11 | */
12 | package com.bumpslide.ui.skin.defaults
13 | {
14 |
15 | import com.bumpslide.ui.ISkinnable;
16 | import com.bumpslide.ui.Label;
17 | import com.bumpslide.ui.Box;
18 | import com.bumpslide.ui.Component;
19 | import com.bumpslide.ui.PixelIcon;
20 | import com.bumpslide.util.Align;
21 | import com.bumpslide.util.DisplayUtil;
22 |
23 |
24 | /**
25 | * Button with a checkbox on it
26 | *
27 | * @author David Knape
28 | */
29 | public class DefaultCheckboxSkin extends DefaultButtonSkin
30 | {
31 | public var checkBox:Box;
32 | public var check:Component;
33 |
34 |
35 | override public function initHostComponent( host_component:ISkinnable ):void
36 | {
37 | super.initHostComponent( host_component );
38 |
39 | // hide the background (make it like the hit area)
40 | background.alpha = 0;
41 |
42 | checkBox = add( Box, Style.INPUT_BACKGROUND_PROPS );
43 |
44 | //checkBox = addChild( new Box( 0xcccccc, 16, 16, 0, 0, 0, 0 ) ) as Box;
45 | //checkBox.filters = [ Style.BEVEL_FILTER_INSET ];
46 |
47 | //addChild( check = new PixelIcon( [ '* *', ' * *', ' * ', ' * *', '* *' ] ) );
48 | addChild( check = new Label( 'X', Style.BUTTON_TEXT_FORMAT ) );
49 |
50 | _off();
51 | }
52 |
53 |
54 | override protected function draw():void
55 | {
56 | super.draw();
57 | if(!checkBox) return;
58 | checkBox.width = checkBox.height = background.height;
59 |
60 | Align.center( check, checkBox.width );
61 | Align.middle( check, checkBox.height );
62 | }
63 |
64 |
65 | override public function _off():void
66 | {
67 | checkBox.borderColor = Style.INPUT_BORDER;
68 | checkBox.backgroundColor = Style.INPUT_BACKGROUND;
69 | DisplayUtil.colorize( check, Style.BUTTON_LABEL );
70 | check.visible = false;
71 | }
72 |
73 |
74 | override public function _over():void
75 | {
76 | checkBox.borderColor = Style.INPUT_FOCUS_BORDER;
77 | checkBox.backgroundColor = Style.INPUT_FOCUS_BACKGROUND;
78 | check.visible = true;
79 | DisplayUtil.colorize( check, Style.BUTTON_LABEL_OVER );
80 | }
81 |
82 |
83 | override public function _selected():void
84 | {
85 | checkBox.borderColor = Style.INPUT_FOCUS_BORDER;
86 | checkBox.backgroundColor = Style.INPUT_BACKGROUND;
87 | check.visible = true;
88 | DisplayUtil.colorize( check, Style.BUTTON_LABEL );
89 | }
90 |
91 |
92 | override public function _down():void
93 | {
94 | checkBox.borderColor = Style.INPUT_FOCUS_BORDER;
95 | checkBox.backgroundColor = Style.INPUT_BACKGROUND;
96 | check.visible = true;
97 | DisplayUtil.colorize( check, Style.BUTTON_LABEL );
98 | }
99 | }
100 | }
101 |
--------------------------------------------------------------------------------
/src/com/bumpslide/ui/skin/defaults/DefaultComboBoxSkin.as:
--------------------------------------------------------------------------------
1 | /**
2 | * This code is part of the Bumpslide Library maintained by David Knape
3 | * Fork me at http://github.com/tkdave/bumpslide_as3
4 | *
5 | * Copyright (c) 2010 by Bumpslide, Inc.
6 | * http://www.bumpslide.com/
7 | *
8 | * This code is released under the open-source MIT license.
9 | * See LICENSE.txt for full license terms.
10 | * More info at http://www.opensource.org/licenses/mit-license.php
11 | */
12 | package com.bumpslide.ui.skin.defaults
13 | {
14 |
15 | import com.bumpslide.ui.Button;
16 | import com.bumpslide.ui.PixelIcon;
17 | import com.bumpslide.ui.Skin;
18 |
19 |
20 | /**
21 | * DefaultComboBoxSkin
22 | *
23 | * @author David Knape
24 | */
25 | public class DefaultComboBoxSkin extends Skin
26 | {
27 | public var arrowIcon:Array = [ '*****', ' ***', ' *' ];
28 | public var icon:PixelIcon;
29 | private var background:Button;
30 |
31 | override protected function addChildren():void
32 | {
33 | background = new Button( 100, 20, 0, 0, 'Select...' );
34 | icon = new PixelIcon( arrowIcon );
35 | addChild( icon );
36 | }
37 |
38 |
39 | protected function createBackground():void
40 | {
41 | if (background == null) {
42 | background = new Button();
43 | background.setSize( width, height );
44 | addChild( background );
45 |
46 | // we're in code-only mode, so draw an icon
47 | icon = new PixelIcon( [ '*****', ' ***', ' *' ] );
48 | addChild( icon );
49 | }
50 | }
51 |
52 |
53 | override public function renderSkin( skinState:String ):void
54 | {
55 | super.renderSkin( skinState );
56 | }
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/src/com/bumpslide/ui/skin/defaults/DefaultDatePickerSkin.as:
--------------------------------------------------------------------------------
1 | /**
2 | * This code is part of the Bumpslide Library maintained by David Knape
3 | * Fork me at http://github.com/tkdave/bumpslide_as3
4 | *
5 | * Copyright (c) 2010 by Bumpslide, Inc.
6 | * http://www.bumpslide.com/
7 | *
8 | * This code is released under the open-source MIT license.
9 | * See LICENSE.txt for full license terms.
10 | * More info at http://www.opensource.org/licenses/mit-license.php
11 | */
12 | package com.bumpslide.ui.skin.defaults
13 | {
14 |
15 | import com.bumpslide.ui.Button;
16 | import com.bumpslide.ui.DatePicker;
17 | import com.bumpslide.ui.Label;
18 | import com.bumpslide.ui.Skin;
19 | import com.bumpslide.util.DateUtil;
20 |
21 |
22 | /**
23 | * DefaultDatePickerSkin
24 | *
25 | * A click on anywhere on this skin will launch the calendar popup
26 | *
27 | * @author David Knape
28 | */
29 | public class DefaultDatePickerSkin extends Skin
30 | {
31 | // The calendar icon
32 | [Embed(source="/assets/calendar_icon2.png")]
33 | public var CalendarIcon:Class;
34 |
35 | private var dateLabel:Label;
36 | private var chooseButton:Button;
37 |
38 | public function get hostComponent():DatePicker {
39 | return _hostComponent as DatePicker;
40 | }
41 |
42 |
43 | override protected function addChildren():void
44 | {
45 | dateLabel = add( Label, { x:24, text:'Select a date...' } );
46 | chooseButton = add( Button, { width:21, height:21, icon:CalendarIcon } );
47 | }
48 |
49 |
50 | override protected function draw():void
51 | {
52 | super.draw();
53 | dateLabel.text = DateUtil.getFormatted( hostComponent.selectedDate, hostComponent.showTime, true, false, true, true );
54 | }
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/src/com/bumpslide/ui/skin/defaults/DefaultPanelSkin.as:
--------------------------------------------------------------------------------
1 | package com.bumpslide.ui.skin.defaults
2 | {
3 |
4 | import com.bumpslide.ui.Box;
5 | import com.bumpslide.ui.Panel;
6 | import com.bumpslide.ui.Skin;
7 |
8 | /**
9 | * The Panel Skin is really just the background skin
10 | *
11 | * @author David Knape
12 | */
13 | public class DefaultPanelSkin extends Skin
14 | {
15 |
16 | private var background:Box;
17 |
18 | public function get hostComponent():Panel {
19 | return _hostComponent as Panel;
20 | }
21 |
22 | override protected function addChildren() : void
23 | {
24 | background = add( Box, Style.PANEL_BACKGROUND );
25 | }
26 |
27 |
28 | override protected function draw() : void
29 | {
30 | if(background && hostComponent) {
31 | background.visible = hostComponent.backgroundVisible;
32 | background.setSize( width, height );
33 | }
34 | }
35 |
36 |
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/com/bumpslide/ui/skin/defaults/DefaultSliderSkin.as:
--------------------------------------------------------------------------------
1 | /**
2 | * This code is part of the Bumpslide Library maintained by David Knape
3 | * Fork me at http://github.com/tkdave/bumpslide_as3
4 | *
5 | * Copyright (c) 2010 by Bumpslide, Inc.
6 | * http://www.bumpslide.com/
7 | *
8 | * This code is released under the open-source MIT license.
9 | * See LICENSE.txt for full license terms.
10 | * More info at http://www.opensource.org/licenses/mit-license.php
11 | */
12 |
13 | package com.bumpslide.ui.skin.defaults
14 | {
15 |
16 | import com.bumpslide.ui.Box;
17 | import com.bumpslide.ui.Button;
18 | import com.bumpslide.ui.Panel;
19 | import com.bumpslide.ui.PixelIcon;
20 | import com.bumpslide.ui.skin.BasicSliderSkin;
21 |
22 | /**
23 | * DefaultSliderSkin
24 | *
25 | * @author David Knape
26 | */
27 | public class DefaultSliderSkin extends BasicSliderSkin
28 | {
29 | override protected function addChildren():void
30 | {
31 | //logEnabled = true;
32 |
33 | // Use panel to control padding around background art
34 | background = add( Box, Style.SLIDER_BACKGROUND_PROPS );
35 |
36 | handle = add( Panel, {
37 | padding: Style.SLIDER_BACKGROUND_PADDING,
38 | backgroundVisible: false,
39 | content: create( Button, {
40 | icon: new PixelIcon(" -, -,-, -, -,-, -, -,-", Style.BUTTON_LABEL)
41 | })
42 | });
43 | }
44 | }
45 | }
--------------------------------------------------------------------------------
/src/com/bumpslide/ui/skin/defaults/DefaultTextInputSkin.as:
--------------------------------------------------------------------------------
1 | /**
2 | * This code is part of the Bumpslide Library maintained by David Knape
3 | * Fork me at http://github.com/tkdave/bumpslide_as3
4 | *
5 | * Copyright (c) 2010 by Bumpslide, Inc.
6 | * http://www.bumpslide.com/
7 | *
8 | * This code is released under the open-source MIT license.
9 | * See LICENSE.txt for full license terms.
10 | * More info at http://www.opensource.org/licenses/mit-license.php
11 | */
12 | package com.bumpslide.ui.skin.defaults
13 | {
14 |
15 | import com.bumpslide.ui.Box;
16 | import com.bumpslide.ui.TextInput;
17 |
18 | import flash.text.TextField;
19 |
20 | import com.bumpslide.ui.Label;
21 | import com.bumpslide.ui.Skin;
22 |
23 |
24 | /**
25 | * Default Skin for TextInput Component
26 | *
27 | * @author David Knape
28 | */
29 | dynamic public class DefaultTextInputSkin extends Skin
30 | {
31 |
32 | private var background:Box;
33 |
34 | private var inputText:Label;
35 | private var hintText:Label;
36 |
37 | // Skin parts
38 | // (TextInput is just looking for the text fields)
39 | public var input_txt:TextField;
40 |
41 | public var hint_txt:TextField;
42 |
43 | public function get hostComponent():TextInput {
44 | return _hostComponent as TextInput;
45 | }
46 |
47 |
48 | override protected function addChildren():void
49 | {
50 | if (this['_background'] == null) {
51 | background = add( Box, Style.INPUT_BACKGROUND_PROPS );
52 | } else {
53 | background = this['_background'];
54 | }
55 | background.buttonMode = true;
56 |
57 | inputText = add( Label, { editable: true, maxLines: 1, selectable: true, padding: Style.INPUT_PADDING, textFormat: Style.INPUT_TEXT_FORMAT } );
58 | hintText = add( Label, { alpha: .5, maxLines: 1, padding: Style.INPUT_PADDING, textFormat: Style.INPUT_TEXT_FORMAT } );
59 |
60 | input_txt = inputText.textField;
61 | hint_txt = hintText.textField;
62 | }
63 |
64 |
65 | override protected function draw():void
66 | {
67 | if (hasChanged( VALID_SIZE )) {
68 | inputText.width = hostComponent.width;
69 | hintText.width = hostComponent.width;
70 | background.setSize( hostComponent.width, inputText.height );
71 | }
72 |
73 | input_txt.text = hostComponent.text;
74 | hint_txt.text = hostComponent.hintText;
75 | }
76 |
77 |
78 | override public function renderSkin( skinState:String ):void
79 | {
80 | super.renderSkin( skinState );
81 |
82 | input_txt.text = hostComponent.text;
83 | hint_txt.text = hostComponent.hintText;
84 | }
85 |
86 |
87 | public function _focused():void
88 | {
89 | hintText.visible = false;
90 | inputText.visible = true;
91 |
92 | background.backgroundColor = Style.INPUT_FOCUS_BACKGROUND;
93 | background.borderColor = Style.INPUT_FOCUS_BORDER;
94 | background.filters = [ Style.BEVEL_FILTER_INSET, Style.FOCUS_FILTER ];
95 | }
96 |
97 |
98 | public function _normal():void
99 | {
100 | hintText.color = Style.INPUT_TEXT_HINT;
101 | inputText.color = Style.INPUT_TEXT;
102 |
103 | hintText.bold = false;
104 | inputText.bold = false;
105 |
106 | hintText.visible = hostComponent.text == null || hostComponent.text.length == 0;
107 | inputText.visible = true;//!hintText.visible;
108 |
109 | background.backgroundColor = Style.INPUT_BACKGROUND;
110 | background.borderColor = Style.INPUT_BORDER;
111 | background.filters = [ Style.BEVEL_FILTER_INSET ];
112 | }
113 | }
114 | }
115 |
--------------------------------------------------------------------------------
/src/com/bumpslide/ui/skin/defaults/Style.as:
--------------------------------------------------------------------------------
1 | /**
2 | * This code is part of the Bumpslide Library maintained by David Knape
3 | * Fork me at http://github.com/tkdave/bumpslide_as3
4 | *
5 | * Copyright (c) 2010 by Bumpslide, Inc.
6 | * http://www.bumpslide.com/
7 | *
8 | * This code is released under the open-source MIT license.
9 | * See LICENSE.txt for full license terms.
10 | * More info at http://www.opensource.org/licenses/mit-license.php
11 | */
12 |
13 | package com.bumpslide.ui.skin.defaults
14 | {
15 |
16 | import flash.text.TextFormatAlign;
17 | import com.bumpslide.data.type.Padding;
18 |
19 | import flash.filters.BevelFilter;
20 | import flash.filters.BitmapFilter;
21 | import flash.filters.DropShadowFilter;
22 | import flash.text.TextFormat;
23 |
24 | /**
25 | * Style constants used by the default programmatic skins
26 | */
27 | public class Style
28 | {
29 | // default panel skin properties (background:Box)
30 | public static var PANEL_BACKGROUND:Object = {
31 | alpha: 0,
32 | backgroundColor: 0xeeeeee,
33 | cornerRadius: 0
34 | };
35 | public static var PANEL_PADDING:Number = 0;
36 |
37 | public static var SLIDER_BACKGROUND_PROPS:Object = {
38 | backgroundColor: 0xeeeeee,
39 | cornerRadius: 3,
40 | filters:[ BEVEL_FILTER_INSET ]
41 | };
42 |
43 | // Default Button Styles
44 | public static var BUTTON_OFF:uint = 0xDDDDDD;
45 | public static var BUTTON_OVER:uint = 0xDDEEFF;
46 | public static var BUTTON_DOWN:uint = 0xBBCCDD;
47 | public static var BUTTON_SELECTED:uint = 0xffdd99;
48 | public static var BUTTON_LABEL:uint = 0x333333;
49 | public static var BUTTON_LABEL_OVER:uint = 0x000000;
50 | public static var BUTTON_PADDING:* = "5 10";
51 | public static var BUTTON_TEXT_FORMAT:TextFormat = new TextFormat( 'Arial', 11, 0x333333, true, null, null, null, null, TextFormatAlign.CENTER);
52 | public static var BUTTON_BACKGROUND_PROPS:Object = {
53 | cornerRadius: 3,
54 | filters:[ BEVEL_FILTER ]
55 | };
56 |
57 | // Default Input Styles
58 | public static var INPUT_BORDER:uint = 0xDDDDDD;
59 | public static var INPUT_FOCUS_BORDER:uint = 0x999999;
60 | public static var INPUT_BACKGROUND:uint = 0xF8F8F8;
61 | public static var INPUT_FOCUS_BACKGROUND:uint = 0xFFFFFF;
62 | public static var INPUT_TEXT:uint = 0x333333;
63 | public static var INPUT_TEXT_HINT:uint = 666666;
64 | public static var INPUT_PADDING:* = "5 5 7 5";
65 | public static var INPUT_BACKGROUND_PROPS:Object = {
66 | cornerRadius: 0,
67 | borderWidth: 0,
68 | borderColor: INPUT_BORDER,
69 | filters:[ BEVEL_FILTER_INSET ]
70 | };
71 |
72 |
73 | // Default Label Text Format
74 | public static var LABEL_TEXT_FORMAT:TextFormat = new TextFormat('Arial', 11, 0x333333, true);
75 | public static var LABEL_FONT_EMBEDDED:Boolean = false;
76 |
77 | // Some Filters
78 | public static var FOCUS_FILTER:BitmapFilter = null; //new GlowFilter( 0xAAAAAA, 1, 2, 2, 10, 2);
79 | public static var BEVEL_FILTER:BitmapFilter = new BevelFilter(1.2, 45, 0xFFFFFF, .5, 0x000000, .5, 1.2, 1.2, 1, 2);
80 | public static var BEVEL_FILTER_INSET:BitmapFilter = new BevelFilter(1.4, 225, 0xDDDDDD, .5, 0x333333, .5, 1.4, 1.4, 1, 2, 'inner');
81 | public static var DROPSHADOW_FILTER:BitmapFilter = new DropShadowFilter(2, 45, 0, .3, 6, 6, 1, 2);
82 |
83 | public static var SCROLLBAR_GAP:Number = 4;
84 | public static var SCROLLBAR_WIDTH:Number = 20;
85 | public static var SLIDER_BACKGROUND_PADDING:* = "2 2";
86 |
87 | public static var BORDER_PIXEL_HINTING:Boolean = true;
88 |
89 | public static var INPUT_TEXT_FORMAT:TextFormat = new TextFormat('Arial', 11, 0x333333, false );
90 |
91 |
92 |
93 |
94 | }
95 | }
--------------------------------------------------------------------------------
/src/com/bumpslide/ui/skin/touch/TouchScrollSkin.as:
--------------------------------------------------------------------------------
1 | package com.bumpslide.ui.skin.touch
2 | {
3 |
4 | import com.bumpslide.ui.Panel;
5 | import com.bumpslide.ui.Box;
6 | import com.bumpslide.ui.skin.BasicSliderSkin;
7 |
8 |
9 | /**
10 | * TouchScrollSkin
11 | *
12 | * @author David Knape
13 | */
14 | public class TouchScrollSkin extends BasicSliderSkin
15 | {
16 | private var handleShape : Box;
17 |
18 |
19 | override protected function addChildren():void
20 | {
21 | //logEnabled = true;
22 |
23 | // Use panel to control padding around background art
24 | background = add( Box, { backgroundAlpha: 0, cacheAsBitmap:true });
25 |
26 | handleShape = new Box( 0x888888 );
27 | handleShape.borderPixelHinting = true;
28 |
29 | handle = new Panel( handleShape, "2 1", 0x000000, 0);
30 | handle.cacheAsBitmap = true;
31 |
32 | addChild( handle );
33 | }
34 |
35 | public function set handleColor( c:uint ):void {
36 | handleShape.backgroundColor = c;
37 | }
38 |
39 | override protected function draw():void
40 | {
41 |
42 | if(hostComponent && hasChanged(VALID_SIZE)) {
43 | handleShape.cornerRadius = hostComponent.isVertical ? hostComponent.width / 2 : hostComponent.height / 2;
44 | }
45 |
46 | super.draw();
47 |
48 |
49 | }
50 |
51 |
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/src/com/bumpslide/util/ActivityMonitor.as:
--------------------------------------------------------------------------------
1 | /**
2 | * This code is part of the Bumpslide Library maintained by David Knape
3 | * Fork me at http://github.com/tkdave/bumpslide_as3
4 | *
5 | * Copyright (c) 2010 by Bumpslide, Inc.
6 | * http://www.bumpslide.com/
7 | *
8 | * This code is released under the open-source MIT license.
9 | * See LICENSE.txt for full license terms.
10 | * More info at http://www.opensource.org/licenses/mit-license.php
11 | */
12 |
13 | package com.bumpslide.util {
14 | import flash.events.TimerEvent;
15 | import flash.events.Event;
16 | import flash.events.KeyboardEvent;
17 | import flash.events.MouseEvent;
18 | import flash.display.InteractiveObject;
19 | import flash.utils.Timer;
20 | import flash.events.EventDispatcher;
21 |
22 | /**
23 | * Monitors mouse and keyboard activity to determine when a user is idle.
24 | *
25 | * @author David Knape
26 | */
27 | public class ActivityMonitor extends EventDispatcher {
28 |
29 | static public var EVENT_IDLE:String = "onAmericanIdle";
30 | private var _timeoutSecs:uint;
31 | private var _timer:Timer;
32 | private var _stage:InteractiveObject;
33 | public var debugEnabled:Boolean=false;
34 |
35 | public var timeStart:Number;
36 | public var timeEnd:Number;
37 |
38 | function ActivityMonitor(stage:InteractiveObject, timeoutSeconds:uint = 90) {
39 | _timeoutSecs = timeoutSeconds;
40 | _timer = new Timer(_timeoutSecs*1000, 1);
41 | _timer.addEventListener(TimerEvent.TIMER, timeoutHandler);
42 | _stage = stage;
43 | }
44 |
45 | public function start():void {
46 | debug('start');
47 | timeStart = new Date().time;
48 | _timer.reset();
49 | _timer.start();
50 | _stage.addEventListener(MouseEvent.MOUSE_UP, uiEventHandler);
51 | _stage.addEventListener(MouseEvent.MOUSE_DOWN, uiEventHandler);
52 | _stage.addEventListener(MouseEvent.MOUSE_MOVE, uiEventHandler);
_stage.addEventListener(KeyboardEvent.KEY_UP, uiEventHandler);
53 | _stage.addEventListener(KeyboardEvent.KEY_DOWN, uiEventHandler);
54 | }
55 |
56 | public function stop():void {
57 | debug('stop');
58 | _timer.stop();
59 | _stage.removeEventListener(MouseEvent.MOUSE_UP, uiEventHandler);
60 | _stage.removeEventListener(MouseEvent.MOUSE_DOWN, uiEventHandler);
_stage.removeEventListener(MouseEvent.MOUSE_MOVE, uiEventHandler);
61 | _stage.removeEventListener(KeyboardEvent.KEY_UP, uiEventHandler);
62 | _stage.removeEventListener(KeyboardEvent.KEY_DOWN, uiEventHandler);
63 | }
64 |
65 | protected function uiEventHandler(e:Event = null):void {
66 | debug('noticed event: ' + e.type );
67 | _timer.reset();
68 | _timer.start();
69 |
70 | // update session end time every time
71 | timeEnd = new Date().time;
72 | }
73 |
74 |
75 |
76 | private function timeoutHandler(event:TimerEvent):void {
77 | debug('User has been idle for '+_timeoutSecs+' seconds.');
78 | _timer.stop();
79 | _timer.reset();
80 |
81 | // use timeout as final ending time
82 | //timeEnd = new Date().time;
83 |
84 | dispatchEvent(new Event(EVENT_IDLE));
85 | }
86 |
87 | /**
88 | * Time spent interacting with the display in milliseconds
89 | */
90 | public function getTimeSpent():Number {
91 | return timeEnd - timeStart;
92 | }
93 |
94 | private function debug(s:String) : void {
95 | if(debugEnabled) trace( '[IdleTracker] '+ s);
96 | }
97 | }
98 | }
99 |
--------------------------------------------------------------------------------
/src/com/bumpslide/util/ArrayUtil.as:
--------------------------------------------------------------------------------
1 | /**
2 | * This code is part of the Bumpslide Library maintained by David Knape
3 | * Fork me at http://github.com/tkdave/bumpslide_as3
4 | *
5 | * Copyright (c) 2010 by Bumpslide, Inc.
6 | * http://www.bumpslide.com/
7 | *
8 | * This code is released under the open-source MIT license.
9 | * See LICENSE.txt for full license terms.
10 | * More info at http://www.opensource.org/licenses/mit-license.php
11 | */
12 |
13 | package com.bumpslide.util {
14 |
/**
15 | * @author David Knape
16 | */
17 | public class ArrayUtil {
18 |
19 | /**
20 | * Shuffles an array (modifies original)
21 | */
22 | static public function shuffle( a:Array ):void {
23 | var len:uint = a.length;
24 | var n:uint;
25 | var i:uint;
26 | var el:*;
27 | for (i=0; i 5) {
46 | str += "...recusion_limit..." + "\n";
47 | return;
48 | }
49 | n++;
50 | var type:String = describeType(o).@name;
51 | if(type == 'Array') {
52 | dumpArray(o);
53 | } else if (type == 'Object') {
54 | dumpObject(o);
55 | } else {
56 | appendStr(o);
57 | }
58 | n--;
59 | }
60 |
61 | private static function appendStr(s:Object):void {
62 | str += s + '\n';
63 | }
64 |
65 | private static function dumpArray(a:Object):void {
66 | var type:String;
67 | for (var i:String in a) {
68 | type = describeType(a[i]).@name;
69 | if (type == 'Array' || type == 'Object') {
70 | appendStr(getSpaces() + "[" + i + "]:");
71 | dump(a[i]);
72 | } else {
73 | appendStr(getSpaces() + "[" + i + "]:" + a[i]);
74 | }
75 | }
76 | }
77 |
78 | private static function dumpObject(o:Object):void {
79 | var type:String;
80 | for (var i:String in o) {
81 | if (type == 'Array' || type == 'Object') {
82 | appendStr(getSpaces() + i + ":");
83 | dump(o[i]);
84 | } else {
85 | appendStr(getSpaces() + i + ":" + o[i]);
86 | }
87 | }
88 | }
89 |
90 | private static function getSpaces():String {
91 | var s:String = "";
92 | for(var i:int = 1;i < n; i++) {
93 | s += " ";
94 | }
95 | return s;
96 | }
97 | }
98 | }
--------------------------------------------------------------------------------
/src/com/bumpslide/util/KeyTracker.as:
--------------------------------------------------------------------------------
1 | /**
2 | * This code is part of the Bumpslide Library maintained by David Knape
3 | * Fork me at http://github.com/tkdave/bumpslide_as3
4 | *
5 | * Copyright (c) 2010 by Bumpslide, Inc.
6 | * http://www.bumpslide.com/
7 | *
8 | * This code is released under the open-source MIT license.
9 | * See LICENSE.txt for full license terms.
10 | * More info at http://www.opensource.org/licenses/mit-license.php
11 | */
12 | package com.bumpslide.util
13 | {
14 |
15 | import flash.display.Stage;
16 | import flash.events.EventDispatcher;
17 | import flash.events.KeyboardEvent;
18 |
19 | /**
20 | * Provides AS2-style isDown function.
21 | *
22 | * @author David Knape
23 | */
24 | public class KeyTracker extends EventDispatcher
25 | {
26 |
27 | private static var stage:Stage;
28 |
29 | private static var initialized:Boolean;
30 |
31 | private static var pressedKeys:Object;
32 |
33 | static public function init( stage:Stage ):void
34 | {
35 | if (KeyTracker.initialized) return;
36 | KeyTracker.stage = stage;
37 | KeyTracker.initialized = true;
38 | pressedKeys = new Object();
39 | stage.addEventListener( KeyboardEvent.KEY_DOWN, keyPressed, false, 999 );
40 | stage.addEventListener( KeyboardEvent.KEY_UP, keyReleased, false, 999 );
41 | }
42 |
43 |
44 | public function cancel():void
45 | {
46 | stage.removeEventListener( KeyboardEvent.KEY_DOWN, keyPressed );
47 | stage.removeEventListener( KeyboardEvent.KEY_UP, keyReleased );
48 | pressedKeys = new Object();
49 | KeyTracker.stage = null;
50 | }
51 |
52 |
53 | public static function isDown( keycode:uint ):Boolean
54 | {
55 | return Boolean( keycode in pressedKeys );
56 | }
57 |
58 |
59 | public static function isLetterDown( letter:String ):Boolean
60 | {
61 | return isDown( letter.toUpperCase().charCodeAt( 0 ) ) || isDown( letter.toLowerCase().charCodeAt( 0 ) );
62 | }
63 |
64 |
65 | static private function keyPressed( evt:KeyboardEvent ):void
66 | {
67 | // trace('[KeyTracker] pressed key ' + evt.keyCode);
68 | pressedKeys[evt.keyCode] = true;
69 | }
70 |
71 |
72 | static private function keyReleased( evt:KeyboardEvent ):void
73 | {
74 | delete pressedKeys[evt.keyCode];
75 | }
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/src/com/bumpslide/util/MacMouseWheel.as:
--------------------------------------------------------------------------------
1 | /**
2 | * This code is part of the Bumpslide Library maintained by David Knape
3 | * Fork me at http://github.com/tkdave/bumpslide_as3
4 | *
5 | * Copyright (c) 2010 by Bumpslide, Inc.
6 | * http://www.bumpslide.com/
7 | *
8 | * This code is released under the open-source MIT license.
9 | * See LICENSE.txt for full license terms.
10 | * More info at http://www.opensource.org/licenses/mit-license.php
11 | */
12 |
13 | package com.bumpslide.util {
import flash.system.Capabilities;
import flash.display.InteractiveObject;
import flash.display.Stage;
import flash.events.MouseEvent;
import flash.external.ExternalInterface;
/**
* Class that supports using the mouseWheel on Mac OS, requires javascript class
* swfmacmousewheel.js
*
* This is a copy of com.pixelbreaker.ui.osx.MacMouseWheel distributed without permission.
* Gabriel does great work. You should check out his site.
*
* http://blog.pixelbreaker.com/flash/as30-mousewheel-on-mac-os-x/
*
* @author Gabriel Bucknall
*/
public class MacMouseWheel
{
private static var instance:MacMouseWheel;
private var _stage:Stage;
private var _currItem:InteractiveObject;
private var _clonedEvent:MouseEvent;
public static function getInstance():MacMouseWheel
{
if (instance == null) instance = new MacMouseWheel( new SingletonEnforcer() );
return instance;
}
public function MacMouseWheel( enforcer:SingletonEnforcer )
{
}
/*
* Initialize the MacMouseWheel class
*
* @param stage Stage instance e.g DocumentClass.stage
*
*/
public static function setup( stage:Stage ):void
{
var isMac:Boolean = Capabilities.os.toLowerCase().indexOf( "mac" ) != -1;
if( isMac ) getInstance()._setup( stage );
}
private function _setup( stage:Stage ):void
{
_stage = stage;
_stage.addEventListener( MouseEvent.MOUSE_MOVE, _getItemUnderCursor );
if( ExternalInterface.available )
{
try {
ExternalInterface.addCallback( 'externalMouseEvent', _externalMouseEvent );
} catch (e:Error) {}
}
}
private function _getItemUnderCursor( e:MouseEvent ):void
{
_currItem = InteractiveObject( e.target );
_clonedEvent = MouseEvent( e );
}
private function _externalMouseEvent( delta:Number ):void
{
var wheelEvent:MouseEvent = new MouseEvent(
MouseEvent.MOUSE_WHEEL,
true,
false,
_clonedEvent.localX,
_clonedEvent.localY,
_clonedEvent.relatedObject,
_clonedEvent.ctrlKey,
_clonedEvent.altKey,
_clonedEvent.shiftKey,
_clonedEvent.buttonDown,
int( delta )
);
_currItem.dispatchEvent( wheelEvent );
}
}
}
internal class SingletonEnforcer{}
--------------------------------------------------------------------------------
/src/com/bumpslide/util/Num.as:
--------------------------------------------------------------------------------
1 | package com.bumpslide.util {
2 |
3 | /*
4 | * Number utilities from Zach Archer
5 | *
6 | * @author Zach Archer, http://zacharcher.com/
7 | */
8 | public class Num {
9 |
10 | // progress = (0.0...1.0)
11 | public static function interpolate( min:Number, max:Number, progress:Number ) :Number {
12 | return( (1-progress)*min + progress*max );
13 | }
14 |
15 | public static function isWithin( subject:Number, left:Number, right:Number ) :Boolean {
16 | return (left <= subject && subject <= right);
17 | }
18 | public static function isBetween( subject:Number, left:Number, right:Number ) :Boolean {
19 | return (left < subject && subject < right);
20 | }
21 |
22 | // Math.pow: If x is negative, and exponent is not an integer, returns NaN. (Based on the
23 | // unfortunate fact that it doesn't know how to flip the sign.)
24 | // This function always returns a positive value that conforms to the expected Exponent
25 | // curve. (see: http://en.wikipedia.org/wiki/Exponent )
26 | public static function powAbs( x:Number, exponent:Number ) :Number {
27 | if( x >= 0 ) {
28 | return Math.pow( x, exponent );
29 | } else {
30 | return Math.pow( Math.abs(x), 1/exponent );
31 | }
32 | }
33 |
34 | //
35 | // DSP SIGNAL PROCESSING
36 | //
37 |
38 | // Converts a 'unipolar' signal (0.0...1.0) to 'bipolar' (-1.0...1.0), and the reverse
39 | public static function uni2bi( n:Number ) :Number {
40 | return (n*2.0) - 1.0;
41 | }
42 | public static function bi2uni( n:Number ) :Number {
43 | return (n+1.0) / 2.0;
44 | }
45 |
46 | // Restrict a value between upper and lower limits
47 | public static function clamp( signal:Number, min:Number, max:Number ) :Number {
48 | return Math.max( min, Math.min( max, signal ) );
49 | }
50 |
51 | // Quantize a signal (0.0...1.0) to a limited output set of "steps"
52 | public static function quantize( signal:Number, steps:Number ) :Number {
53 | return Math.floor( signal * steps ) / (steps+1);
54 | }
55 |
56 | // Wrap a signal between 0..height.
57 | // Different from modulo because negative numbers will wrap upwards and become positive.
58 | public static function wrap( signal:Number, height:Number ) :Number {
59 | return signal - (Math.floor( signal / height ) * height);
60 | }
61 |
62 | }
63 |
64 | }
65 |
--------------------------------------------------------------------------------
/src/com/bumpslide/util/ObjectPool.as:
--------------------------------------------------------------------------------
1 | /**
2 | * This code is part of the Bumpslide Library maintained by David Knape
3 | * Fork me at http://github.com/tkdave/bumpslide_as3
4 | *
5 | * Copyright (c) 2010 by Bumpslide, Inc.
6 | * http://www.bumpslide.com/
7 | *
8 | * This code is released under the open-source MIT license.
9 | * See LICENSE.txt for full license terms.
10 | * More info at http://www.opensource.org/licenses/mit-license.php
11 | */
12 |
13 | package com.bumpslide.util
14 | {
15 |
16 | /**
17 | * ObjectPool
18 | *
19 | * @author David Knape
20 | * @version SVN: $Id: $
21 | */
22 | public class ObjectPool extends Object
23 | {
24 |
25 | private var _pool:Array;
26 | private var _objClass:Class;
27 | private var _maxPoolSize:uint = 5000;
28 |
29 | public function ObjectPool( objectClass:Class, initialPoolSize:uint=10, maxPoolSize:uint=5000)
30 | {
31 | _objClass = objectClass;
32 | _maxPoolSize = maxPoolSize;
33 | _pool = new Array();
34 | for(var n:uint=0; n0) {
42 | obj = _pool.pop();
43 | } else {
44 | obj = new _objClass();
45 | }
46 | if(defaultProperties!=null) {
47 | for(var prop:String in defaultProperties) {
48 | obj[prop] = defaultProperties[prop];
49 | }
50 | }
51 | return obj;
52 | }
53 |
54 | public function releaseObject( obj:* ):* {
55 | if(_pool.length<_maxPoolSize) {
56 | _pool.push( obj );
57 | }
58 | return obj;
59 | }
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/src/com/bumpslide/util/ObjectUtil.as:
--------------------------------------------------------------------------------
1 | /**
2 | * This code is part of the Bumpslide Library maintained by David Knape
3 | * Fork me at http://github.com/tkdave/bumpslide_as3
4 | *
5 | * Copyright (c) 2010 by Bumpslide, Inc.
6 | * http://www.bumpslide.com/
7 | *
8 | * This code is released under the open-source MIT license.
9 | * See LICENSE.txt for full license terms.
10 | * More info at http://www.opensource.org/licenses/mit-license.php
11 | */
12 |
13 | package com.bumpslide.util
{
import flash.net.registerClassAlias;
import flash.utils.ByteArray;
import flash.utils.Dictionary;
import flash.utils.Proxy;
import flash.utils.getDefinitionByName;
import flash.utils.getQualifiedClassName;
/**
* Object cloning and comparison utilities
*
* This code was inspired by and borrowed from the
* Flight Framework Type utility.
*
* @author David Knape
*/
public class ObjectUtil
{
private static var registeredTypes:Dictionary = new Dictionary();
public static function create( classs:Class, initialProperties:Object = null):*
{
var obj:* = new classs();
return ObjectUtil.mergeProperties( initialProperties, obj );
}
public static function equals(value1:Object, value2:Object):Boolean
{
if(value1 == value2) {
return true;
}
if(value1 == null || value2 == null) {
return false;
}
ObjectUtil.registerType(value1);
var so1:ByteArray = new ByteArray();
so1.writeObject(value1);
var so2:ByteArray = new ByteArray();
so2.writeObject(value2);
return Boolean(so1.toString() == so2.toString());
}
public static function clone(value:Object):Object
{
if(value == null) return null;
ObjectUtil.registerType(value);
var so:ByteArray = new ByteArray();
so.writeObject(value);
so.position = 0;
return so.readObject();
}
/**
* Registers the class alias for this object so it can be
* cloned and compared as a byteArray
*/
public static function registerType(value:Object):Boolean
{
if( !(value is Class) ) {
value = getType(value);
}
if(!registeredTypes[value]) {
// no need to register a class more than once
registeredTypes[value] = registerClassAlias(getQualifiedClassName(value).split("::").join("."), value as Class);
}
return true;
}
/**
* Get the class name for an object
*/
public static function getType(value:Object):Class
{
if (value is Class) {
return value as Class;
} else if(value is Proxy) {
return getDefinitionByName(getQualifiedClassName(value)) as Class;
} else {
return value.constructor as Class;
}
}
/**
* Merge properties from source into target
*
* Assumes source is an object with enumerable properties
*/
public static function mergeProperties( source:*, target:*, merge_props:Array=null, not_props:Array=null ):*
{
if(source != null && target != null)
14 |
15 | var prop:String;
16 |
17 | if(merge_props && merge_props.length) {
18 | for each( prop in merge_props ) {
19 | try {
20 | target[prop] = source[prop];
21 | } catch (er:Error) {
22 | //trace( e, e.getStackTrace() );
23 | }
24 | }
25 | } else {
26 |
for( prop in source ) {
27 | if(not_props==null || -1==not_props.indexOf( prop )) {
try {
target[prop] = source[prop];
} catch (er:Error) {
//trace( e, e.getStackTrace() );
}
28 | }
29 |
}
30 | }
return target;
}
}
}
--------------------------------------------------------------------------------
/src/com/bumpslide/view/BasicView.as:
--------------------------------------------------------------------------------
1 | /**
2 | * This code is part of the Bumpslide Library maintained by David Knape
3 | * Fork me at http://github.com/tkdave/bumpslide_as3
4 | *
5 | * Copyright (c) 2010 by Bumpslide, Inc.
6 | * http://www.bumpslide.com/
7 | *
8 | * This code is released under the open-source MIT license.
9 | * See LICENSE.txt for full license terms.
10 | * More info at http://www.opensource.org/licenses/mit-license.php
11 | */
12 |
13 | package com.bumpslide.view
14 | {
15 |
16 | import com.bumpslide.events.ViewChangeEvent;
17 | import com.bumpslide.tween.FTween;
18 | import com.bumpslide.ui.Component;
19 |
20 | /**
21 | * Abstract Transitionable View
22 | *
23 | * Extend this class with custom transitions in your app.
24 | * See example implementation at the bottom of this file.
25 | *
26 | * @author David Knape
27 | */
28 | public class BasicView extends Component implements IView {
29 |
30 |
31 | protected var _viewState:String = ViewState.INACTIVE;
32 |
33 | public var transitionsEnabled:Boolean = true;
34 |
35 | public function transitionIn():void {
36 | _viewState = ViewState.TRANSITIONING_IN;
37 | dispatchEvent( new ViewChangeEvent( ViewChangeEvent.TRANSITION_IN ) );
38 | if(transitionsEnabled) doTransitionIn();
39 | else transitionInComplete();
40 | }
41 |
42 |
43 | protected function doTransitionIn():void
44 | {
45 | FTween.fadeIn( this, 0, .2, transitionInComplete );
46 | }
47 |
48 | public function transitionOut():void {
49 | _viewState = ViewState.TRANSITIONING_OUT;
50 | dispatchEvent( new ViewChangeEvent( ViewChangeEvent.TRANSITION_OUT ) );
51 | if(transitionsEnabled) doTransitionOut();
52 | else transitionOutComplete();
53 | }
54 |
55 |
56 | protected function doTransitionOut():void
57 | {
58 | FTween.fadeOut( this, 0, .5, transitionOutComplete );
59 | }
60 |
61 | protected function transitionOutComplete() : void {
62 | log('transition out complete');
63 | _viewState = ViewState.INACTIVE;
64 | dispatchEvent( new ViewChangeEvent( ViewChangeEvent.TRANSITION_OUT_COMPLETE ) );
65 | destroy();
66 | }
67 |
68 | protected function transitionInComplete() : void {
69 | if(_viewState==ViewState.TRANSITIONING_OUT) return;
70 | _viewState = ViewState.ACTIVE;
71 | dispatchEvent( new ViewChangeEvent( ViewChangeEvent.TRANSITION_IN_COMPLETE ) );
72 | }
73 |
74 | public function get viewState():String {
75 | return _viewState;
76 | }
77 |
78 |
79 | override public function destroy():void
80 | {
81 | super.destroy();
82 | FTween.stopTweening(this);
83 | }
84 | }
85 | }
86 |
87 | //package app {
88 | // import com.bumpslide.ui.AbstractView;
89 | // import com.bumpslide.tween.FTween;
90 | //
91 | // /**
92 | // * Example View Implementation
93 | // */
94 | // public class AppView extends BasicView {
95 | //
96 | // override public function doTransitionIn():void {
97 | // FTween.fadeIn( this, 0, .2, transitionInComplete );
98 | // }
99 | //
100 | // override public function doTransitionOut():void {
101 | // FTween.fadeOut( this, 0, .5, transitionOutComplete );
102 | // }
103 | // }
104 | //}
105 |
--------------------------------------------------------------------------------
/src/com/bumpslide/view/IView.as:
--------------------------------------------------------------------------------
1 | /**
* This code is part of the Bumpslide Library maintained by David Knape
* Fork me at http://github.com/tkdave/bumpslide_as3
*
* Copyright (c) 2010 by Bumpslide, Inc.
* http://www.bumpslide.com/
*
* This code is released under the open-source MIT license.
* See LICENSE.txt for full license terms.
* More info at http://www.opensource.org/licenses/mit-license.php
*/
package com.bumpslide.view {
import flash.events.IEventDispatcher;
/**
* Represents a page views that has transitions
*
* This interface is similar to the Gaia Framework IPage.
*
*
* @see com.bumpslide.view.ViewStack
* @see com.bumpslide.view.ViewLoader
*
* @author David Knape
*/
public interface IView extends IEventDispatcher {
/**
* Transition in and update views state accordingly
*/
function transitionIn():void;
/**
* Transition out and update views state accordingly
*/
function transitionOut():void;
/**
* Current views state
*
* Should be one of the constants defined in com.bumpslide.views.ViewState
*/
function get viewState():String;
}
}
--------------------------------------------------------------------------------
/src/com/bumpslide/view/ViewStack.as:
--------------------------------------------------------------------------------
1 | /**
* This code is part of the Bumpslide Library maintained by David Knape
* Fork me at http://github.com/tkdave/bumpslide_as3
*
* Copyright (c) 2010 by Bumpslide, Inc.
* http://www.bumpslide.com/
*
* This code is released under the open-source MIT license.
* See LICENSE.txt for full license terms.
* More info at http://www.opensource.org/licenses/mit-license.php
*/
package com.bumpslide.view {
import com.bumpslide.ui.IResizable;
import com.bumpslide.view.ViewLoader;
import flash.display.DisplayObject;
[DefaultProperty("dataProvider")]
/**
* A stack of views that can be selected by index.
*
* Views are stored as class references and are
* re-instantiated each time they are needed.
*
* ViewStacks can contain IViews or any display object.
* Be sure to implement destroy on your views so that
* things can get properly cleaned up and garbage
* collected.
*
* Update Oct. 2010: dataProvider can now holder display objects
* as well as class references. These objects will get
* reused each time.
*
* @author David Knape
*/
public class ViewStack extends ViewLoader {
protected var _selectedIndex:int=0;
protected var _dataProvider:Array = [];
/**
* Create a views stack using passed in array as the dataProvider
*/
public function ViewStack( views:Array=null ) {
if(views==null) views=[];
super();
dataProvider = views;
}
public function get selectedIndex():int {
return _selectedIndex;
}
public function set selectedIndex(selectedIndex:int):void {
log('selectedIndex='+selectedIndex );
if(_selectedIndex==selectedIndex) return;
_selectedIndex = selectedIndex;
invalidate( VALID_VIEW );
}
public function get dataProvider():Array {
return _dataProvider;
}
/**
* Array of classes and/or display objects
*/
public function set dataProvider(dataProvider:Array):void {
_dataProvider = dataProvider;
invalidate( VALID_VIEW );
}
override protected function initView():void {
// selected index of -1 means show nothing
if(selectedIndex==-1) {
log('initView failed (selectedIndex=-1)');
return;
}
var view:* = dataProvider[ selectedIndex ];
var obj:DisplayObject;
if(view is Class) {
obj = new view();
} else if(view is DisplayObject){
obj = view;
}
// If object is not an IView, wrap it with the component wrapper
if(obj is IView) {
currentView = obj as IView;
} else if (obj is DisplayObject){
var wrapper:ComponentView = new ComponentView();
wrapper.content = obj;
currentView = wrapper;
}
if(currentView!=null) {
if(currentView is IResizable) {
(currentView as IResizable).setSize( width, height );
}
if(currentView is DisplayObject) {
addChild( currentView as DisplayObject );
}
}
log( 'initView() currentView=' + currentView );
sendChangeEvent( 'selectedIndex', selectedIndex );
}
}
}
--------------------------------------------------------------------------------
/src/com/bumpslide/view/ViewState.as:
--------------------------------------------------------------------------------
1 | /**
2 | * This code is part of the Bumpslide Library maintained by David Knape
3 | * Fork me at http://github.com/tkdave/bumpslide_as3
4 | *
5 | * Copyright (c) 2010 by Bumpslide, Inc.
6 | * http://www.bumpslide.com/
7 | *
8 | * This code is released under the open-source MIT license.
9 | * See LICENSE.txt for full license terms.
10 | * More info at http://www.opensource.org/licenses/mit-license.php
11 | */
12 |
13 | package com.bumpslide.view
14 | {
15 | /**
16 | * ViewState constants
17 | *
18 | * @author David Knape
19 | * @version SVN: $Id: ViewState.as 194 2010-01-28 19:29:17Z tkdave $
20 | */
21 | public class ViewState
22 | {
23 |
24 | /**
25 | * Transitioning out
26 | *
27 | * Should be set as transition out begins
28 | */
29 | public static const TRANSITIONING_OUT:String = "transOut";
30 |
31 | /**
32 | * Transitioning In
33 | *
34 | * Should be set as transition in begins
35 | */
36 | public static const TRANSITIONING_IN:String = "transIn";
37 |
38 | /**
39 | * Component is currently active
40 | *
41 | * Should be set when transition in is complete
42 | */
43 | public static const ACTIVE:String = "active";
44 |
45 | /**
46 | * Component is not active
47 | *
48 | * Should be set when transition out is complete
49 | */
50 | public static const INACTIVE:String = "inactive";
51 |
52 |
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/fl/events/DataChangeType.as:
--------------------------------------------------------------------------------
1 | // Copyright 2007. Adobe Systems Incorporated. All Rights Reserved.
2 | package fl.events {
3 |
4 | /**
5 | * The DataChangeType class defines constants for the DataChangeEvent.changeType
6 | * event. These constants are used by the DataChangeEvent class to identify the type
7 | * of change that was applied to the data in a list-based component such as a List, ComboBox,
8 | * TileList, or DataGrid.
9 | *
10 | * @see DataChangeEvent#changeType
11 | *
12 | * @langversion 3.0
13 | * @playerversion Flash 9.0.28.0
14 | */
15 | public class DataChangeType {
16 |
17 | /**
18 | * A change was made to the component data. This value does not affect the
19 | * component data that it describes.
20 | *
21 | * @eventType change
22 | *
23 | * @langversion 3.0
24 | * @playerversion Flash 9.0.28.0
25 | */
26 | public static const CHANGE:String = "change";
27 |
28 | /**
29 | * A change was made to the data contained in an item.
30 | *
31 | * @eventType invalidate
32 | *
33 | * @langversion 3.0
34 | * @playerversion Flash 9.0.28.0
35 | */
36 | public static const INVALIDATE:String = "invalidate";
37 |
38 | /**
39 | * The data set is invalid.
40 | *
41 | * @eventType invalidateAll
42 | *
43 | * @langversion 3.0
44 | * @playerversion Flash 9.0.28.0
45 | */
46 | public static const INVALIDATE_ALL:String = "invalidateAll";
47 |
48 | /**
49 | * Items were added to the data provider.
50 | *
51 | * @eventType add
52 | *
53 | * @langversion 3.0
54 | * @playerversion Flash 9.0.28.0
55 | * @internal The word "model" was replaced with "data provider" above. What should it say?
56 | * @internal If this indicates "one or more" items were added, we should use that string.
57 | */
58 | public static const ADD:String = "add";
59 |
60 | /**
61 | * Items were removed from the data provider.
62 | *
63 | * @eventType remove
64 | *
65 | * @langversion 3.0
66 | * @playerversion Flash 9.0.28.0
67 | * @internal The word "model" was replaced with "data provider" above. What should it say?
68 | * @internal If this indicates "one or more" items were removed, we should use that string.
69 | */
70 | public static const REMOVE:String = "remove";
71 |
72 | /**
73 | * All items were removed from the data provider.
74 | *
75 | * @eventType removeAll
76 | *
77 | * @langversion 3.0
78 | * @playerversion Flash 9.0.28.0
79 | * @internal The word "model" was replaced with "data provider" above. What should it say?
80 | */
81 | public static const REMOVE_ALL:String = "removeAll";
82 |
83 | /**
84 | * The items in the data provider were replaced by new items.
85 | *
86 | * @eventType replace
87 | *
88 | * @langversion 3.0
89 | * @playerversion Flash 9.0.28.0
90 | * @internal I used "data provider" here instead of the word "model". Correct?
91 | */
92 | public static const REPLACE:String = "replace";
93 |
94 | /**
95 | * The data provider was sorted. This constant is used to indicate
96 | * a change in the order of the data, not a change in
97 | * the data itself.
98 | *
99 | * @eventType sort
100 | *
101 | * @langversion 3.0
102 | * @playerversion Flash 9.0.28.0
103 | * @internal The word "model" was replaced with "data provider" above. What should it say?
104 | */
105 | public static const SORT:String = "sort";
106 | }
107 | }
--------------------------------------------------------------------------------
/test/TestRunner.mxml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/test/unit/BumpslideTestSuite.as:
--------------------------------------------------------------------------------
1 | package unit
2 | {
3 |
4 | [Suite]
5 | [RunWith("org.flexunit.runners.Suite")]
6 |
7 | /**
8 | * Unit Test Suite for Bumpslide Library
9 | *
10 | * @author David Knape
11 | */
12 | public class BumpslideTestSuite
13 | {
14 | public var testBinding:TestBindableModel;
15 | public var testHttp:TestHTTPRequest;
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/test/unit/TestBindableModel.as:
--------------------------------------------------------------------------------
1 | package unit
2 | {
3 | import com.bumpslide.events.ModelChangeEvent;
4 |
5 | import org.flexunit.Assert;
6 | import org.flexunit.async.Async;
7 |
8 | import flash.events.Event;
9 | import flash.events.EventDispatcher;
10 |
11 | /**
12 | * @author David Knape
13 | */
14 | public class TestBindableModel extends EventDispatcher
15 | {
16 | private var model:TestModel;
17 |
18 |
19 | [Before]
20 | public function setup():void {
21 | model = new TestModel();
22 | }
23 |
24 | [Test(async, description="Test Prop Change Event")]
25 | public function testArrayPropChange():void {
26 | model.addEventListener( ModelChangeEvent.PROPERTY_CHANGED, Async.asyncHandler( this, handleArrayPropChange, 1000) );
27 | model.arrayData = ['Test', 'Data'];
28 | }
29 |
30 | private function handleArrayPropChange(event:ModelChangeEvent, passthru:*=null):void
31 | {
32 | Assert.assertEquals( model.arrayData.length, 2);
33 | }
34 |
35 |
36 | [Test(async,description='Test String Binding')]
37 | public function testStringBinding():void {
38 | model.bind('stringData', this );
39 | model.stringData = "hi";
40 | Async.proceedOnEvent(this, this, 'stringDataBound');
41 | }
42 |
43 | public function set stringData (s:String):void {
44 | if(s==null) return;
45 | Assert.assertEquals(s, "hi");
46 | dispatchEvent( new Event('stringDataBound') );
47 | }
48 |
49 |
50 |
51 | [Test(description='Last Test')]
52 | public function testHello():void {
53 | model.stringData = "hello";
54 | Assert.assertNotNull( model.stringData );
55 | }
56 |
57 |
58 | // private function handleArrayDataChange(arrayData:Array):void
59 | // {
60 | // Assert.assertEquals( arrayData.length, 2 );
61 | // }
62 | }
63 | }
64 |
65 | import com.bumpslide.data.BindableModel;
66 |
67 |
68 | class TestModel extends BindableModel {
69 |
70 | public function set arrayData(a:Array):void {
71 | set('arrayData', a);
72 | }
73 |
74 | public function get arrayData():Array {
75 | return get('arrayData');
76 | }
77 |
78 | public function set stringData(s:String):void {
79 | set('stringData', s);
80 | }
81 |
82 | public function get stringData():String {
83 | return get('stringData');
84 | }
85 |
86 |
87 |
88 | }
--------------------------------------------------------------------------------
/test/unit/TestHTTPRequest.as:
--------------------------------------------------------------------------------
1 | package unit
2 | {
3 |
4 | import com.bumpslide.data.Callback;
5 | import com.bumpslide.net.HTTPRequest;
6 |
7 | import org.flexunit.asserts.assertTrue;
8 | import org.flexunit.asserts.fail;
9 | import org.flexunit.async.Async;
10 |
11 | import flash.errors.IOError;
12 | import flash.events.Event;
13 | import flash.events.EventDispatcher;
14 | import flash.net.URLRequest;
15 |
16 | /**
17 | * @author David Knape
18 | */
19 | public class TestHTTPRequest extends EventDispatcher
20 | {
21 |
22 | protected var req:HTTPRequest;
23 |
24 | private static const TEST_URL:String = "http://google.com/";
25 |
26 | private static const TIMEOUT:int = 10000;
27 |
28 | [Test(async)]
29 | public function testListeningForCompleteEvent():void
30 | {
31 | req = new HTTPRequest( new URLRequest( TEST_URL ) );
32 | Async.proceedOnEvent( this, req, Event.COMPLETE, TIMEOUT );
33 | req.load();
34 | }
35 |
36 |
37 | [Test(async)]
38 | public function testUsingCallbackWithPassthruData():void
39 | {
40 | req = new HTTPRequest( new URLRequest( TEST_URL ) );
41 | req.addResponder( new Callback( handleResult, handleUnexpectedError, { data:"Passthru" } ) );
42 | Async.proceedOnEvent( this, this, 'passthruComplete', TIMEOUT );
43 | req.load();
44 | }
45 |
46 |
47 | private function handleResult( data:Object, passthru:Object ) : void
48 | {
49 | assertTrue( data is String );
50 | assertTrue( passthru.data == "Passthru" );
51 | dispatchEvent( new Event( 'passthruComplete' ) );
52 | }
53 |
54 |
55 | private function handleUnexpectedError( error:Error ) : void
56 | {
57 | fail( error.message );
58 | }
59 |
60 |
61 | [Test(async)]
62 | public function testIOError():void
63 | {
64 | req = new HTTPRequest( new URLRequest( TEST_URL + "XX" ) );
65 | req.addResponder( new Callback( null, handleExpectedIOError ) );
66 | Async.proceedOnEvent( this, this, 'ioErrorComplete', TIMEOUT );
67 | req.load();
68 | }
69 |
70 |
71 | private function handleExpectedIOError( error:Error ):void
72 | {
73 | assertTrue( error is IOError );
74 | dispatchEvent( new Event( 'ioErrorComplete' ) );
75 | }
76 | }
77 | }
78 |
--------------------------------------------------------------------------------