forked from: adobe challenge 2
forked from adobe challenge 2 (diff: 305)
ActionScript3 source code
/**
* Copyright zahir ( http://wonderfl.net/user/zahir )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/riuZ
*/
<?xml version="1.0" encoding="utf-8"?>
<!--
// forked from checkmate's adobe challenge 2
/**
*
* "Use Flash Player 10 text libraries (FTE).
* You can do a lot of interesting things with text,
* but I think it has even more potential
* in experimental work where
* the APIs are used just as a container format
* for images, movie clips
* and other interactive elements."
* by Justin Everett-Church
*
* This code is an example of FTE.
*/
-->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="465" height="465"
backgroundGradientAlphas="[1.0, 1.0]" backgroundGradientColors="[#041421, #0F2F4E]" initialize="init()">
<mx:Style>
HSlider.FontSize{
borderColor: #3792BC;
errorColor: #FF7200;
tickColor: #BCE2FF;
color:#FFFFFF;
dataTipPlacement: bottom;
}
Label{
color: #FFFFFF;
}
Button.Btn1{
fontGridFitType: none;
fontSize: 12;
fontStyle: normal;
paddingLeft: 3;
paddingRight: 3;
textAlign: center;
}
Text.output{
fontFamily: Georgia;
backgroundColor:#FFFFFF;
color:#333333;
}
Button{
fontFamily: "Times New Roman";
fontSize: 16;
fontWeight: bold;
paddingLeft: 0;
paddingRight: 0;
paddingTop: 1;
}
</mx:Style>
<mx:Script>
<![CDATA[
import flash.display.Sprite;
import flash.system.Capabilities;
import flash.text.*;
import flash.text.engine.*;
import mx.collections.ArrayCollection;
[Bindable]
public var cards:ArrayCollection;
private var s:Sprite = new Sprite();
private var size:int =30;
private var marginR:int = 3;
private var marginT:int = 10;
private var textCont:Sprite = new Sprite();
private var fName:String = "小塚明朝 Pro R";
private var ta_width:int = 215;
private function init():void{
myCont.addChild(s);
myCont.height = 420;
ini_text();
s_fonts();
myCont.width = s.width;
Wonderfl.capture_delay(10);
}
private function onChange():void{
myCont.width = s.width;
var r:int = s_red.value;
var g:int = s_green.value;
var b:int = s_blue.value;
var a:int = s_Alpha.value;
t_red.text = r.toString();
t_green.text = g.toString();
t_blue.text = b.toString();
t_Alpha.text = a.toString();
F_color.text = "0x" + ((r <<16) | (g<<8) | b).toString();
var _txt:String = editer.text;
size = txt_size.value;
var Aa:Number = a / 255;
var font:FontDescription = new FontDescription();
var format:ElementFormat = new ElementFormat();
if(Btn_n.enabled){
if(!Btn_b.enabled) font.fontWeight = flash.text.engine.FontWeight.BOLD;
if(!Btn_i.enabled) font.fontPosture = flash.text.engine.FontPosture.ITALIC;
if(!Btn_k.enabled) format.kerning = flash.text.engine.Kerning.ON;
}else{
font.fontWeight = flash.text.engine.FontWeight.NORMAL;
font.fontPosture = flash.text.engine.FontPosture.NORMAL;
format.kerning = flash.text.engine.Kerning.OFF;
}
font.fontName = fName;
format.fontDescription = font;
format.fontSize = size;
format.color = (r <<16) | (g<<8) | b;
format.alpha = Aa;
var tb:TextBlock = new TextBlock();
tb.content = new TextElement(_txt,format);
tb.baselineZero = TextBaseline.DESCENT;
tb.textJustifier = new EastAsianJustifier("ja",flash.text.engine.LineJustification.UNJUSTIFIED);
tb.lineRotation = TextRotation.ROTATE_90; // レッツ縦書き
var previousLine:TextLine = null;
var linePosition:Number = ta_width - (size + size*0.25);
var lineSpace:Number = size*(s_ls.value/100);
myCont.width = s.width;
marginT = 420 - s_v.values[1] ;
var h:Number = s_v.values[1] - s_v.values[0];
//一旦文字を全部削除する
while (textCont.numChildren) { textCont.removeChildAt(0); }
textCont.x = 0;
var flg:Boolean = true;
while(true){
var textLine:TextLine = tb.createTextLine(previousLine, h); //(開始位置のX? , 高さ)
if (textLine == null) break;
textLine.y = marginT;
textLine.x = linePosition;
linePosition -= lineSpace; //行間的な
textCont.addChild(textLine); // とりあえずaddChild
previousLine = textLine;
//if(flg){textLine.x += marginR; flg = false;}
}
if(textCont.width > ta_width){
textCont.x = textCont.width - ta_width + marginR;
}else if(textCont.width < ta_width){
textCont.x = -marginR -(10 - size/10);
}
}
//ボタン用
private function onClick_n():void{
Btn_b.enabled = true;
Btn_i.enabled = true;
Btn_k.enabled = true;
Btn_n.enabled = false;
if(Btn_b.enabled && Btn_i.enabled && Btn_k.enabled) Btn_n.enabled = false;
onChange();
}
private function onClick_b():void{
if(Btn_b.enabled){
Btn_b.enabled = false;
}
else if(!Btn_b.enabled){
Btn_b.enabled = true;
}
if(!Btn_n.enabled) Btn_n.enabled = true;
if(Btn_b.enabled && Btn_i.enabled && Btn_k.enabled) Btn_n.enabled = false;
onChange();
}
private function onClick_i():void{
if(Btn_i.enabled){
Btn_i.enabled = false;
}
else if(!Btn_i.enabled){
Btn_i.enabled = true;
}
if(!Btn_n.enabled) Btn_n.enabled = true;
if(Btn_b.enabled && Btn_i.enabled && Btn_k.enabled) Btn_n.enabled = false;
onChange();
}
private function onClick_k():void{
if(Btn_k.enabled){
Btn_k.enabled = false;
}
else if(!Btn_k.enabled){
Btn_k.enabled = true;
}
if(!Btn_n.enabled) Btn_n.enabled = true;
if(Btn_b.enabled && Btn_i.enabled && Btn_k.enabled) Btn_n.enabled = false;
onChange();
}
/* 縦書き */
private function ini_text():void{
var font:FontDescription = new FontDescription();
var format:ElementFormat = new ElementFormat();
var str:String = "ふらっしゅぷれいやー⑩(あすとろ)の縦書き機能を試してみるテスト\n\n";
str += "便利なライブラリでないかなぁ、使いづらい・・・\n\n";
str += "記号系がずれるけどどうにかならないかな?"
var textBlock:TextBlock = new TextBlock();
var te:TextElement;
editer.text = str;
// OSでフォントを選別
if (Capabilities.os.search("Mac OS") > -1)
font.fontName = String.fromCharCode(0x5C0F, 0x585A, 0x660E, 0x671D) + " Pro R";
else font.fontName = "小塚明朝 Pro R";
format.fontDescription = font;
format.fontSize = size;
format.locale = "ja";
format.color = 0x000000;
textBlock.baselineZero = TextBaseline.DESCENT; //よくわからないorz
textBlock.textJustifier = new EastAsianJustifier("ja",flash.text.engine.LineJustification.UNJUSTIFIED);
textBlock.lineRotation = TextRotation.ROTATE_90; // レッツ縦書き
te = new TextElement(str, format);
textBlock.content =te;
var previousLine:TextLine = null;
var linePosition:Number = ta_width - (size + size*0.2);
var lineSpace:Number = size;
var flg:Boolean = true;
while(true){
var textLine:TextLine = textBlock.createTextLine(previousLine, 420); //(開始位置のX? , 高さ)
if (textLine == null) break;
textLine.y = marginT;
if(flg){ textLine.x = linePosition + marginR; flg = false; }
else textLine.x = linePosition;
linePosition -= lineSpace; //行間的な
textCont.addChild(textLine); // とりあえずaddChild
previousLine = textLine;
}
s.addChild(textCont);
if(textCont.width > ta_width){
textCont.x = textCont.width - ta_width;
}else if(textCont.width < ta_width){
textCont.x = -marginR -(10 - size/10);
}
myCont.width = s.width;
}
/*
コンボボックスにOSに登録されているフォントを追加していく
*/
private function s_fonts():void{
var allFonts:Array = Font.enumerateFonts(true);
var _arr:Array = new Array();
allFonts.sortOn("fontName", Array.CASEINSENSITIVE);
for(var i:int=0;i<allFonts.length;i++){
_arr[i] = {label:allFonts[i].fontName , data:i+1};
}
cards = new ArrayCollection(_arr);
}
private function close():void{
fName = FontsName.text;
onChange();
}
]]>
</mx:Script>
<mx:Canvas x="5" y="10" width="255" height="445" backgroundColor="#FFFFFF" backgroundAlpha="0.6" cornerRadius="5" borderStyle="solid" id="base" alpha="1.0">
<mx:Canvas x="5" y="5" width="228" height="435" backgroundColor="#808080" borderStyle="solid" borderColor="#04141F">
<mx:Canvas id="txt_area" verticalScrollPolicy="off" x="5" y="5" width="215" height="423" backgroundColor="#FFFFFF">
<mx:UIComponent id="myCont" width="215" height="423"></mx:UIComponent>
</mx:Canvas>
</mx:Canvas>
<mx:VSlider x="232" y="8" height="430" maximum="420" minimum="0" snapInterval="5" thumbCount="2" tickInterval="10" values="[0,420]" showTrackHighlight="true" id="s_v" change="onChange()"/>
</mx:Canvas>
<mx:Text x="263" y="10" text="Flashで縦書きテスト" width="197" height="25" fontSize="20" textAlign="center" fontWeight="bold" fontFamily="Georgia" color="#FFFFFF"/>
<mx:Canvas x="266" y="35" width="192" height="421" backgroundColor="#FFFFFF" backgroundAlpha="0.2" borderStyle="solid" cornerRadius="5" borderColor="#0C4D7B">
<mx:Label x="5" y="3" text="テキストエディット"/>
<mx:TextArea x="5" y="20" width="180" height="79" borderStyle="outset" borderColor="#666666" id="editer" editable="true" enabled="true" change="onChange();"/>
<mx:Canvas x="5" y="104" width="180" height="60">
<mx:Label x="0" y="3" text="フォント選択"/>
<mx:ComboBox dataProvider="{cards}" x="55" y="0" width="125" close="close()" id="FontsName" editable="false"></mx:ComboBox>
<mx:Label x="0" y="34" text="フォントサイズ"/>
<mx:HSlider x="61" y="21" id="txt_size" allowTrackClick="true" minimum="8" maximum="200" snapInterval="2" liveDragging="true" width="119" labels="[8,200]" tickInterval="10" value="30" showDataTip="true"
styleName="FontSize" change="onChange()"/>
</mx:Canvas>
<mx:Canvas x="5" y="170" width="180" height="65">
<mx:Label x="0" y="0" text="テキストスタイル"/>
<mx:Button x="23" y="16" label="B" width="22" height="22" styleName="Btn1" id="Btn_b" click="onClick_b()"/>
<mx:Button x="0" y="16" label="N" width="22" height="22" styleName="Btn1" id="Btn_n" fontWeight="bold" enabled="false" click="onClick_n()"/>
<mx:Button x="46" y="16" label="I" width="22" height="22" styleName="Btn1" id="Btn_i" enabled="true" click="onClick_i()"/>
<mx:Button x="69" y="16" label="K" width="22" height="22" styleName="Btn1" id="Btn_k" enabled="true" click="onClick_k()"/>
<mx:Canvas x="0" y="45" width="180" height="20">
<mx:Label x="0" y="1" text="行間:"/>
<mx:HSlider x="30" y="2" width="150" minimum="0" maximum="200" snapInterval="5" tickInterval="25" value="100" id="s_ls" change="onChange()"/>
</mx:Canvas>
</mx:Canvas>
<mx:Canvas x="5" y="241" width="180" height="177" backgroundAlpha="0.1">
<mx:HSlider x="40" y="15" width="130" labels="[0,255]" maximum="255" minimum="0" snapInterval="1" value="0" invertThumbDirection="false" tickInterval="51" fillAlphas="[1.0, 1.0]" fillColors="[#FF0000, #FF0000]" borderColor="#FF0000" trackColors="#FF0000" change="onChange()" id="s_red"/>
<mx:HSlider x="40" y="60" width="130" maximum="255" minimum="0" snapInterval="1" value="0" tickInterval="51" fillAlphas="[1.0, 1.0]" fillColors="[#00FF00, #00FF00]" borderColor="#00FF00" trackColors="#00FF00" change="onChange()" id="s_green"/>
<mx:HSlider x="40" y="86" width="130" maximum="255" minimum="0" snapInterval="1" value="0" tickInterval="51" borderColor="#0000FF" fillAlphas="[1.0, 1.0]" fillColors="[#0000FF, #0000FF]" change="onChange()" id="s_blue"/>
<mx:HSlider x="40" y="153" width="120" maximum="255" minimum="0" snapInterval="1" value="255" tickInterval="51" change="onChange();" id="s_Alpha"/>
<mx:TextInput x="5" y="148" width="30" id="t_Alpha" styleName="input" text="255" maxChars="3" textAlign="right"/>
<mx:TextInput x="5" y="29" width="30" id="t_red" styleName="input" text="0" maxChars="3" textAlign="right"/>
<mx:TextInput x="5" y="55" width="30" id="t_green" styleName="input" text="0" maxChars="3" textAlign="right"/>
<mx:TextInput x="5" y="81" width="30" id="t_blue" styleName="input" text="0" maxChars="3" textAlign="right"/>
<mx:TextArea x="5" y="108" width="175" height="20" borderStyle="outset" borderColor="#666666" id="F_color" editable="true" enabled="true" change="onChange();"/>
<mx:Label x="0" y="0" text="フォントカラー"/>
<mx:Label x="0" y="128" text="透明度"/>
</mx:Canvas>
</mx:Canvas>
</mx:Application>