- LeoAdministrator
- Age : 25
Number of posts : 9153
Registration date : 2009-05-23
Location : Brazil
automated textboxes (AS2)
12/31/2013, 12:58 am
hi again
got a few requests on how to do this, so here it goes. won't really explain the code in detail, as i don't feel like doing that. just google "typewriter effect" or whatever, if you really want to know.
Step 1
create your dynamic text box and give it the instance name of "text_txt" (without the quotes, obviously)
Step 2
create the graphic for your textbox. i'm lazy so i'll just use a black rectangle here, but you can be as fancy as you want. you can also just grab one from a game or something
Step 3
take both the text and the graphic and put those in a movieclip. then give it the instance name of "textHolder". the reason i'm doing this is so that i can just drag this symbol from the library, whenever i need to use it, instead of copy-pasting these everytime. that and if i use the automated parallax code on my animation, i can apply it to this as well (won't cover how to do it here though) (yeah i'm really lazy)
Step 4
then copy and paste this code on the frame you want to use this (the little animation i did was for clarity - so you could see it looping and whatnot):
Step 5 (optional)
if you want to add sound to this, then give the sound an identifier (can be whatever name you want, but here i'm using "soundText"), then change the code to this:
did this kinda fast, so if you have any problems, feel free to tell me!
got a few requests on how to do this, so here it goes. won't really explain the code in detail, as i don't feel like doing that. just google "typewriter effect" or whatever, if you really want to know.
Step 1
create your dynamic text box and give it the instance name of "text_txt" (without the quotes, obviously)
- Spoiler:
Step 2
create the graphic for your textbox. i'm lazy so i'll just use a black rectangle here, but you can be as fancy as you want. you can also just grab one from a game or something
- Spoiler:
Step 3
take both the text and the graphic and put those in a movieclip. then give it the instance name of "textHolder". the reason i'm doing this is so that i can just drag this symbol from the library, whenever i need to use it, instead of copy-pasting these everytime. that and if i use the automated parallax code on my animation, i can apply it to this as well (won't cover how to do it here though) (yeah i'm really lazy)
- Spoiler:
Step 4
then copy and paste this code on the frame you want to use this (the little animation i did was for clarity - so you could see it looping and whatnot):
- Code:
var contentField:String = "change this to your text";
var charLength:Number = length(contentField);
var charNr:Number = 0;
var charNr2:Number = 0;
var speed:Number = 20;//milliseconds
function showChar():Void {
if (charNr<charLength) {
charNr++;
_root.textHolder.text_txt.text = contentField.substr(0, charNr);
_root.textHolder.text_txt.setTextFormat(my_fmt);
} else {
clearInterval(showCharX);
}
}
var showCharX:Number = setInterval(showChar, speed);
clearInterval(showCharDelayX);
- Spoiler:
Step 5 (optional)
if you want to add sound to this, then give the sound an identifier (can be whatever name you want, but here i'm using "soundText"), then change the code to this:
- Code:
var contentField:String = "change this to your text";
var charLength:Number = length(contentField);
var charNr:Number = 0;
var charNr2:Number = 0;
var speed:Number = 20;//milliseconds
function showChar():Void {
if (charNr<charLength) {
charNr++;
var typing_sound = new Sound(this);
typing_sound.attachSound("soundText");
//soundText is the identifier
typing_sound.start(0, 1);
_root.textHolder.text_txt.text = contentField.substr(0, charNr);
_root.textHolder.text_txt.setTextFormat(my_fmt);
} else {
clearInterval(showCharX);
}
}
var showCharX:Number = setInterval(showChar, speed);
clearInterval(showCharDelayX);
- Spoiler:
did this kinda fast, so if you have any problems, feel free to tell me!
Re: automated textboxes (AS2)
12/31/2013, 1:21 am
Damn talk about an enhanced tutorial without all the annoying YouTube stuff. Thanks Leo, this is really helpful.
- PattAdministrator
- Age : 28
Number of posts : 13124
Registration date : 2009-03-28
Re: automated textboxes (AS2)
1/8/2014, 2:15 pm
Yay! Action script stuff!
Well done man.
Well done man.
- PingSpritan
- Age : 27
Number of posts : 20149
Registration date : 2010-09-15
Location : Madison Wisconsin
Re: automated textboxes (AS2)
1/8/2014, 4:09 pm
I found this very thorough and beneficial. This tutorial provides good highlights to action scripting. The sound option proves that exemplary. Thanks Leo! (:
Re: automated textboxes (AS2)
1/11/2014, 5:21 pm
Your tutorials are so high quality! This is awesome.
Also, I never realized how simple this code actually was, holy shit.
Also, I never realized how simple this code actually was, holy shit.
- LeoAdministrator
- Age : 25
Number of posts : 9153
Registration date : 2009-05-23
Location : Brazil
Re: automated textboxes (AS2)
1/11/2014, 6:07 pm
yeah, before i thought this was really hard to pull off. fortunately i was wrong
- YoshiSonicSpritan
- Age : 25
Number of posts : 1299
Registration date : 2010-11-05
Location : Earth
Re: automated textboxes (AS2)
1/11/2014, 6:44 pm
You should do the Parallax code next meng, it's really confusing, but eh, doing it by yourself works also.
- LeoAdministrator
- Age : 25
Number of posts : 9153
Registration date : 2009-05-23
Location : Brazil
Re: automated textboxes (AS2)
1/11/2014, 6:53 pm
the parallax code is really easy (and kind of weird with zooms, but it will do because no one has a better engine, except for lange but ITS LANGE)
basically, you just give your vcam the instance name of vcam, then click on the bg movieclip that you want to apply the parallax and write this (AS2)
and you can change the 0.8 to something else. the closer it is to 1, the less it moves.
basically, you just give your vcam the instance name of vcam, then click on the bg movieclip that you want to apply the parallax and write this (AS2)
- Code:
onClipEvent(enterFrame){
this._x = _root.vcam_x;
this._y = _root.vcam_y;
this._xscale = _root.vcam_xscale;
this._yscale = _root.vcam_yscale;
}
- Code:
onClipEvent(enterFrame){
this._x = _root.vcam_x*0.8;
this._y = _root.vcam_y*0.8;
this._xscale = _root.vcam._xscale;
this._yscale = _root.vcam._yscale;
}
and you can change the 0.8 to something else. the closer it is to 1, the less it moves.
- YoshiSonicSpritan
- Age : 25
Number of posts : 1299
Registration date : 2010-11-05
Location : Earth
Re: automated textboxes (AS2)
1/11/2014, 7:02 pm
Leo wrote:the parallax code is really easy (and kind of weird with zooms, but it will do because no one has a better engine, except for lange but ITS LANGE)
basically, you just give your vcam the instance name of vcam, then click on the bg movieclip that you want to apply the parallax and write this (AS2)
that's if you want it to be static. if you want it to move then it's more like
- Code:
onClipEvent(enterFrame){
this._x = _root.vcam_x;
this._y = _root.vcam_y;
this._xscale = _root.vcam_xscale;
this._yscale = _root.vcam_yscale;
}
- Code:
onClipEvent(enterFrame){
this._x = _root.vcam_x*0.8;
this._y = _root.vcam_y*0.8;
this._xscale = _root.vcam_xscale;
this._yscale = _root.vcam_yscale;
}
and you can change the 0.8 to something else. the closer it is to 1, the less it moves.
By instance name do you mean--
Wait I don't want to flood this thread with you helping me. I'll pm you.
Permissions in this forum:
You cannot reply to topics in this forum