豚会 名札じぇねれーたー
適当でマジごめん・・・・
エラーチェックもしてないからタイポしたら知らないよ
こんなフォントいやだ!だれかフォークしてかっちょいいのにして!
めそ
package {
/*
適当でマジごめん・・・・
エラーチェックもしてないからタイポしたら知らないよ
こんなフォントいやだ!だれかフォークしてかっちょいいのにして!
めそ
*/
import com.adobe.images.PNGEncoder;
import com.adobe.serialization.json.JSON;
import flash.display.BitmapData;
import flash.display.Loader;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.KeyboardEvent;
import flash.events.MouseEvent;
import flash.net.FileReference;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.system.LoaderContext;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFieldType;
import flash.text.TextFormat;
import flash.ui.Keyboard;
import flash.utils.ByteArray;
public class Main extends Sprite {
private var SEARCH_URL:String = "http://search.twitter.com/search.json?rpp=100&q=from:";
private var TON_URL:String = "http://ton-up.net/nametag_ton.png";
private var saveButton:Sprite;
private var idTxt:TextField;
private var callNameTxt:TextField;
private var okButton:Sprite;
private var nameTag:Sprite;
private var yourIcon:Loader;
private var tonIcon:Loader;
private var idName:TextField;
private var callName:TextField;
public function Main():void {
initText();
initNameTag();
loadTon();
}
private function initText():void {
var txt1:TextField = new TextField();
txt1.autoSize = TextFieldAutoSize.LEFT;
txt1.text = "呼び名(読みやすいの)";
stage.addChild(txt1);
callNameTxt = new TextField();
callNameTxt.x = txt1.width;
callNameTxt.width = 150;
callNameTxt.height = 20;
callNameTxt.border = true;
callNameTxt.type = TextFieldType.INPUT;
stage.focus = callNameTxt;
stage.addChild(callNameTxt);
var txt2:TextField = new TextField();
txt2.y = txt1.height + 5;
txt2.autoSize = TextFieldAutoSize.LEFT;
txt2.text = "Twitter ID";
addChild(txt2);
idTxt = new TextField();
idTxt.x = txt1.width;
idTxt.y = callNameTxt.height + 5;
idTxt.width = 150;
idTxt.height = 20;
idTxt.border = true;
idTxt.type = TextFieldType.INPUT;
idTxt.restrict = "a-zA-Z1-9_";
idTxt.maxChars = 15;
stage.addChild(idTxt);
var okTxt:TextField = new TextField();
okTxt.width = 25;
okTxt.height = 20;
okTxt.text = "OK";
okTxt.background = true;
okTxt.backgroundColor = 0xaaaaaa;
okTxt.border = true;
okTxt.mouseEnabled = false;
okButton = new Sprite();
okButton.x = idTxt.x + idTxt.width + 10;
okButton.y = callNameTxt.height + 5;
okButton.buttonMode = true;
okButton.addChild(okTxt);
var saveTxt:TextField = new TextField();
saveTxt.width = 30;
saveTxt.height = 20;
saveTxt.text = "保存";
saveTxt.background = true;
saveTxt.backgroundColor = 0xaaaaaa;
saveTxt.border = true;
saveTxt.mouseEnabled = false;
saveButton = new Sprite();
saveButton.buttonMode = true;
saveButton.addChild(saveTxt);
saveButton.x = stage.stageWidth - saveButton.width - 10;
saveButton.addEventListener(MouseEvent.CLICK, save);
addEvent();
}
private function save(e:MouseEvent):void {
var bmd:BitmapData = new BitmapData(nameTag.width, nameTag.height);
bmd.draw(nameTag);
var byteImage:ByteArray = PNGEncoder.encode(bmd);
var file:FileReference = new FileReference();
file.save(byteImage, "名札-" + idName.text + ".png");
}
private function initNameTag():void{
nameTag = new Sprite();
nameTag.graphics.lineStyle(1, 0x000000);
nameTag.graphics.drawRect(0, 0, 364, 220);
nameTag.graphics.endFill();
nameTag.x = stage.stageWidth / 2 - nameTag.width / 2;
nameTag.y = stage.stageHeight / 2 - nameTag.height / 2;
addChild(nameTag);
callName = new TextField();
callName.autoSize = TextFieldAutoSize.CENTER;
callName.defaultTextFormat = new TextFormat(null, 32);
callName.text = "dummy";
callName.x = nameTag.width / 2 - callName.width / 2;
callName.y = 5;
idName = new TextField();
idName.autoSize = TextFieldAutoSize.CENTER;
idName.defaultTextFormat = new TextFormat(null, 32);
idName.text = "dummy";
idName.x = nameTag.width / 2 - idName.width / 2;
idName.y = nameTag.height - idName.height - 5;
}
private function loadTon():void{
tonIcon = new Loader();
tonIcon.load(new URLRequest(TON_URL), new LoaderContext(true));
}
private function addEvent():void {
idTxt.addEventListener(KeyboardEvent.KEY_DOWN, pressEnter);
okButton.addEventListener(MouseEvent.CLICK, pressOK);
stage.addChild(okButton);
}
private function removeEvent():void {
idTxt.removeEventListener(KeyboardEvent.KEY_DOWN, pressEnter);
okButton.removeEventListener(MouseEvent.CLICK, pressOK);
stage.removeChild(okButton);
}
private function pressOK(e:MouseEvent):void {
removeEvent();
loadID();
}
private function pressEnter(e:KeyboardEvent):void {
if (e.keyCode == Keyboard.ENTER) {
removeEvent();
loadID();
}
}
private function loadID():void {
var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, completeLoadID);
loader.load(new URLRequest(SEARCH_URL + idTxt.text));
}
private function completeLoadID(e:Event):void {
if (yourIcon) nameTag.removeChild(yourIcon);
yourIcon = new Loader();
yourIcon.contentLoaderInfo.addEventListener(Event.COMPLETE, completeLoadImage);
var url:String = JSON.decode(e.target.data).results[0].profile_image_url.replace("_normal", "_bigger");
trace(url);
yourIcon.load(new URLRequest(url), new LoaderContext(true));
}
private function completeLoadImage(e:Event):void {
addEvent();
nameTag.addChild(tonIcon);
yourIcon.width = 146;
yourIcon.height = 146;
yourIcon.x = nameTag.width - yourIcon.width - 10;
yourIcon.y = nameTag.height / 2 - yourIcon.height / 2;
nameTag.addChild(yourIcon);
idName.text = idTxt.text;
nameTag.addChild(idName);
callName.text = callNameTxt.text;
nameTag.addChild(callName);
stage.addChild(saveButton);
}
}
}