/****************************
Import Classes
****************************/
import flash.display.*;
import flash.geom.*;
/****************************
Define Variables
****************************/
//Type of Gradient we will be using
var fType:String = GradientType.LINEAR;
//Colors of our gradient in the form of an array
var colors:Array = [ 0xF1F1F1, 0x666666 ];
//Store the Alpha Values in the form of an array
var alphas:Array = [ 1, 1 ];
//Array of color distribution ratios.
//The value defines percentage of the width where the color is sampled at 100%
var ratios:Array = [ 0, 255 ];
//Create a Matrix instance and assign the Gradient Box
var matr:Matrix = new Matrix();
matr.createGradientBox( 200, 20, 0, 0, 0 );
//SpreadMethod will define how the gradient is spread. Note!!! Flash uses CONSTANTS to represent String literals
var sprMethod:String = SpreadMethod.PAD;
//Start the Gradietn and pass our variables to it
var sprite:Sprite = new Sprite();
//Save typing + increase performance through local reference to a Graphics object
var g:Graphics = sprite.graphics;
g.beginGradientFill( fType, colors, alphas, ratios, matr, sprMethod );
g.drawRect( 0, 0, 400, 200 );
addChild( sprite );
function get currentURL():String
{
var url:String;
if (ExternalInterface.available) {
return ExternalInterface.call("window.location.href");
}
return url;
}
function slugify(string:String):String
{
const pattern1:RegExp = /[^\w- ]/g; // Matches anything except word characters, space and -
const pattern2:RegExp = / +/g; // Matches one or more space characters
var s:String = string;
return s.replace(pattern1, "").replace(pattern2, "-").toLowerCase();
}
// Imports
import flash.filesystem.FileMode;
import flash.filesystem.FileStream;
import flash.filesystem.File;
import flash.events.ProgressEvent;
import flash.events.Event;
// Declare the FileStream and String variables
private var _fileStream:FileStream;
private var _fileContents:String;
private function onCreationComplete():void // Fired when the application has been created
{
var myFile:File = File.appResourceDirectory; // Create out file object and tell our File Object where to look for the file
myFile = myFile.resolve("mySampleFile.txt"); // Point it to an actual file
_fileStream = new FileStream(); // Create our file stream
_fileStream.addEventListener(ProgressEvent.PROGRESS, onFileProgress); // Add our the progress event listener
_fileStream.addEventListener(Event.COMPLETE, onFileComplete); // Add our the complete event listener
_fileStream.openAsync(myFile, FileMode.READ); // Call the openAsync() method instead of open()
}
private function onFileProgress(p_evt:ProgressEvent):void // Event handler for the PROGRESS Event
{
_fileContents += _fileStream.readMultiByte(_fileStream.bytesAvailable, "iso-8859-1"); // Read the contens of the file and add to the contents variable
fileContents_txt.text = _fileContents; // Display the contents. I've created a TextArea on the stage for display
}
private function onFileComplete(p_evt:Event):void // Event handler for the COMPLETE event
{
_fileStream.close(); // Clean up and close the file stream
}
public function SlideShow( ){
//If you are working locally on your computer, you will load manually load the xml file. Otherwise you will be receiving the xml file from SWFObject2
xmlURL = ( getDevelopmentMode() === "Production" ) ? getFlashVars().xml : "./xml/data.xml";
//Capture where the SWF is living on the live site
var currentLocationOfSWF:String = getContextPath();
}
private function getFlashVars():Object
{
return Object( LoaderInfo( this.loaderInfo ).parameters );
}
private function getDevelopmentMode():String
{
var dev:Boolean = new RegExp("file://").test( this.loaderInfo.loaderURL);
if( dev ) return "Development";
else return "Production";
}
private function getContextPath():String
{
var uri:String = getLoaderURL();
return uri.substring(0, uri.lastIndexOf("/")) + "/";
}
private function getLoaderURL():String
{
return this.loaderInfo.loaderURL;
}
//Using Replace
var toungeTwister:String = "Peter Piper Picked a peck of pickled peppers";
//g is a global identifier so it doesn't stop only on the first match
var pickRegExp:RegExp = /pick|peck/g;
var replaced:String = toungeTwister.replace( pickRegExp, "Match");
//trace(replaced);
//Using Character Classes
var compassPoints:String = "Naughty Naotersn elephants squirt water";
var firstWordRegExp:RegExp = /N(a|o)/g;
//trace( compassPoints.replace( firstWordRegExp, "MATCH" ) );
var favoriteFruit = "bananas";
var bananaRegExp:RegExp = /b(an)+a/;
//trace( bananaRegExp.test( favoriteFruit ) );
//Exec() method returns an Object containing the groups that were matched
var htmlText:String = "<strong>This text is important</strong> while this text is not as important <strong>ya</strong>";
var strongRegExp:RegExp = /<strong>(.*?)<\/strong>/g;
var matches:Object = strongRegExp.exec( htmlText);
for( var i:String in matches ) {
//trace( i + ": " + matches[i] );
}
var email:String = "c@chrisaiv.comm";
var emailRegExp:RegExp = /^([a-zA-Z0-9_-]+)@([a-zA-Z0-9.-]+)\.([a-zA-Z]{2,4})$/i;
var catches:Object = emailRegExp.exec( email );
for( var j:String in catches ) {
//trace( j + ": " + catches[j] );
}
//trace( "This e-mail's validity is: " + emailRegExp.test( email ) );
//Test the validity of an e-mail
var validEmailRegExp:RegExp = /([a-z0-9._-]+)@([a-z0-9.-]+)\.([a-z]{2,4})/;
trace( validEmailRegExp.test( "a1a@c.info" ) );
//Return a Boolean if there is a pattern match
var phoneNumberPattern:RegExp = /\d\d\d-\d\d\d-\d\d\d\d/;
trace( phoneNumberPattern.test( "347-555-5555" )); //true
trace( phoneNumberPattern.test("Call 800-123-4567 now!")); //true
trace( phoneNumberPattern.test("Call now!")); //false
//Return the index number of the occurence is there is a pattern match
var themTharHills:String = "hillshillshillsGOLDhills";
trace(themTharHills.search(/gold/i)); //15