Reputation: 4555
I recently started fiddling around with as3, which look pretty good, problem is I come from as2 and I'm completely lost.
I'm tring to import text from 4 text files then move them on on top of the other:
text1 x = 100, text2 x=150 text3 x=200 etc..
Here is where I'm stuck:
import flash.display.MovieClip;
import flash.display.Loader;
import flash.events.*;
import flash.net.URLRequest;
import caurina.transitions.Tweener;
var myTextLoader:URLLoader = new URLLoader();
var myTextField_txt:TextField = new TextField();
myTextField_txt.wordWrap=true;
myTextField_txt.autoSize=TextFieldAutoSize.CENTER;
var i:int = 0;
var ipsilon:int = 200;
for(i;i<5;i++) {
myTextLoader.addEventListener(Event.COMPLETE, onLoaded);
myTextLoader.load(new URLRequest("text"+i+".txt"));
}
function onLoaded(e:Event):void {
var testo = e.target.data;
styleMe(testo);
}
function styleMe(testo){
//Associamo il testo alla variabile
myTextField_txt.text = testo;
//Formato Carattere
var myFormat:TextFormat = new TextFormat();
myFormat.size = 15;
myFormat.align = TextFormatAlign.CENTER;
myTextField_txt.defaultTextFormat = myFormat;
//Formato Varie
myTextField_txt.textColor = 0x000000;
myTextField_txt.border = true;
myTextField_txt.borderColor = 0x999999;
myTextField_txt.width = 200;
myTextField_txt.height = 20;
myTextField_txt.background = true;
myTextField_txt.backgroundColor = 0xFFCC00;
//Posizione
myTextField_txt.x = 0;
myTextField_txt.y = -100;
var text1 = addChild(myTextField_txt);
tweenMe(text1);
}
function tweenMe(text1){
Tweener.addTween(text1, {x:450,y:200, time:5});
}
I can't understand how do I tell actionscript to move them in different position.
Thank you very much for your patience
David
Upvotes: 0
Views: 273
Reputation: 15623
uhm, there would be a hacky solution ... but you should try a clean solution, using classes ...
i am not completely sure, what you want to do, but this should do the trick:
package {
import caurina.transitions.Tweener;
import flash.events.Event;
import flash.net.*;
import flash.text.*;
public class MyText extends TextField {
private var _tweenParams:Object;
public function MyText(location:String, tweenParams:Object, initVars:Object = null) {
this._tweenParams = { };
for (var name:String in tweenParams) this._tweenParams[name] = tweenParams[name];
for (name in initVars) this[name] = initVars[name];
(new URLLoader(new URLRequest(location))).addEventListener(Event.COMPLETE, onLoad);
var myFormat:TextFormat = new TextFormat();
myFormat.size = 15;
myFormat.align = TextFormatAlign.CENTER;
this.defaultTextFormat = myFormat;
this.textColor = 0x000000;
this.border = true;
this.borderColor = 0x999999;
this.width = 200;
this.height = 20;
this.background = true;
this.backgroundColor = 0xFFCC00;
}
private function onLoad(e:Event):void {
this.text = e.target.data;
Tweener.addTween(this, this._tweenParams);
}
}
}
and then just use it like this:
this.addChild(new MyText("text1.txt",{x:0,y:0, time:5},{y:-100}));
this.addChild(new MyText("text2.txt",{x:200,y:0, time:5},{y:-100}));
this.addChild(new MyText("text3.txt",{x:400,y:0, time:5},{y:-100}));
this.addChild(new MyText("text4.txt",{x:600,y:0, time:5},{y:-100}));
hope that helps ...
greetz
back2dos
Upvotes: 1