Jun 26
Form Validation - Using Components
Quick and easy way to validate a form that uses components.
Sample Code:
//REQUIRED You can use any of the string validators for the txtinputs var tempPhone:PhoneNumberValidator = new PhoneNumberValidator(); //REQUIRED reference the actual textinput tempPhone.source = this.txtPhone; //REQUIRED the property of the component to validate tempPhone.property = "text"; // the prompt to be displayed in the text field. tempPhone.prompt = "Phone Number"; // If this validator is enabled tempPhone.enabled = true; // the required message tempPhone.requiredFieldError = "Error :: Phone (xxx-xxx-xxxx)"; // REQUIRED whether or not the field is required tempPhone.required = true; // max length tempPhone.maxLength = 12; // min length tempPhone.minLength = 10; // the event fired if invalid tempPhone.addEventListener(ValidationResultEvent.INVALID, onInvalid); // the event fired if valid tempPhone.addEventListener(ValidationResultEvent.VALID, onValid); // REQUIRED: register the validator if validating against the entire form this.formController.registerValidator(tempPhone);No comments
May 12
Using Components: ColorPicker AS3
Quick example on how to setup the ColorPicker component for AS3, drag the ColorPicker component on the stage give it an instance name of mcColorPicker, create a movieClip size of the stage give it an instance name of mcBackground.
//
package {
import flash.display.MovieClip;
import flash.events.*;
import fl.controls.ColorPicker;
import flash.geom.ColorTransform;
public class colorPicker extends MovieClip {
public var mcColorPicker:ColorPicker;
public var mcBackground:MovieClip;
public function colorPicker() {
mcColorPicker.addEventListener(Event.CHANGE, doColorPicker);
}
private function doColorPicker(e:Event) {
var myTransform:ColorTransform = new ColorTransform();
myTransform.color = e.target.selectedColor;
mcBackground.transform.colorTransform = myTransform;
}
}
}
//
No comments
May 9
Using Components: ComboBox and RadioButtons
Another simple example of how to set up components, in this case ComboBox and RadioButtons.
//
package {
import flash.text.*;
import flash.display.*;
import flash.events.*;
import fl.controls.RadioButton;
import fl.controls.ComboBox;
public class componentEx extends MovieClip {
//textField
public var txtField:TextField;
private var numRadioButton:Number = 2;
//comboBox
public var mcComboBx:ComboBox;
//radioButton
public var mcRadioButton0:RadioButton;
public var mcRadioButton1:RadioButton;
public function componentEx() {
this.initialize();
}
public function initialize():void {
this.setComboBox();
this.setRadioButton();
}
/*
comboBox
*/
private function setComboBox():void {
this.mcComboBx.prompt = "Select";
this.mcComboBx.addItem( { label: "Option 1", data:1 } );
this.mcComboBx.addItem( { label: "Option 2", data:2 } );
this.mcComboBx.addEventListener(Event.CHANGE, doComboBoxChange);
}
/*
radioButton
*/
private function setRadioButton():void {
var arrRBtnLabels:Array = new Array("Button1", "Button2");
for (var i:Number = 0; i < this.numRadioButton; i++) {
var tempRBtn = this["mcRadioButton" + i];
tempRBtn.label = arrRBtnLabels[i];
tempRBtn.addEventListener(MouseEvent.CLICK, doRadioBtnChange);
}
}
//
//
//
private function doComboBoxChange(e:Event):void {
this.txtField.text = this.mcComboBx.selectedLabel
}
//
private function doRadioBtnChange(e:MouseEvent):void {
this.txtField.text = e.currentTarget.label
}
}
}
//
No comments
May 6
TweenMax - TweenLite on Steroids
TweenMax builds on top of the TweenLite core class and its big brother, TweenFilterLite, to round out the tweening family with popular (though not essential) features like bezier tweening, pause/resume capabilities, easier sequencing, hex color tweening, and more. TweenMax uses the same easy-to-learn syntax as its siblings. In fact, since it extends them, TweenMax can do anything TweenLite and/or TweenFilterLite can do, plus more.
TweenMax
May 6
Playing External Sound in AS3 - Made Simple
Really easy way to add external sounds to flash.
//
playBtn.addEventListener(MouseEvent.CLICK, onPlayClick);
var myExternalSound:Sound = new Sound();
var req:URLRequest = new URLRequest("sound.mp3");
myExternalSound.load(req);
function onPlayClick(e:MouseEvent):void{
myExternalSound.play();
}
//
No comments
May 6
Simple AS3 Preloader
Simple preloader that plays the frame number based on the numPercentage value. Once everything has been loaded it removes the EventListener and the movieClip that displays the animation.
stop();
addEventListener(Event.ENTER_FRAME, onLoading);
function onLoading(event:Event) {
var numBytesTotal = stage.loaderInfo.bytesTotal;
var numBytesLoaded = stage.loaderInfo.bytesLoaded;
var numPercentage = Math.round(numBytesLoaded*100/numBytesTotal);
// MC for preloader animation
mcAnimation.gotoAndPlay(numPercentage);
//
trace(numPercentage)
if (numBytesLoaded >= numBytesTotal) {
gotoAndStop(2);
// remove EventListener and MC from stage
removeEventListener(Event.ENTER_FRAME, onLoading);
removeChild(mcAnimation);
}
}
No comments
May 6
Using the Slider Component
Really good simple example of how to use the slider component.
//import slider classes
import fl.controls.Slider;
import fl.events.SliderEvent;
//set text to 0
amount.text = "0";
//instantiate slider
var mcSlider:Slider = new Slider();
//position slider
mcSlider.move(50,100);
// if "true" slider updates instantly,
// if "false" updates after mouse is released
mcSlider.liveDragging = true;
//set size of slider
mcSlider.setSize(200,0);
//set maximum value
mcSlider.maximum = 200;
//set mininum value
mcSlider.minimum = 0;
//set tick position interval (optional)
mcSlider.tickInterval = 50;
// this is a EventListener that broadcasts an event changes
mcSlider.addEventListener(SliderEvent.CHANGE, doSliderChange);
//add slider to stage
addChild(mcSlider);
function doSliderChange(e:SliderEvent):void {
trace("Slider value is now: " + e.target.value);
amount.text = e.target.value;
}
No comments
Apr 29
Dispatch an Event from a Text Link
The link event is dispatched when a user clicks the hypertext link:
import flash.text.TextField;
import flash.events.TextEvent;
var tf:TextField = new TextField();
tf.htmlText = "<a href='event:myEvent'>Click Me.</a>";
tf.addEventListener(TextEvent.LINK, clickHandler);
addChild(tf);
function clickHandler(e:TextEvent):void {
trace(e.type); // link
trace(e.text); // myEvent
}
No comments
Apr 29
Guinness Tipping Point : Digital Campaign
We worked with AMV-BBDO to produce an interactive site for Guinness. They created a pretty cool campaign layout for Guinness Tipping Point, definitely worth checking out. For the ultimate experience you have to play the game.
Campaign Layout
Play the Game
Apr 18
Holy Smokes ToolBar
Ladies and Gents i bring to you “Holy Smokes ToolBar” for all your flash needs. Ive been messing with JSFL for the past couple of days and decided to make a simple toolbar, but i kept adding and adding to it and finally created “Holy Smokes ToolBar”.
This is a rundown of what HS does. The toolBar has 5 buttons:
1. Setup - renames the first layer in the toolbar to “Actions” and sets the Frame Rate to 30
2. Distribute Layers - distributes all the items to separate layers
3. Make Single MC - (ex. cornBread.jpg) Converts to Symbol, renames Layer, MovieClip, and sets instance name to “mcCornBread”
4. Make Multiple MC - Does the same as previous button except to multiple items
5. Organize Library - Creates folders in the Library “Audio”, “Buttons”, Graphics”, Miscellaneous”, and “Movie Clips” stores items in appropriate folders (if item exists in folder, makes a copy)
pretty cool little toolbar to make your life easier.
love to hear your feedback.