View Full Version : [FLASH5] help with strings
Felipe Bastos
October 1st, 2003, 01:38 PM
Hello! I'm using flash 5 to develop a dynamic banner. It loads a txt file in an single line text field that moves from right to left, similar an electronic bank display. What I need is to check when the last character of the text loaded gets out of the stage (-x), so I can send the text field to its original position simulating a continuous loop animation. (I could do this using flashMX cause the text field scales according to the text size but I have to use flash5 :( ). If u can help me with this or sugest another solution for checking the textfield size in flash5 I'll be very thankfull! see u... Felipe Bastos.
lostinbeta
October 1st, 2003, 01:42 PM
Why don't you put the textfield inside a movie clip symbol (which you need to do to make it scroll anyway) and then go by the _width property of the movieclip symbol. The width is determined by solid content, so it will read up to the last character in the textbox. Just set the registration point all the way to the left (you can do this in the creation of the clip in MX, but i'm not sure how it works in Flash 5)
lostinbeta
October 1st, 2003, 01:48 PM
Ok, I tried this and it works...
1) Create text field
2) Click on textfield and convert to movie clip symbol with registration point on left side (center)
3) Right click on the movie clip symbol and open the actions panel. Then use these actions... onClipEvent (load) {
//start on right side of movie
this._x = 550;
//position vertical
this._y = 200;
}
onClipEvent (enterFrame) {
//move clip left 10 pixels repeatedly
this._x -= 10;
//if the clips is off the left side of the stage
if (this._x<=-this._width) {
//start it again all the way on the right side
this._x = 550;
}
}
Felipe Bastos
October 1st, 2003, 01:57 PM
I tried that but didnt work. The textfield in flash5 doesnt resize according to the txt file like in flashMX. It has to work with whatever the testfield width is (the txt file will be constantily updated!). The textfield is already inside a movie clip that contains some graphics (logos). !!!!
Felipe Bastos
October 1st, 2003, 02:08 PM
Here is the fla and the txt file!
lostinbeta
October 1st, 2003, 02:10 PM
This is where it sucks that I have no clue about Flash 5.
I am guessing you will need to guestimation the width of each letter and multiply that by the length of the string.
For example (I used Verdana size 10, which left me with a spacing of approximate 7px per letter) onClipEvent (load) {
this._x = 550;
this._y = 200;
var boxWidth = this.ranQuote.length*7;
}
onClipEvent (enterFrame) {
this._x -= 5;
if (this._x<=-boxWidth) {
this._x = 550;
}
}
sorry, didn't see you posted your .fla
Felipe Bastos
October 1st, 2003, 02:23 PM
Thanks! This will help me a lot.
See u.
lostinbeta
October 1st, 2003, 02:43 PM
Ok a few things...
You can't get the textboxes text length on load because you are loading it dynamically so it doesn't get loaded right away. Since Flash 5 has no dynamic event handler for onLoad of the variables (via loadVars() object) I ran a thing on enterframe that checks to make sure texto was not undefined.
I also move the textbox, then resized it to 1000.9 (It wouldn't let me get a whole number and if I set it manually in the properties the text would stretch) and then put the textbox back where you had it.
I then checked if the value of texto was defined and when it was I used the method I posted in my last post to get how long the text was, and I used the width of the textbox (1000.9) and subtracted the length of the string to get the remainder of empty textbox space leftover.
After that I created another variable to hold the value of the total clip width minus the remainder empty textbox space.
I ended up with this... onClipEvent (load) {
this._x = 170;
this._y = 8;
}
onClipEvent (enterFrame) {
//if the texto textbox is not undefined
if (this.texto != undefined) {
//get the remainder of empty textbox space
//1000.9 is the width of the textbox (got info from properties panel)
//9 is the estimated pixel width of each character
var textBoxWidth = 1000.9-(this.texto.length*9);
//subtract that remainder width from the clips total width
var wholeWidth = this._width-textBoxWidth;
}
this._x -= 3;
if (this._x<=-wholeWidth) {
this._x = 170;
}
}
It seems to work good, I think :-\ :P
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.