Syllable Mixer/Word Generator [Attempt 2]
The objective for this code is to:
1. Display a clickable button and text field for the result.
2. Create a new random word based on the syllables in two (or more) arrays when the button is pressed.
♥0 |
Line 47 |
Modified 2011-02-28 00:43:03 |
MIT License
archived:2017-03-09 22:29:50
ActionScript3 source code
/**
* Copyright simplyJenGrier ( http://wonderfl.net/user/simplyJenGrier )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/rHD5
*/
// The objective for this code is to:
// 1. Display a clickable button and text field for the result.
// 2. Create a new random word based on the syllables in two (or more) arrays when the button is pressed.
package {
import flash.display.Sprite;
import flash.text.TextField;
import flash.events.*;
public class ButtonInteractivity extends Sprite {
private var button:Sprite = new Sprite();
private var resultField:Sprite = new Sprite();
private var resultName:TextField = new TextField();
public function Button() {
drawButton()
button.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
addChild(button);
drawText()
addChild(resultName);
}
//Ripped from a tutorial... was working until I messed up a whole bunch :$
private function drawButton():void {
var textLabel:TextField = new TextField()
button.graphics.clear();
button.graphics.beginFill(0xD4D4D4); // grey color
button.graphics.drawRoundRect(0, 0, 80, 25, 10, 10); // x, y, width, height, ellipseW, ellipseH
button.graphics.endFill();
textLabel.text = "Click Me!";
textLabel.x = 10;
textLabel.y = 5;
textLabel.selectable = false;
button.addChild(textLabel)
}
private function drawText():void {
resultField.graphics.beginFill(0x111111);
//Need some other stuff about
resultName.x = 50;
resultName.y = 50;
}
private function mouseDownHandler(event:MouseEvent):void {
//The button was displaying before... but now it doesn't work and I can't seem to get it back... :(
button.x += 20
if (button.x > 400) { button.x = 0}
//All the code for the syllables, randomizing, and displaying of a result... why won't it work?
var myName:String = new String;
var random1:Number = new Number;
var random2:Number = new Number;
var syllable1:Array = new Array("Awe","Bal","Bos","Dop","Hal","Har","Hed","Loo","Nei","Pra","Run","Se");
var syllable2:Array = new Array("rod","do","gan","deg","ger","bum","la","fre","na","mu","se");
random1 = Math.floor(Math.random() * syllable1.length);
random2 = Math.floor(Math.random() * syllable2.length);
myName = syllable1[random1] + " " + syllable2[random2];
resultName.text = "Your new name is: " + myName;
}
}
}