flash on 2015-2-4
♥0 |
Line 60 |
Modified 2015-02-08 22:59:02 |
MIT License
archived:2017-03-20 01:58:18
ActionScript3 source code
/**
* Copyright Cheshir ( http://wonderfl.net/user/Cheshir )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/syRU
*/
package {
import flash.events.MouseEvent;
import flash.text.StyleSheet;
import flash.display.Stage;
import flash.utils.Dictionary;
import flash.text.TextField;
import flash.display.Sprite;
public class FlashTest extends Sprite {
private var Text:XML =
<text>
<lang id="rus"/>
<lang id="eng"/>
<rus>
<text id="main">Выбран русский язык, вы должны видеть текст на русском.</text>
</rus>
<eng>
<text id="main">English is selected, you should see the English text.</text>
</eng>
</text>;
//private var
public function FlashTest() {
// write as3 code here..
var toReplace:Object = {"@family":"Aikiti","@name":"Onidzuka","@age":22,"@status":"Single"};
var toReplace2:Object = {"@family":"Bond","@name":"James","@age":42,"@status":"Agent 007"};
var tf:TextField = createText(20,40,'<p>@family @name. @age Years. @status</p>',false,'#338833');
tf.text = replaceTags(tf.text,toReplace);
var tf2:TextField = createText(40,80,"<p>@family, @name @family. @age years. @status.</p>");
tf2.text = replaceTags(tf2.text,toReplace2);
var tf3:TextField = createText(200,115,"<p>English</p>",true);
var tf4:TextField = createText(200,130,"<p>Русский</p>",true);
tf3.addEventListener(MouseEvent.CLICK, setLanguage);
tf4.addEventListener(MouseEvent.CLICK, setLanguage);
}
public function setLanguage(e:MouseEvent):void {
}
public function createText(toX:Number, toY:Number, txt:String, html:Boolean=false, col:String="#000",fSize:Number=16):TextField {
var tf:TextField = new TextField();
tf.x = toX; tf.y = toY;
if(html){
tf.htmlText = txt;
} else {
tf.text = txt;
}
tf.autoSize = 'left';
// tf.maxScrollH = 300;
var style:StyleSheet = new StyleSheet();
style.setStyle("p", {fontSize:fSize,fontFamily:"Arial",color:col});
tf.styleSheet = style;
addChild(tf);
return tf;
}
public function replaceTags(txt:String, diction:Object, tag:String="@"):String {
var pattern:RegExp = new RegExp(tag,"g");
var iterations:int = txt.match(pattern).length;
for(var i:int=0; i<iterations; i++) {
for(var prop:String in diction) {
txt = txt.replace(prop, diction[prop]);
}
}
return txt;
}
}
}