Home
> FlashEff 2.0
> Topic
RANDOM TEXT FROM AN ARRAY
Posted by xFLASHSTUDENTx
RANDOM TEXT FROM AN ARRAY February 09, 2010 04:32PM | Registered: 15 years ago Posts: 8 |
What's good Flash coders?
I'm trying to do a looping show and hide text effect with Random text pulled from an array instead of just having one text field for the effects.
Here's the code from the actionscript 3.0 usage manual that creates a looping show and hide text effect with actionscript:
// Import the necessary classes.
import com.jumpeye.Events.FLASHEFFEvents;
import com.jumpeye.flashEff2.text.magneticWind.FETMagneticWind;
import com.jumpeye.flashEff2.text.xyscale.FETXYScale;
// Create the text format for the font.
var txtFormat:TextFormat = new TextFormat();
txtFormat.font = "Lucida Sans";
txtFormat.align = "center";
txtFormat.color = 0x0099FF;
txtFormat.size = 40;
// Create the text field, set it up and add it to the display list.
var myText:TextField = new TextField();
myText.type = "dynamic";
myText.embedFonts = true;
myText.antiAliasType = "advanced";
myText.multiline = true;
myText.wordWrap = true;
myText.autoSize = "center";
addChild(myText);
// Add the text into the text field (text should be as HTML).
myText.defaultTextFormat = txtFormat;
myText.htmlText = "The quick brown fox jumps over the lazy dog";
// Center the text field on the stage.
myText.width = 350;
myText.x = (stage.stageWidth - myText.width) / 2;
myText.y = (stage.stageHeight - myText.height) / 2;
// Create the FlashEff2Code instance and add it to the stage. The FlashEff2Code
// component must be in the display list in order for it to work.
var effect:FlashEff2Code = new FlashEff2Code();
effect.addEventListener(FLASHEFFEvents.TRANSITION_END, replay);
addChild(effect);
// Create the show pattern instance (FESBrightSquares) and set it
// so the effect looks as you like.
var showEffect:FETMagneticWind = new FETMagneticWind();
showEffect.randomX = 200;
showEffect.randomY = 50;
showEffect.groupDuration = 1.5;
showEffect.tweenDuration = 2;
// Create the hide pattern instance (FESEqualizer) and set it
// so the effect looks as you like.
var hideEffect:FETXYScale = new FETXYScale();
hideEffect.positionX = -15;
9
hideEffect.positionY = -50;
hideEffect.preset = 9; // char: random
hideEffect.groupDuration = 1.5;
hideEffect.tweenDuration = 2;
// Assign the show and hide transitions to the FlashEff2Code instance.
effect.showTransition = showEffect;
effect.hideTransition = hideEffect;
// There will be a 3 seconds pause between the show and hide transitions.
effect.hideDelay = 3;
// Set the target text field to the FlashEff2Code instance. Once you do this,
// the show effect will start immediately (except the case when the
// show effect has a delay too).
effect.target = myText;
// When the "hide" transition ends, start the show effect again.
function replay(evt:FLASHEFFEvents):void {
if (effect.currentTransitionType == "hide") {
effect.show();
}
}
and here's the code I tried to use to made random text:
var randomText:Array=["Bimmer fanatics","Flash Fanatic","certified go-getta","relentless paper chaser"];
myText.htmlText = randomText;
That obviously didn't work. Instead, Flash just printed the whole array.
Can anyone assist me in setting this code for random text and random patters? I know I would need to an an array of patters, but I'm stuck right here.
I'm trying to do a looping show and hide text effect with Random text pulled from an array instead of just having one text field for the effects.
Here's the code from the actionscript 3.0 usage manual that creates a looping show and hide text effect with actionscript:
// Import the necessary classes.
import com.jumpeye.Events.FLASHEFFEvents;
import com.jumpeye.flashEff2.text.magneticWind.FETMagneticWind;
import com.jumpeye.flashEff2.text.xyscale.FETXYScale;
// Create the text format for the font.
var txtFormat:TextFormat = new TextFormat();
txtFormat.font = "Lucida Sans";
txtFormat.align = "center";
txtFormat.color = 0x0099FF;
txtFormat.size = 40;
// Create the text field, set it up and add it to the display list.
var myText:TextField = new TextField();
myText.type = "dynamic";
myText.embedFonts = true;
myText.antiAliasType = "advanced";
myText.multiline = true;
myText.wordWrap = true;
myText.autoSize = "center";
addChild(myText);
// Add the text into the text field (text should be as HTML).
myText.defaultTextFormat = txtFormat;
myText.htmlText = "The quick brown fox jumps over the lazy dog";
// Center the text field on the stage.
myText.width = 350;
myText.x = (stage.stageWidth - myText.width) / 2;
myText.y = (stage.stageHeight - myText.height) / 2;
// Create the FlashEff2Code instance and add it to the stage. The FlashEff2Code
// component must be in the display list in order for it to work.
var effect:FlashEff2Code = new FlashEff2Code();
effect.addEventListener(FLASHEFFEvents.TRANSITION_END, replay);
addChild(effect);
// Create the show pattern instance (FESBrightSquares) and set it
// so the effect looks as you like.
var showEffect:FETMagneticWind = new FETMagneticWind();
showEffect.randomX = 200;
showEffect.randomY = 50;
showEffect.groupDuration = 1.5;
showEffect.tweenDuration = 2;
// Create the hide pattern instance (FESEqualizer) and set it
// so the effect looks as you like.
var hideEffect:FETXYScale = new FETXYScale();
hideEffect.positionX = -15;
9
hideEffect.positionY = -50;
hideEffect.preset = 9; // char: random
hideEffect.groupDuration = 1.5;
hideEffect.tweenDuration = 2;
// Assign the show and hide transitions to the FlashEff2Code instance.
effect.showTransition = showEffect;
effect.hideTransition = hideEffect;
// There will be a 3 seconds pause between the show and hide transitions.
effect.hideDelay = 3;
// Set the target text field to the FlashEff2Code instance. Once you do this,
// the show effect will start immediately (except the case when the
// show effect has a delay too).
effect.target = myText;
// When the "hide" transition ends, start the show effect again.
function replay(evt:FLASHEFFEvents):void {
if (effect.currentTransitionType == "hide") {
effect.show();
}
}
and here's the code I tried to use to made random text:
var randomText:Array=["Bimmer fanatics","Flash Fanatic","certified go-getta","relentless paper chaser"];
myText.htmlText = randomText;
That obviously didn't work. Instead, Flash just printed the whole array.
Can anyone assist me in setting this code for random text and random patters? I know I would need to an an array of patters, but I'm stuck right here.
Re: RANDOM TEXT FROM AN ARRAY February 10, 2010 12:04AM | Registered: 15 years ago Posts: 6 |
Re: RANDOM TEXT FROM AN ARRAY February 13, 2010 11:10PM | Registered: 15 years ago Posts: 8 |
Thanks for that, but I need to convert the array to strings I've found via the output panel. Thus, when i add this code:
myText.htmlText = Math.floor(Math.random ()*randomText.length);
I get this error:
1067: Implicit coercion of a value of type Number to an unrelated type String.
so the array seems to be a number, and the htmlText is looking for a string. ISo I need to figure out how to convert the array to a string (which I can do) , but I need code it right... I need help with that....anyone else want to assist? This would be useful code to everyone...
myText.htmlText = Math.floor(Math.random ()*randomText.length);
I get this error:
1067: Implicit coercion of a value of type Number to an unrelated type String.
so the array seems to be a number, and the htmlText is looking for a string. ISo I need to figure out how to convert the array to a string (which I can do) , but I need code it right... I need help with that....anyone else want to assist? This would be useful code to everyone...
Re: RANDOM TEXT FROM AN ARRAY March 25, 2010 06:19PM | Registered: 15 years ago Posts: 8 |
Re: RANDOM TEXT FROM AN ARRAY March 26, 2010 12:04PM | Registered: 15 years ago Posts: 3 |
Sorry, you do not have permission to post/reply in this forum.