Share
View previous topicGo downView next topic
avatar
Moderator
Moderator
Age : 19
Number of posts : 9196
Registration date : 2009-05-23
Reputation : 3
Location : Brazil
View user profile

automated textboxes (AS2)

on 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)
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);
additionally, if you DO use a sound, then make sure its volume is low, because if it gets repeated a lot it adds up and gets really loud. that and it would be annoying. so keep its volume low.
Spoiler:



did this kinda fast, so if you have any problems, feel free to tell me!
avatar
Spritan
Spritan
Age : 23
Number of posts : 627
Registration date : 2013-11-03
Reputation : 0
Location : Hyrule Castle
View user profilehttps://www.facebook.com/TJ Callwoodhttps://twitter.com/tjcallwood

Re: automated textboxes (AS2)

on 12/31/2013, 1:21 am
Damn talk about an enhanced tutorial without all the annoying YouTube stuff. Thanks Leo, this is really helpful.


avatar
Administrator
Administrator
Age : 22
Number of posts : 13137
Registration date : 2009-03-28
Reputation : 12
View user profile

Re: automated textboxes (AS2)

on 1/8/2014, 2:15 pm
Yay! Action script stuff!

Well done man.




[The Return]
avatar
Spritan
Spritan
Age : 21
Number of posts : 20163
Registration date : 2010-09-15
Reputation : 8
Location : Madison Wisconsin
View user profile

Re: automated textboxes (AS2)

on 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! (:



@darkdragon581 wrote:ping, i don't see you getting 'boodie' anytime soon, i don't care if your black, its most likely not going to happen
avatar
Administrator
Administrator
Age : 22
Number of posts : 4788
Registration date : 2009-01-23
Reputation : 86
Location : Hollow Bastion
View user profile

Re: automated textboxes (AS2)

on 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.
avatar
Moderator
Moderator
Age : 19
Number of posts : 9196
Registration date : 2009-05-23
Reputation : 3
Location : Brazil
View user profile

Re: automated textboxes (AS2)

on 1/11/2014, 6:07 pm
yeah, before i thought this was really hard to pull off. fortunately i was wrong
avatar
Spritan
Spritan
Age : 19
Number of posts : 1302
Registration date : 2010-11-05
Reputation : 0
Location : Earth
View user profile

Re: automated textboxes (AS2)

on 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.


avatar
Moderator
Moderator
Age : 19
Number of posts : 9196
Registration date : 2009-05-23
Reputation : 3
Location : Brazil
View user profile

Re: automated textboxes (AS2)

on 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)
Code:
onClipEvent(enterFrame){
   this._x = _root.vcam_x;
   this._y = _root.vcam_y;
   this._xscale = _root.vcam_xscale;
   this._yscale = _root.vcam_yscale;
}
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*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.


Last edited by Leo on 1/11/2014, 7:21 pm; edited 1 time in total
avatar
Spritan
Spritan
Age : 19
Number of posts : 1302
Registration date : 2010-11-05
Reputation : 0
Location : Earth
View user profile

Re: automated textboxes (AS2)

on 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)
Code:
onClipEvent(enterFrame){
   this._x = _root.vcam_x;
   this._y = _root.vcam_y;
   this._xscale = _root.vcam_xscale;
   this._yscale = _root.vcam_yscale;
}
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*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.


View previous topicBack to topView next topic
Permissions in this forum:
You cannot reply to topics in this forum