Speech Class Reference Manual


BACK TO README.htm

Here's a list of all the methods, properties and events contained in the Speech class. The Speech class controls the text written into a speech balloon.

When the Speech object is told to write a text, it will fill the text in letter by letter as each frame passes. How many letters are written in each frame depends on the textSpeed property.


Index

Methods
Speech Constructor.
say Writes a phrase into the speech balloon.
clearSpeech Stops writing text into the speech balloon, empties the text of the speech balloon and makes it invisible.
setEvent Makes the Speech object listen for a specific event, then write text when the event is fired.
getEvent Returns an object representing an event the Speech object is listening for.
clearEvent Stops the Speech object from listening for a specific event.
listenTo Makes the Speech object listen to a specific Expansion object for "checkpoint" events.
setCheckPoint Makes the Speech object listen for a specific Expansion checkpoint.
getCheckPoint Returns an object representing a checkpoint the Speech object is listening for.
clearCheckPoint Stops the Speech object from listening for a specific Expansion checkpoint.
destroy Clears out the Speech object and stops it from listening to events.
Properties
textField A reference to the TextField object representing the text of the speech balloon.
contained Indicates whether the DisplayObjectContainer containing the TextField is also part of the speech balloon.
textSpeed Indicates how many letters are written into the TextField in each frame.
position Indicates the position of the next character to be written into the TextField.
phrase The current text to be written into the TextField.
timer The number of frames left before the speech balloon becomes invisible.
speaking Indicates whether letters are being printed onto the screen or not.
interruptionText The text to be written if the Speech object is interrupted when writing a word.
interruptible Indicates whether a text can be interrupted by another text or not.
Events
"speechFinished" Indicates that the Speech object has finisheed writing all the letter of the text.
"speechCleared" Indicates that the speech balloon is finished displaying the text and will become invisible.

Methods


Speech()

public function Speech(txt0:TextField,contained0:Boolean=true))

Creates a new Speech object, which represents a speech balloon. The first parameter is the TextField to write the text into. The second parameter indicates whether the object containing the TextField should be considered part of the speech balloon. The recommended value is true.

When the Speech object is created, the TextField's visible property is set to false and the text property is set to "". If the second parameter is set to true, the parent object of the TextField also has its visible property set to false.

Parameters

txt0:TextField A reference to the Textfield object to be used when writing text.
contained0:Boolean Indicated whether the object containing the TextField is considered part of the speech balloon.

say()

public function say(phrase0:String, wait:int=-1)

Makes the speech balloon visible and starts writing text into it. The first parameter indicates the teext to be written into the speech balloon. The second parameter indicates now many frames to wait after the text has been written into the speech balloon.

Once this function has been called, the program will write letters into the TextField object in each frame until the entire text has been written. Once the text has been written, the timer will decrease by 1 in each frame until it reaches 0. When this happens, the speech balloon will become invisible.

If say() is called again before the text has finished writing, one of two possible things will happen:

After doing one of these two things, the speech balloon will start writing the new text into the TextField object normally.

Parameters

phrase0:String The text to be written into the speech balloon.
wait:int The number of frames to wait after the text has finished being written into the TextField. A value of -1 will use the default value, given by the expression phrase0.length+20.

clearSpeech()

public function clearSpeech()

Stops writing into the TextField object, clears the text of the TextField object and makes the speech balloon invisible.

If you want to stop the speech balloon from writing text without clearing the text or becoming invisible, call the say() function using an empty string as the first parameter.


setEvent()

public function setEvent(obj0:EventDispatcher,type0:String,phrase0:String,time0:int=-1)

Makes the Speech object write a text when it receives a specific event. This is equivalent to calling the say() function when the event is triggered, as seen in the following code:

obj0.addEventListener(type0,fn);
function fn(E:Event){
   speech.say(phrase0,time0);
}

Parameters

obj0:EventDispatcher The EventDispatcher object that will trigger the event to listen for.
type0:String The type of event to listen for.
phrase0:String The text to write when the event is triggered.
time0:int The time to wait after the text is finished being written. See the say() function for more information on the timer.

getEvent()

public function getEvent(obj0:EventDispatcher,type0:String):Object

Returns an object representing the event the Speech object is listening for. If the Speech object is not listening to the event given by the parameters, the function returns null.

Parameters

obj0:EventDispatcher The EventDispatcher object that triggers the event.
type0:String The name of the event being listened for.

Returns

An object representing the event the Speech object is listening for. The object has the following properties:

object The EventDispatcher object that triggers the event.
type The name of the event being listened for.
phrase The text that will be written when the event is fired.
time The timer parameter used in the say() function.

clearEvent()

public function clearEvent(obj0:EventDispatcher,type0:String)

Stops listening for the event given by the parameters. If the Speech object is not listening for this event, the function has not effects.

Parameters

obj0:EventDispatcher The EventDispatcher object that triggers the event.
type0:String The name of the event being listened for.

listenTo()

public function listenTo(exp:Expansion)

Causes the Speech object to listen to "checkpoint" events from the Expansion object given by the first parameter.

Parameters

stage:Stage A reference to the stage. Used for the enterFrame event handling.

Notes

Note: In order for the checkpoint of the Expansion object to have an effect on the Speech object, both of the objects must have called their respecting setCheckPoint() functions with the corresponding parameters, as seen in the following example:

//Assume these exist on the stage
var mc;MovieClip;
var txt:TextField;

//Initialize variables
var exp:Expansion;
var id:int = exp.insertExpandable(mc);
var speech:Speech = new Speech(txt);

//Setting checkpoints
exp.setCheckPoint(id,20,1);
speech.setCheckPoint(exp.getExpandable(id),20,1,"Checkpoint at size 20!",-1);

speech.listenTo(exp);

setCheckPoint()

public function setCheckPoint(part0:MovieClip,size0:int,dir0:int=1,phrase0:String="",time0:int=-1)

Makes the Speech object listen for a "checkpoint" event from an Expansion object. the first three parameters are used to determine which "checkpoint" event to listen to. The last two parameters are used in the say() function triggered by the event.

Learn more about checkpoints in the Expansion class tutorial. Also, see listenTo() to find out more about Speech checkpoints.

Parameters

part0:MovieClip The MovieClip associated with the expandable part to watch.
size0:int The size to watch for.
dir0:int The direction of the expansion to watch for. The value 1 indicates an increasing expansion and the value -1 indicates a decreasing expansion.
phrase0:String The phrase to write into the TextField when the "checkpoint" event is triggered.
time0:int The number of frames to wait after the Speech object has finished writing all the characters into the TextField object.

Notes

Note: The listenTo() function must be called in order for the Speech object to receive events from an Expansion object.


getCheckPoint()

public function getCheckPoint(part0:MovieClip,size0:int,dir0:int=1):Object

Returns an object representing the checkpoint being watched by the Speech object. If the Speech object is not watching the specified checkpoint, the function returns null.

Learn more about checkpoints in the Expansion class tutorial. Also, see listenTo() to find out more about Speech checkpoints.

Parameters

part0:MovieClip The MovieClip associated with the expandable part to watch.
size0:int The size to watch for.
dir0:int The direction of the expansion to watch for. The value 1 indicates an increasing expansion and the value -1 indicates a decreasing expansion.

Returns

An object representing the checkpoint being watched by the Speech object. The returned object has the following properties:

part:MovieClip The MovieClip associated with the expandable part to watch.
size:int The size to watch for.
direction:int The direction of the expansion to watch for. The value 1 indicates an increasing expansion and the value -1 indicates a decreasing expansion.
phrase:String The phrase to write into the TextField when the "checkpoint" event is triggered.
time:int The number of frames to wait after the Speech object has finished writing all the characters into the TextField object.

clearCheckPoint()

public function clearCheckPoint(part0:MovieClip,size0:int,dir0:int=1)

If the Speech object is listening for the checkpoint specified by the parameters, it stops listening. If not, this function has no effect.

Learn more about checkpoints in the Expansion class tutorial. Also, see listenTo() to find out more about Speech checkpoints.

Parameters

part0:MovieClip The MovieClip associated with the expandable part to watch.
size0:int The size to watch for.
dir0:int The direction of the expansion to watch for. The value 1 indicates an increasing expansion and the value -1 indicates a decreasing expansion.

destroy()

public function destroy()

Clears out the Speech object and stops it from listening to any events. Always remember to call this function whenever you plan to stop using the Speech object. Otherwise, some event handlers may remain in memory and cause memory leaks.


Properties


textField

public function get textField():TextField

A read-only value. Returns the TextField object where the text is written when the say() function is called.


contained

public function get contained():Boolean
public function set contained(n:Boolean)

Indicates whether the DisplayObjectContiainer containing the TextField object should be considered a part of the speech balloon or not.

If this value is set to true, the visible property of the DisplayObjectContiainer containing the TextField object will take the same value as the TextField's visible property.

If this value is set to false after previously having been true, the visible property of the DisplayObjectContiainer containing the TextField object will be set to true


textSpeed

public function get textSpeed():int
public function set textSpeed(n:int)

Indicates how many letters to write into the TextField in each frame. This value can be 1 or greater.


position

public function get position():int

A read-only value. The position of the next letter that will be written into the TextField object.


phrase

public function get phrase():String

A read-only value. The text to be written into the TextField object.


timer

public function get timer():int

A read-only value. The number of frames left before the TextField's visible property is set to false. This value is only accurate after the Speech object has finished writing all of the characters into the TextField.


speaking

public function get speaking():Boolean

A read-only value. Indicates whether the Speech object is writing characters into the TextField object. This value becomes false after the last character is written, even if the TextField is still visible.


interruptionText

public function get interruptionText():String
public function set interruptionText(n:String)

The text to be written when the say() function is called while the Speech object is still writing characters into the TextField. The default value is "--".

To learn more about interruptions, read the Speech class tutorial.


interruptible

public function get interruptible():Boolean
public function set interruptible(n:Boolean)

Indicates whether the Speech object can be interrupted while writing a text. The default value is true. If this value is false, the say() function will have no effect while the Speech object is writing text.

To learn more about interruptions, read the Speech class tutorial.


Events


"speechFinished"

"speechFinished"

This event fires when all of the characters have been written into the TextField object, after calling the say() function.


"speechCleared"

"speechCleared"

This event fires when the timer reaches 0 after writing text into the TextField. By the time this event fires, the text property of the TextField has been set to "" and the visible property has been set to false.


BACK TO README.htm

© 2014 Doom the wolf. http://doom-the-wolf.deviantart.com