logo
468x60-2-495


  • Home
  • Privacy Policy
  • About
search
Jan 25, 2011 Posted on Jan 25, 2011 in Hints and Tips | 5 comments

Winners Announced: Win 1 of 2 Tickets to FITC Toronto 2011 – Worth $699!

Get this: ActiveDen and Activetuts+ are giving away 2 free tickets to FITC Toronto, worth $699 each! Even if you win, but can’t make it to the conference we’ll give you 1 year subscription to Tuts+ as well as $100 to spend on the Envato marketplaces instead!


About FITC

Rockingest. That’s how I’d describe FITC. Now in its 10th year, FITC Toronto is one of the largest and longest running events of its kind in the world. With some of the most unique and engaging presenters from around the globe, FITC Toronto is a blitz of presentations, demonstrations, and panel discussions, sandwiched between our legendary FITC parties and abundant networking opportunities. Topped off with the FITC Award Show, it’s three days and nights that will leave you inspired, energized, and awed.

FITC Toronto: Monday, May 02, 2011 – Wednesday, May 04, 2011

FITC Toronto 2010 Highlight Reel from FITC on Vimeo.


The Discount

ActiveDen and ActiveTuts users get a 10% discount on ANY FITC Toronto 2011 ticket, including the early and super early birds! Just use the discount code ActiveDen10 when purchasing.


The Competition

Want to go, but you prefer free things over things you have to pay for? You’re in luck – we’re giving away 2 free tickets to FITC Toronto, worth $699 each!

Can’t make it to Toronto for the conference, but still want to participate in the competition? That’s fine. One winner can opt out of the FITC ticket prize in exchange for a 1 year subscription to Tuts+ as well as $100 to spend on the Envato marketplaces.


How To Win

I’m afraid you’re too late! The winners have been selected, congratulations to antonelli and hellonicolas who’ll both be heading to Toronto for FITC 2011!

If you were unlucky this time, don’t worry. There’ll be plenty of chances to win stuff courtesy of ActiveDen and Activetuts+ in the near future. Keep following us on twitter and Facebook to keep up to date :)



View full post on Activetuts+

Jan 24, 2011 Posted on Jan 24, 2011 in Hints and Tips | 0 comments

Quick Tip: Auto Tab Between TextFields Using AS3

This Quick Tip will show you how to implement an Auto Tab between text fields. Doing so will set focus on the next defined text field when the maximum number of characters have been introduced in the previous one. Let’s get going!


Final Result Preview

Let’s take a look at the final result we will be working towards:


Step 1: Brief Overview

A series of TextFields will be placed on the stage, as well as a button. Using the length property we will check the maximum number of characters allowed in each field and change the active TextField using the focus property. The button will be hidden by default and revealed when all textfields are complete.


Step 2: Set up Your Flash File

Launch Flash and create a new Flash Document, set the stage size to 400x200px and the frame rate to 24fps.

Flash AS3 change textfield focus


Step 3: Interface

Flash AS3 change textfield focus

This is the interface we’ll be using, it includes three Input TextFields and a button. The TextFields are named txt1, txt2, and txt3 from left to right and the button is named okButton.

In order for the code to work, you need to set the Max Chars option in the Properties Panel of each TextField, in this example these numbers are 3, 3, and 4, respectively.

Recreate the interface yourself, or use the Source FLA.


Step 4: ActionScript

Create a new ActionScript Class (Cmd+N), save the file as Main.as and start writing:

package
{
	import flash.display.Sprite;
	import flash.events.KeyboardEvent;

	public class Main extends Sprite
	{
		public function Main():void
		{
			okButton.visible = false; //Hide the okButton
			stage.addEventListener(KeyboardEvent.KEY_UP, checkTextField); //Listen for key presses
		}

		private function autoTab(...textfields):void //Use the rest argument to include any number of textfields
		{
			var txtLen:int = textfields.length; //Declare the length of the textfields used

			for (var i:int = 0; i < txtLen; i++)
			{
				if (textfields[i].length == textfields[i].maxChars)
				{
					stage.focus = textfields[i + 1]; //Change focus to next textfield in the array
				}
				if (textfields[txtLen - 1].length == textfields[txtLen - 1].maxChars) //checks for the last textfield in the array
				{
					okButton.visible = true; //show the button
				}
			}
		}

		private function checkTextField(e:KeyboardEvent):void
		{
			autoTab(txt1, txt2, txt3); //executes the function every key press
		}
	}
}

This code checks the maximum number of characters allowed in each textfield, these fields are introduced in the autoTab function as parameters, then the focus changes if the max number is reached. If the last textfield in the parameters array is completed, the submit button is revealed.

The key line is stage.focus = textfields[i + 1];.

Again, don’t forget to set the Max Chars option in the Properties Panel of the TextField.


Step 5: Document Class

Remember to add the class name to the Class field in the Publish section of the Properties panel.

Flash AS3 change textfield focus

Conclusion

Try the demo and experiment with the uses of this feature!

I hope you liked this tutorial, thank you for reading!



View full post on Activetuts+

Jan 22, 2011 Posted on Jan 22, 2011 in Hints and Tips | 2 comments

Quick-Tip: Throwing Errors the Clean Way

There comes a time while developing, especially when developing for other developers, that you think “I should really anticipate this error”. This Quick Tip will show you how to do it — the clean way.


Step 1: Throwing

Often, you’ll try to anticipate a bug but end up just tracing something out. Whilst debugging you would find it really useful to throw an exception to make your code stop from executing further, or give some more information about why the error is happening. To do that you need to throw an error to the user, meaning Flash’s debug player will be able to catch it, as will the console when exporting directly from Flash Professional.

Let’s say I’m building a User class; it’s a static class with parameters like name and gender.

Now let’s say I want to catch if the user inputs something other than M or F in his/her gender:

package {

	public class User1 {
		private static var _name:String;
		private static var _gender : String;

		//SETTERS
		public static function set name(name:String):void{
			_name = name;
		}
		public static function set gender(gender:String):void{
			gender = gender.toUpperCase();
			if(gender != "F" && gender !="M"){
				throw new Error("Gender must be F or M");
			}else{
				_gender = gender;
			}
		}
		public static function get name():String{
			return _name;
		}
		public static function get gender():String{
			return _gender;
		}
	}
}

By submitting something like User1.gender = "multi", I would been thrown an error in my debugger specifying that my gender is invalid.


Step 2: Try and Catch the Error

Grabbing this concept and developing it further, I can also build custom error classes.

Let’s say I have a UConnection class that handles User Connection activity like login. This login function sends information to a php method that returns a user id (in this case I’ll call it uid) and you need to anticipate the uid being invalid (meaning the login could not be performed).

What you would need to create first is a custom error class, a UIDError class.

package{
	public class UIDError extends Error{
		public function UIDError():void{
			super("User ID returned invalid");
		}
	}
}

Secondly a class that anticipates and handles the exception:

package{

	public class User{
			private static var _uid:int;

		//SETTER
		public static function set uid(uid:int):void{
			if(uid == 0){
				throw new UIDError();
			}else{
				_uid = uid;
			}
		}

		//GETTER
		public static function get uid():int{
			return _uid;
		}
	}
}

Finally the implementation:

//bear in mind this is pseudo code,
//it will not work as I don't have a login.php
//and I'm not sending any variable through post,
//for a working version refer to the samples provided

public function login(un:String;pw:String):void{
	urlloader:URLLoader = new URLLoader();
	urlloader.addEventListener(Event.COMPLETE,onLogin)
	urlloader.load(new URLRequest("login.php"));
}

private function onLogin(e:Event){
	try{
		User.uid = e.target.data
	}catch(e:UIDError){
		trace("login invalid");
	}
}

The code inside the catch block runs if it notices any errors being thrown inside the try block. In this case, if a UIDError is thrown when attempting to set User.uid, then "login invalid" will be traced. If any other type of error gets thrown, then Flash Player will react in the way it normally does.


Conclusion

So there you have it, a clean, simple way of error handling your code, for you and your coworkers’ debugging pleasure.

I hope you liked this quick tip, thanks for reading!



View full post on Activetuts+

Jan 22, 2011 Posted on Jan 22, 2011 in Hints and Tips | 2 comments

Help Wanted: We Need an Awesome Staff Writer

We’re looking for a top-notch – and consistent – author to help out on Activetuts+ on a monthly basis. You’ll be expected to submit two articles each month and you’re free to choose your topics, as long as they’ll appeal to our audience. Interested? Read on..


Am I Right For the Job?

We’re after a few logical, but crucial, qualities in a regular writer:

  • Rock solid knowledge: Activetuts+ is a highly respected source of information and we expect the same high quality from you.
  • Ability to teach: Knowing what you’re doing is one thing; being able to explain to others what they should (and shouldn’t) be doing is a different animal.
  • Excellent writing skills: You must be comfortable with the English language. We can proof your content but we can’t rewrite everything for you. To put it simply, if you struggle when deciding whether to write your or you’re, this might not be the gig for you.
  • Consistency: Professionalism is key here. We expect you to keep the schedule we’ve agreed upon.

Unity

We cover a wide range of stuff here on Activetuts+, all related to Flash, ActionScript, Silverlight and soon we’ll be expanding into the world of Unity game development. Know a thing or two about Unity? You may just have jumped to the front of the queue..

activetuts unity

How Much Will I Earn?

Current rates for Activetuts+ regular content are as follows:

  • $50 per Quick Tip.
  • $200 per tutorial.
  • $350+ per Premium tutorial (negotiable depending on content).
  • Preferential treatment (and higher pay) will be given to those who can record professional quality screencasts.

You’ll take home at least $400 each month. We’ll expect delivery of (for example) 2 tutorials, or 1 Premium + 1 Quick Tip. That’s the minimum. If you have more to offer then you’re free to earn more :)


Apply Within..

We’ll need the following information from you:

  • Name.
  • A few sentences about yourself, your strengths and interests.
  • A link to your blog, if you have one.
  • A single link to an article that you’ve written or screencast that you’ve recorded.
  • Two ideas for tutorials you’d like to write for us.

Please email this information to active[at]tutsplus.com.

We get a ton of single line emails. Don’t be that person. Emails without the requisite information will be discarded.

We look forward to hearing from you!



View full post on Activetuts+

Jan 21, 2011 Posted on Jan 21, 2011 in Hints and Tips | 5 comments

Use the Flash Project Panel‏ to Build a Dynamic AS3 Menu

During this tutorial, we’ll use the Project Panel in Flash to create a vertical animated AS3 menu. The whole process will allow you to easily customize all aspects of the menu using the parameterized constructors. Read on to learn more!


Final Result Preview

Let’s take a look at the final result we will be working towards:


Step 1: Create a New Project

Start by creating a new project. Open Flash and go to File > New, then select Flash Project. The Project panel will appear.

simple Flash menu tutorial

In the Projects dropdown select New Project. Type the project name “AnimatedMenu”. In the Root Folder, browse and choose where you want to save your project; you can select an already existing folder or create a new one. Make sure the ActionScript version is set to ActionScript 3.0 and click Create Project.

simple Flash menu tutorial

Step 2: Add the Classes Folder

Now that the project is created, we are going to add a new folder to group in it our classes. Still in the same panel “Project” press the “New Folder” icon in the bottom, name the new folder “Classes” and click Create Folder.

simple Flash menu tutorial

Step 3: Install TweenLite

During this tutorial we will use the TweenLite classes from GreenSock for tweening, so we need to add it to our project. Download it and extract it, place it in your project folder (so you will have AnimatedMenu/com/greensock/).

Now if you refresh the Project panel you should see this structure:

simple Flash menu tutorial

Step 4: Create a New Flash File

Click the “New File” icon in the Project panel to create a new file, name it “AnimatedMenu.fla” (make sure that the File Type is Flash File) and click Create File.

simple Flash menu tutorial

Set the stage size to 600x350px.

simple Flash menu tutorial

Step 5: Create a New ActionScript File

Select the Classes folder and click the “New File” icon, set the File Type to ActionScript, name it “Main”. This will be our document class, if you are not familiar with document classes this Quick Tip on using a document class will help you.

simple Flash menu tutorial

Step 6: Set a Relative Source Path

This will allow us to use any class located in our Classes folder without the need to change the package name. Go to File > ActionScript Settings and click the plus button “Add New Path” and write the relative path ‘./Classes’.

simple Flash menu tutorial

Step 7: Start Coding the Main.as File

Inside the package Classes, import the Sprite Class and use it to extand the class “Main”. Here is the code :

package Classes
{
	import flash.display.Sprite;

	public class Main extends Sprite
	{

Step 8: Declare the Variables

These are the variables we will use (MenuItem is an ActionScript class that we will create later)

private var item1:MenuItem;
private var item2:MenuItem;
private var item3:MenuItem;
private var item4:MenuItem;

Step 9: The Constructor

Now we are going to code the constructor, it contains the code that will be executed when this class is called.

public function Main():void
{

Step 10: Create Four Menu Items

Instantiate the MenuItem class to create four menu items with different colors, labels, functionalities and positions:

//Create four instances of the MenuItem class and spacify the parameters (x,y,color,label,URL).
item1 = new MenuItem(100,60,0x28D9E9,"Home page","http://active.tutsplus.com/");
item2 = new MenuItem(140,150,0xA8FA2D,"Services","http://psd.tutsplus.com/");
item3 = new MenuItem(120,240,0xFC30FC,"About me","http://net.tutsplus.com/");
item4 = new MenuItem(160,330,0xEE2B2B,"Contacts","http://vector.tutsplus.com/");

You can change the URLs to point to other sites.


Step 11: Add the Items to the Stage

This code simply adds the four items created earlier to the stage.

//Add the items to the stage.
addChild(item1);
addChild(item2);
addChild(item3);
addChild(item4);

Now we are done with the Main class, here is the full code of this class.

package Classes
{
	import flash.display.Sprite;

	public class Main extends Sprite
	{
		private var item1:MenuItem;
		private var item2:MenuItem;
		private var item3:MenuItem;
		private var item4:MenuItem;

		public function Main():void
		{
			//Create four instances of the MenuItem class and spacify the parameters (x,y,color,label,URL).
			item1 = new MenuItem(100,60,0x28D9E9,"Home page","http://active.tutsplus.com/");
			item2 = new MenuItem(140,150,0xA8FA2D,"Services","http://psd.tutsplus.com/");
			item3 = new MenuItem(120,240,0xFC30FC,"About me","http://net.tutsplus.com/");
			item4 = new MenuItem(160,330,0xEE2B2B,"Contacts","http://vector.tutsplus.com/");

			//Add the items to the stage.
			addChild(item1);
			addChild(item2);
			addChild(item3);
			addChild(item4);
		}
	}
}

This class is too short to do all the functions that our menu is supposed to do, so we will create the “MenuItem.as” class that contains the necessary functions for our menu.


Step 12: Create the MenuItem.as

Add a new ActionScript 3 file in the Classes folder exactly like you did for the Main.as. Name it “MenuItem.as”.

simple Flash menu tutorial

Step 13: Import Classes

These are the classes that we need to import for our new class. Don’t forget you can always look them up in the LiveDocs.

package Classes
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import com.greensock.*;
	import com.greensock.TweenLite;
	import com.greensock.easing.*;
	import com.greensock.plugins.*;
	import flash.text.TextField;
	import flash.media.Sound;
	import flash.net.navigateToURL;
	import flash.net.URLRequest;

Step 14: Class and Variables

Declare the MenuItem class (should have the same name as its File name “MenuItem”) and extend the Sprite class.

public class MenuItem extends Sprite
{

These are the variables that we need at the moment, later we will add some others as we progress in this tutorial.

private var rect1:DynamicMovie = new DynamicMovie(); //Use the DynamicMovie class instead of Sprite class.
private var rect2:DynamicMovie = new DynamicMovie(); //This allow us to change the registration point.
private var rect3:DynamicMovie = new DynamicMovie(); //So we can rotate the rectangels around their centers.
private var X:Number;
private var Y:Number;
private var Color:uint;

DynamicMovie is an AS3 class based on an old AS2 class written by Darron Schall; this AS3 class extends MovieClip and adds a new set of properties (x2, y2, rotation2, scaleX2, scaleY2, mouseX2, mouseY2) that allow you to manipulate the sprite based on a contextual registration point that can be set using the setRegistration() method.

We need this class to rotate the rectangles around their centers. So let’s place it.


Step 15: Add the DynamicMovie Class

You find this class in the source folder of this tutorial or you can download it from oscartrelles.com, then just place it in the Classes Folder so that it can be recognized by our code.

simple Flash menu tutorial

Step 16: The Constructor

This is the constructor of the MenuItem.

public function MenuItem(posX:Number, posY:Number,color:uint,Title:String,URL:String)
{
	//Get the position and color parameters.
	X = posX;
	Y = posY;
	Color = color;

	// Call the addRect function to add 3 rectangles with the specified parameters.
	addRect(rect1,X-12,Y,360,62,Color,0.3,3);
	addRect(rect2,X-4,Y,360,62,Color,0.4,0);
	addRect(rect3,X,Y,360,62,Color,0.7,-2);
}

Step 17: addRect() Function

This function is responsible for drawing the rectangles according to the given parameters: position, width, height, color, alpha and rotation.

private function addRect(rect:DynamicMovie,X:Number, Y:Number, width:Number, height:Number,color:uint, alpha:Number, rotation:Number)
{
	rect.setRegistration(X+(width/2),Y+(height/2));
	rect.graphics.beginFill(color,alpha);
	rect.graphics.drawRect(X,Y,width,height);
	addChild(rect);
	rect.rotation2 = rotation;
}

Now you can test it and you will see this:

Sure, we can’t call it a menu if we don’t add some labels. We’ll deal with that in the next step.


Step 18: Add a Dynamic TextField

Head back to your AnimatedMenu.fla file and add a new symbol (Ctrl + F8); name it “Text_mc” and select “Export for ActionScript”.

simple Flash menu tutorial

Now inside this symbol add a 160x30px Dynamic TextField using the Text Tool (T). This is the font I used: Creampuff Regular, 24px, #FFFFFF. Name the instance “txtLabel”.

Select the TextField and go to Window > Align (Ctrl + K) and hit the buttons “Align left edge” and “Align top edge” (make sure that the checkbox “Align to stage” is selected)

simple Flash menu tutorial

Step 19: Embed the Font

After creating the text field with the specified font we should embed it to display the text properly.

So go to Text > Font Embedding, give it a name (for example “Font1″), select the Creampuff font from the Family combo box, in the Character ranges select all of the Uppercase and the Lowercase, then press the “plus” button located in the left section. See the image below:

simple Flash menu tutorial

Step 20: Add Labels

To add labels to the menu items we are going to instantiate the Text_mc MovieClip. Add this line of code to the variables in the MenuItem.as file.

private var txt:Text_mc = new Text_mc();

Now we should assign to the TextField the title given in the constructor’s parameters.

Add this code to the end of the constructor.

//Assign a title to the TextField and place it.
txt.txtLabel.text = Title;
txt.x = X + 70;
txt.y = Y + 16;
addChild(txt);

This is what you should get:

In the next steps we will add some functions to animate the menu.


Step 21: Menu Button

To turn our menu item into a button we should add a transparent rectangle over it and set the buttonMode to true. So add this variable to the variable list.

private var menuButton:DynamicMovie = new DynamicMovie();

In the end of the constructor add this code:

//Use the addRect function to draw a transparent rectangle over the menu item.
addRect(menuButton,X-10,Y-5,380,80,Color,0,0);
buttonMode = true;

Step 22: Add Event Listeners

Add the following event listeners to the menuButton at the end of the constructor.

menuButton.addEventListener(MouseEvent.MOUSE_OVER,mouseOver);
menuButton.addEventListener(MouseEvent.MOUSE_OUT,mouseOut);
menuButton.addEventListener(MouseEvent.CLICK,mouseClick);

Step 23: Mouse Over

This function will be called when the mouse is over the menuButton.

private function mouseOver(e:MouseEvent)
{
	var timeline:TimelineLite = new TimelineLite();

	//Rotate the rectangels.
	new TweenLite(rect1,.3,{rotation2:-4});
	new TweenLite(rect2,.3,{rotation2:0});
	new TweenLite(rect3,.3,{rotation2:5});

	//Tween the text.
	timeline.append(new TweenLite(txt,.3,{x:X+45,scaleX:1.1,scaleY:1.1}));
	timeline.append(new TweenLite(txt,.3,{x:X+70,alpha:1}));

	//Add a Glow Filter to the text.;
	new TweenMax(txt,.3,{glowFilter:{color:0xffffff,alpha:1,blurX:5,blurY:5,strength:1,quality:3}});
}

Here we are using the GreenSock classes TimelineLite and TweenMax to animate the button. Search the Activetuts+ site for more tutorials featuring GreenSock.


Step 24: Mouse Out

When the mouse is out this function will return the menu to its initial position.

private function mouseOut(e:MouseEvent)
{
	var timeline:TimelineLite = new TimelineLite();

	//Rotate the rectangles to their initial position.
	new TweenLite(rect1,.3,{rotation2:3});
	new TweenLite(rect2,.3,{rotation2:0});
	new TweenLite(rect3,.3,{rotation2:-2});

	//backward the text animation.
	timeline.append(new TweenLite(txt,.3,{x:X+65,alpha:.9}));
	timeline.append(new TweenLite(txt,.3,{x:X+70}));
	new TweenMax(txt,.3,{glowFilter:{color:0xffffff,alpha:0,blurX:0,blurY:0,strength:0,quality:3}});
}

Step 25: Mouse Click

This function will open the specified URL when the menu item is clicked.

private function mouseClick(e:MouseEvent)
{
	//Open the requested URL.
	navigateToURL(new URLRequest(myURL));
}

You should add this variable to the variables list.

private var myURL:String;

And add this instruction to the constructor.

myURL = URL;

This is what you should get. Roll over the menu to see the animation.

Now let’s add a cool bubbles effect.


Step 26: The Bubbles Effect

This function will create a number of bubbles with a random position, size and alpha in two directions. This is the code:

private function bubbles(position:Number,direction:Number)
{
	//Create 50 bubbles, you can modify the number to get more or less bubbles.
	for (var i=0; i<50; i++)
	{
		var bubble:DynamicMovie= new DynamicMovie();

		//Set the registration point for the current bubble.
		bubble.setRegistration(X+position,Y);

		//Give the bubble the same color as the menu item and a random alpha (but greater than 0.2).
		bubble.graphics.beginFill(Color,Math.random()+0.2);

		//draw a circle with a random position and radius.
		bubble.graphics.drawCircle(X + position + Math.random() * i,Y + 55  - Math.random() * i,Math.random()*5);

		//add the bubble at the third index so that it is under the menuButton.
		addChildAt(bubble,3);

		//Tween the Bubble randomly according to the direction.
		new TweenLite(bubble,Math.random() + 1,{x2:X - 80 * direction + position - Math.random() * i,y2:Y - Math.random() * i,alpha:0,ease:Circ.easeOut});
	}
}

Step 27: Call the Bubbles Function

We need to call the bubbles() function when the mouse rolls over the menu item. So add this code to the mouseOver() function:

//Left bubbles.
bubbles(70,1);

//Right bubbles
bubbles(270,-1);

This is what we get:


Step 28: Import the Sound Effect

We are going to finish by adding a sound effect to the menu when it is rolled over by the mouse. To do so, download the sound from here (download the mp3 file). Then import it to the library, File > Import > Import to Library. Rename it to “MySound.mp3″.

simple Flash menu tutorial

Open its properties and click Advanced; the window will display extra content, select “Export for ActionScript” and name the Class “MySound”.

simple Flash menu tutorial

Step 29: Add the Sound Effect to the Menu

To add the sound effect instantiate the sound imported earlier to the library and play it. Place this code in the mouseOver() function.

var mySound:MySound = new MySound();
mySound.play();

We are done with our menu! Here is the full code of the MenuItem.as :

package
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import com.greensock.*;
	import com.greensock.TweenLite;
	import com.greensock.easing.*;
	import com.greensock.plugins.*;
	import flash.text.TextField;
	import flash.media.Sound;
	import flash.net.navigateToURL;
	import flash.net.URLRequest;

	public class MenuItem extends Sprite
	{
		private var rect1:DynamicMovie = new DynamicMovie();//Use the DynamicMovie class instead of Sprite class.
		private var rect2:DynamicMovie = new DynamicMovie();//This allow us to change the registration point.
		private var rect3:DynamicMovie = new DynamicMovie();//So we can rotate the rectangels around their centers.
		private var menuButton:DynamicMovie = new DynamicMovie();
		private var X:Number;
		private var Y:Number;
		private var Color:uint;
		private var txt:Text_mc = new Text_mc();
		private var myURL:String;

		public function MenuItem(posX:Number, posY:Number,color:uint,Title:String,URL:String)
		{
			//Get the position and color parameters.
			X = posX;
			Y = posY;
			Color = color;
			myURL = URL;

			// Call the addRect function to add 3 rectangles with the specified parameters.
			addRect(rect1,X-12,Y,360,62,Color,0.3,3);
			addRect(rect2,X-4,Y,360,62,Color,0.4,0);
			addRect(rect3,X,Y,360,62,Color,0.7,-2);

			//Assign a title to the TextField and place it.
			txt.txtLabel.text = Title;
			txt.x = X + 70;
			txt.y = Y + 16;
			addChild(txt);

			//Use the addRect function to draw a transparent rectangle over the menu item.
			addRect(menuButton,X-10,Y-5,380,80,Color,0,0);
			buttonMode = true;

			menuButton.addEventListener(MouseEvent.MOUSE_OVER,mouseOver);
			menuButton.addEventListener(MouseEvent.MOUSE_OUT,mouseOut);
			menuButton.addEventListener(MouseEvent.CLICK,mouseClick);
		}

		private function addRect(rect:DynamicMovie,X:Number, Y:Number, width:Number, height:Number,color:uint, alpha:Number, rotation:Number)
		{
			rect.setRegistration(X+(width/2),Y+(height/2));
			rect.graphics.beginFill(color,alpha);
			rect.graphics.drawRect(X,Y,width,height);
			addChild(rect);
			rect.rotation2 = rotation;
		}

		private function mouseOver(e:MouseEvent)
		{
			var timeline:TimelineLite = new TimelineLite();
			var mySound:MySound = new MySound();
			mySound.play();

			//Rotate the rectangels.
			new TweenLite(rect1,.3,{rotation2:-4});
			new TweenLite(rect2,.3,{rotation2:0});
			new TweenLite(rect3,.3,{rotation2:5});

			//Tween the text.
			timeline.append(new TweenLite(txt,.3,{x:X+45,scaleX:1.1,scaleY:1.1}));
			timeline.append(new TweenLite(txt,.3,{x:X+70,alpha:1}));

			//Add a Glow Filter to the text.;
			new TweenMax(txt,.3,{glowFilter:{color:0xffffff,alpha:1,blurX:5,blurY:5,strength:1,quality:3}});

			//Left bubbles.
			bubbles(70,1);

			//Right bubbles
			bubbles(270,-1);
		}

		private function mouseOut(e:MouseEvent)
		{
			var timeline:TimelineLite = new TimelineLite();

			//Rotate the rectangles to their initial position.
			new TweenLite(rect1,.3,{rotation2:3});
			new TweenLite(rect2,.3,{rotation2:0});
			new TweenLite(rect3,.3,{rotation2:-2});

			//backward the text animation.
			timeline.append(new TweenLite(txt,.3,{x:X+65,alpha:.9}));
			timeline.append(new TweenLite(txt,.3,{x:X+70}));
			new TweenMax(txt,.3,{glowFilter:{color:0xffffff,alpha:0,blurX:0,blurY:0,strength:0,quality:3}});
		}

		private function mouseClick(e:MouseEvent)
		{
			//Open the requested URL.
			navigateToURL(new URLRequest(myURL));
		}

		private function bubbles(position:Number,direction:Number)
		{
			//Create 50 bubble, you can modify the number to get more or less bubbles.
			for (var i=0; i<50; i++)
			{
				var bubble:DynamicMovie= new DynamicMovie();

				//Set the registration point for the bubble.
				bubble.setRegistration(X+position,Y);

				//Give the bubble the same color as the menu item and a random alpha but upper than 0.2.
				bubble.graphics.beginFill(Color,Math.random()+0.2);

				//draw a circle with a random Position and Radius. ;
				bubble.graphics.drawCircle(X + position + Math.random() * i,Y + 55  - Math.random() * i,Math.random()*5);

				//add the bubble at the third index to be under the menuButton.;
				addChildAt(bubble,3);

				//Tween the Bubble randomly according to the direction.
				new TweenLite(bubble,Math.random() + 1,{x2:X - 80 * direction + position - Math.random() * i,y2:Y - Math.random() * i,alpha:0,ease:Circ.easeOut});
			}
		}

	}
}

And here is the final result:


Conclusion

Now you can create your own menu and customize it by adding more menu items, changing the colors, changing the text…

The menu was coded in a separate ActionScript class which allows you to use it easily in other projects.

I want to thank you for reading; I hope you enjoyed it!



View full post on Activetuts+

Page 1 of 712345...»Last »
search search search search search
Find an Article
Categories
  • Flash Video Training
  • Hints and Tips
  • Recommended
Please Support Our Sponsors
Recent Posts
  • Tuts+ Community Meetup in New York!
  • HTML5 Canvas Optimization: A Practical Example
  • Recreate the Cover Flow Effect Using Flash and AS3
  • Drawing Activetuts+ to a Close
  • Intro to Dart: Creating a Marquee
Tag Cloud
2011 ActionScript Active Activetuts+ Adobe animation Basic Basix Best Build Button Character Code Create Creating Critique Custom design Effect Effects Files Flash from Game Guide HTML5 Introduction Macromedia Motion Muzzle part Player Premium Professional Quick Silverlight Simple Text Tool Tutorial Tuts+ Using Video website Workshop
About Our Site:

Hey there and welcome to "Flash Video Training Source", a resource for anybody interested in learning more about Adobe's great tool. We feature educational videos, which will help you master Adobe Flash and help you get to know all of its features. We at "Flash Video Training Source" believe that video training and video... more

Why don't you follow us on Twitter and get the latest video tutorials twitted to your account. Just click on the floating twitter bar to your right!

Go Back In Time
January 2011
M T W T F S S
« Dec   Feb »
 12
3456789
10111213141516
17181920212223
24252627282930
31  
Pretty Blank Box
top

Blogroll

  • Development Blog
  • Documentation
  • Plugins
  • Suggest Ideas
  • Support Forum
  • Themes
  • WordPress Planet

Meta

  • Log in
  • Entries RSS
  • Comments RSS
  • WordPress.org

Archives

  • July 2012
  • June 2012
  • May 2012
  • April 2012
  • March 2012
  • February 2012
  • January 2012
  • December 2011
  • November 2011
  • October 2011
  • September 2011
  • August 2011
  • July 2011
  • June 2011
  • May 2011
  • April 2011
  • March 2011
  • February 2011
  • January 2011
  • December 2010
  • November 2010
  • October 2010
  • September 2010
  • August 2010
  • July 2010
  • June 2010
  • May 2010
  • April 2010
Powered by WordPress  |  Designed by Elegant Themes  |  Lightning Fast Hosting by Site 5 Hosting