flash on 2009-12-27
♥0 |
Line 199 |
Modified 2009-12-27 18:18:23 |
MIT License
archived:2017-03-20 04:37:11
ActionScript3 source code
/**
* Copyright taxponation ( http://wonderfl.net/user/taxponation )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/A4Ev
*/
package
{
import __AS3__.vec.Vector;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.ProgressEvent;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.text.StyleSheet;
import flash.text.TextField;
[SWF(width="200", height="780", backgroundColor="#FFFFFF")]
public class TwAPI extends Sprite
{
private var tf:TextField = new TextField();
private var loader:URLLoader = new URLLoader();
private var i:int = 0;
private var t:Sprite;
private var tw:Vector.<TwButton> = new Vector.<TwButton>(20);
private var twUrl:Vector.<String> = new Vector.<String>(20);
public function TwAPI():void
{
var i:int = 0;
tf.y = 20;
tf.width = 200;
tf.height = 412 - 20;
tf.multiline = true;
tf.wordWrap = true;
tf.selectable = false;
//addChild(tf);
t = new Sprite();
for(i = 0; i<20; i++){
tw[i] = new TwButton(i);
tw[i].width = 200;
tw[i].y = 60*i;
tw[i].setTF("aaa");
addChild(tw[i]);
}
var ss:StyleSheet = new StyleSheet();
ss.setStyle("a:link", { textDecoration:"underline", color:"#0000FF" } );
tf.styleSheet = ss;
trace("aaaa");
default xml namespace = new Namespace("http://www.w3.org/2005/Atom");
loader.addEventListener(ProgressEvent.PROGRESS, onProgress);
loader.addEventListener(Event.COMPLETE, loadComplete);
loader.load(new URLRequest("http://twitter.com/favorites.atom?id=taxpon&page=1"));
}
private function onProgress(evt:Event):void{
trace("progress");
for(var i:int = 0; i< 20; i++){
tw[i].setTF("Loading ..");
}
}
private function loadComplete(e:Event):void{
var i:int = 0;
var entrys:XMLList = XML(loader.data).entry;
trace("LENGTH : ",entrys.length());
var s:String = "<br/>";
for each(var x:XML in entrys)
{
s+= entryToString(x);
tw[i].setTF(x.title);
tw[i].jumpUrl = x.link.(@type=="text/html")[0].@href;
trace(i);
i++;
}
tf.htmlText = s;
}
private function entryToHtmlString(entry:XML):String
{
var s:String = "<p>"+ entry.title + "</p>";
return s;
}
private function entryToString(entry:XML):String
{
var s:String = entry.title;
return s;
}
}
}
import flash.display.Sprite;
import flash.text.TextField;
import flash.events.MouseEvent;
import org.libspark.betweenas3.BetweenAS3;
import org.libspark.betweenas3.easing.*;
import org.libspark.betweenas3.tweens.ITween;
class TwButton extends Sprite{
private var num:int;
public var jumpUrl:String;
private var tf:TextField = new TextField();
private var format:TextFormat = new TextFormat();
private var b:Box = new Box(200, 60);
private var grad:Gradation = new Gradation(0xFF0000, 0x000000);
private var gradLet:Gradation = new Gradation(0xAAAAAA, 0xffffff);
private var colnum:Number = 0;
private var mFlag:Boolean = false;
private var twEnd:Boolean = false;
public function TwButton(n:int){
num = n;
//width = 200.0;
//height = 60.0;
b.width = 200;
b.height = 59;
addChild(b);
tf.defaultTextFormat = format;
tf.borderColor = 0xff0000;
//tf.border = true;
tf.selectable = false;
tf.x = 5;
tf.y = 5;
tf.width = 190;
tf.height = 59;
tf.wordWrap = true;
addChild(tf);
graphics.lineStyle(0.5, 0x333333);
graphics.moveTo(0,59);
graphics.lineTo(200,59);
this.addEventListener(MouseEvent.MOUSE_OVER, onMOver);
this.addEventListener(MouseEvent.MOUSE_OUT, onMOut);
this.addEventListener(MouseEvent.MOUSE_UP, onMUp);
}
public function getNum():int{
return num;
}
public function setTF(s:String):void{
tf.text = s;
}
public function setHtmlTF(s:String):void{
tf.htmlText = s;
}
private function onMOver(evt:MouseEvent):void{
if(!twEnd){
addEventListener(Event.ENTER_FRAME, onEnterFrame);
}
}
private function onMOut(evt:MouseEvent):void{
removeEventListener(Event.ENTER_FRAME, onEnterFrame);
if(twEnd){
twEnd = false;
colnum = 0;
}
b.setCol(0xffffff);
tf.textColor = 0x333333;
}
private function onMUp(evt:MouseEvent):void{
var jump:URLRequest = new URLRequest( jumpUrl );
// 実際にページに飛ぶ
navigateToURL( jump );
}
private function onEnterFrame(evt:Event):void{
b.setCol(grad.getColor(colnum));
//format.color = gradLet.getColor(colnum);
tf.textColor = gradLet.getColor(colnum);
colnum += 0.1;
if(colnum > 1){
removeEventListener(Event.ENTER_FRAME, onEnterFrame);
twEnd = true;
}
}
}
import flash.display.Shape;
class Box extends Shape{
private var col:uint = 0xffffff;
public function Box(w:Number, h:Number){
width = 200;
height = 40;
draw();
}
private function draw():void{
graphics.beginFill(col);
graphics.drawRect(0,0,200,40);
graphics.endFill();
}
public function setCol(c:uint):void{
col =c;
draw();
}
}
import frocessing.color.ColorLerp;
import org.libspark.betweenas3.core.easing.IEasing;
import org.libspark.betweenas3.easing.Linear;
import flash.events.Event;
import flash.text.TextFormat;
import flash.net.URLRequest;
import flash.net.navigateToURL;
class Gradation {
private var _colors:Array;
private var _easing:IEasing;
public function Gradation(...args) {
_colors = args.concat();
_easing = Linear.linear;
}
public function setEasing(easing:IEasing):void {
_easing = easing;
}
public function getColor(position:Number):uint {
position = (position < 0 ? 0 : position > 1 ? 1 : position) * (_colors.length - 1);
var idx:int = position;
var alpha:Number = _easing.calculate(position - idx, 0, 1, 1);
if (alpha == 0) {
return _colors[idx];
} else {
return ColorLerp.lerp(_colors[idx], _colors[idx + 1], alpha);
}
}
}