-
Notifications
You must be signed in to change notification settings - Fork 24
/
AS3ScrollingList.as
135 lines (119 loc) · 3.98 KB
/
AS3ScrollingList.as
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/**
* @author Michael Ritchie
* @blog http://www.thanksmister.com
* @twitter Thanksmister
* Copyright (c) 2010
*
* This is a Flash application to test the TouchList component.
* */
package
{
import flash.desktop.NativeApplication;
import flash.desktop.SystemIdleMode;
import flash.display.MovieClip;
import flash.display.Stage;
import flash.display.StageAlign;
import flash.display.StageOrientation;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.events.KeyboardEvent;
import flash.events.StageOrientationEvent;
import flash.system.Capabilities;
import flash.text.TextField;
import flash.ui.Keyboard;
import com.thanksmister.touchlist.renderers.TouchListItemRenderer;
import com.thanksmister.touchlist.events.ListItemEvent;
import com.thanksmister.touchlist.controls.TouchList;
[SWF( width = '480', height = '800', backgroundColor = '#000000', frameRate = '24')]
public class AS3ScrollingList extends MovieClip
{
private var touchList:TouchList;
private var textOutput:TextField;
private var stageOrientation:String = StageOrientation.DEFAULT;
public function AS3ScrollingList()
{
// needed to scale our screen
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
if(stage)
init();
else
stage.addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event = null):void
{
stage.removeEventListener(Event.ADDED_TO_STAGE, init);
stage.addEventListener(KeyboardEvent.KEY_DOWN, handleKeyDown);
stage.addEventListener(Event.RESIZE, handleResize);
// if we have autoOrients set in permissions we add listener
if(Stage.supportsOrientationChange) {
stage.addEventListener(StageOrientationEvent.ORIENTATION_CHANGE, handleOrientationChange);
}
if(Capabilities.cpuArchitecture == "ARM") {
NativeApplication.nativeApplication.addEventListener(Event.ACTIVATE, handleActivate, false, 0, true);
NativeApplication.nativeApplication.addEventListener(Event.DEACTIVATE, handleDeactivate, false, 0, true);
}
// add our list and listener
touchList = new TouchList(stage.stageWidth, stage.stageHeight);
touchList.addEventListener(ListItemEvent.ITEM_SELECTED, handlelistItemSelected);
addChild(touchList);
// Fill our list with item rendreres that extend ITouchListRenderer.
for(var i:int = 0; i < 50; i++) {
var item:TouchListItemRenderer = new TouchListItemRenderer();
item.index = i;
item.data = "This is list item " + String(i);
item.itemHeight = 80;
touchList.addListItem(item);
}
}
/**
* Handle stage orientation by calling the list resize method.
* */
private function handleOrientationChange(e:StageOrientationEvent):void
{
switch (e.afterOrientation) {
case StageOrientation.DEFAULT:
case StageOrientation.UNKNOWN:
//touchList.resize(stage.stageWidth, stage.stageHeight);
break;
case StageOrientation.ROTATED_RIGHT:
case StageOrientation.ROTATED_LEFT:
//touchList.resize(stage.stageHeight, stage.stageWidth);
break;
}
}
private function handleResize(e:Event = null):void
{
touchList.resize(stage.stageWidth, stage.stageHeight);
}
private function handleActivate(event:Event):void
{
NativeApplication.nativeApplication.systemIdleMode = SystemIdleMode.KEEP_AWAKE;
}
private function handleDeactivate(event:Event):void
{
NativeApplication.nativeApplication.exit();
}
/**
* Handle keyboard events for menu, back, and seach buttons.
* */
private function handleKeyDown(e:KeyboardEvent):void
{
if(e.keyCode == Keyboard.BACK) {
e.preventDefault();
NativeApplication.nativeApplication.exit();
} else if(e.keyCode == Keyboard.MENU){
e.preventDefault();
} else if(e.keyCode == Keyboard.SEARCH){
e.preventDefault();
}
}
/**
* Handle list item seleced.
* */
private function handlelistItemSelected(e:ListItemEvent):void
{
trace("List item selected: " + e.renderer.index);
}
}
}