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
136<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="http://www.adobe.com/2006/mxml"
creationComplete="handle_creationComplete()"
resize="handle_resizeHandler(event)"
width="450" height="250"
backgroundColor="#FFFFFF" backgroundAlpha="0.0">
<mx:Style source="twittercamp/assets/TwitterCamp.css"/>
<mx:Script>
<![CDATA[
import mx.effects.easing.Bounce;
import mx.effects.easing.Exponential;
import mx.events.EffectEvent;
import mx.events.ResizeEvent;
import spark.utils.TextFlowUtil;
import twittercamp.services.twitter.Tweet;
public var creationTime:Date = new Date();
public function get twitterStatus():Tweet
{
return nextStatus;
}
public function set twitterStatus( nextStatus:Tweet ):void
{
this.nextStatus = nextStatus;
kill();
}
[Bindable]
private var status:Tweet;
private var nextStatus:Tweet;
private var updateRelativeTimeLabelTimer:Timer;
private function handle_creationComplete():void
{
setVisible(false);
updateRelativeTimeLabelTimer = new Timer( 60000 );
updateRelativeTimeLabelTimer.addEventListener( TimerEvent.TIMER, handle_updateRelativeTimeLabelTimer );
handle_resizeHandler(null);
}
private function handle_updateRelativeTimeLabelTimer( event:TimerEvent ):void
{
relativeTime.text = status.relativeCreatedAt;
}
private function kill():void
{
creationTime = new Date();
killEffect.play([this]);
}
private function handle_killEffectEnd( event:EffectEvent ):void
{
status = nextStatus;
bounceIn.play([this]);
setVisible(true);
updateRelativeTimeLabelTimer.start();
if(status != null)
{
avatar.load(status.user.profileImg);
content.textFlow = TextFlowUtil.importFromString(status.content);
relativeTime.text = status.relativeCreatedAt;
}
else
{
trace(status);
}
}
protected function handle_resizeHandler(event:ResizeEvent):void
{
// set font size
var fontSize:int = Math.max(14, content.height / 9);
content.setStyle("fontSize", fontSize);
content.setStyle("lineHeight", fontSize*1.4);
userName.setStyle("fontSize", fontSize);
relativeTime.setStyle("fontSize", Math.max(12, fontSize*0.6));
// set tweet padding
content.left = fontSize;
content.right = fontSize;
// change avatar size
avatar.height = fontSize * 2.8;
avatar.width = fontSize * 2.8;
}
]]>
</mx:Script>
<mx:Sequence id="bounceIn">
<mx:Parallel>
<mx:Fade duration="250" alphaFrom="0" alphaTo="1" />
<mx:Zoom easingFunction="{Bounce.easeOut}"
zoomHeightFrom="0.5" zoomWidthFrom="0.5"
zoomHeightTo="1" zoomWidthTo="1"
duration="750" />
</mx:Parallel>
</mx:Sequence>
<mx:Fade id="killEffect" alphaFrom="1" alphaTo="0" duration="3000"
easingFunction="{Exponential.easeIn}"
effectEnd="handle_killEffectEnd(event)" />
<mx:VBox x="0" y="0" width="100%" height="100%">
<mx:Canvas width="100%" height="100%">
<mx:SWFLoader source="twittercamp/assets/flash/bubble.swf"
maintainAspectRatio="false" scaleContent="true"
left="0" right="0" bottom="0" top="0"/>
<s:RichText fontWeight="bold" fontSize="14" lineHeight="18" textAlign="left"
left="14" right="14" top="8" bottom="27" verticalAlign="middle"
id="content">
<s:content></s:content>
</s:RichText>
</mx:Canvas>
<mx:HBox width="100%" verticalAlign="middle" horizontalGap="10">
<mx:Canvas dropShadowVisible="true">
<mx:Image id="avatar" width="40" height="40" verticalCenter="0" horizontalCenter="0"/>
</mx:Canvas>
<mx:VBox height="100%" width="100%" verticalGap="0" verticalAlign="bottom">
<mx:Label id="userName" width="100%" text="{status.user.name}" color="#FFFFFF" fontSize="14"/>
<mx:Label id="relativeTime" width="100%" text="" color="#FFFFFF"/>
</mx:VBox>
</mx:HBox>
</mx:VBox>
</mx:Canvas>