logo
468x60-2-495


  • Home
  • Privacy Policy
  • About
search
Mar 2, 2011 Posted on Mar 2, 2011 in Hints and Tips | 0 comments

Quick Introduction: Flash ScrollPane and ColorPicker Components

This entry is part 8 of 8 in the series Flash Components

In this Quick Introduction to Flash Professional components we are going to look at the ScrollPane and ColorPicker. Let’s dive in..


Brief Overview

Check out the demo. In it, on the left hand side, you see two Color Picker components, two Labels labeled “Custom Color Picker” and “Normal Color Picker” and a blue rectangle.

The Custom Color Picker uses colors taken exclusively from a selection of our choosing. The Normal Color Picker has all the colors of a regular color picker and when a user chooses a color we change the rectangle to the color they’ve chosen.

On the right hand side of the SWF there is a ScrollPane, into which we load an image, and a button that we use to initiate the loading of the image.


Step 1: Setting Up the Document

Open a new Flash Document and set the following properties:

  • Document Size: 550x400px
  • Background Color: #FFFFFF

Step 2: Add Components to the Stage

Open the components window by going to Menu > Window > Components or press CTRL+F7

Drag two ColorPickers, two Labels, a ScrollPane and a button to the stage.

In the Properties panel give the first Label the instance name customLabel.

If the Properties panel is not showing go to Menu > Window > Properties or press CTRL+F3.

Set the Label’s X to 16 and its Y to 12.

Give the second Label the instance name “normalLabel”; set its X to 16 and its Y to 176.

Give the first ColorPicker the instance name “customColorPicker”; set its X to 16 and its Y to 41.

Give the second ColorPicker the instance name “normalColorPicker”; set its X to 16 and its Y to 206.

Give the second ScrollPane the instance name “imageScrollPane”; set its X to 277 and its Y to 29.

Give the Button the instance name “loadImageButton”; set its X to 354 and its Y to 332.

Using the rectangle tool draw a rectangle on the stage. I drew mine with a blue color. Select the rectangle and go to Menu > Modify > Convert to Symbol (or press F8); set its name to “square” and make sure “Type” is set to MovieClip.

Next, give it an instance name of square as we did with the components above. Set its size to 143x97px, set its X to 90, and its Y to 47.


Explaining the Components

The ColorPicker is a great little component which allows users to select a color. You can also define which colors you want available in the ColorPicker.

The ScrollPane component displays DisplayObjects, JPEG, GIF, and PNG files, as well as SWF files, in a scrollable area. When the content you are loading is too large for the movie this is an ideal component to use.


Step 3: Preparing the AS File

Create a new ActionScript file and give it the name Main.as. We will be declaring our components in Main.as so we need to turn off “auto declare stage instances”; the benefit of doing this is that you get code hinting for the instance.

Go to Menu > File > Publish Settings and click on Settings next to Script [Actionscript 3.0]

Uncheck “Automatically declare stage instances”.

Next, in Main.as, we’ll open the package declaration and import the classes we will be using.

Add the following to Main.as:

package  {
    //We extend MovieClip
    import flash.display.MovieClip;
    //Need to import the components we are using
    import fl.controls.ColorPicker;
    import fl.controls.Label;
    import fl.containers.ScrollPane;
    import fl.controls.Button;
    //The events we need
    import flash.events.MouseEvent;
    import flash.events.Event;
    //Needed to change color of movieClip
    import flash.geom.ColorTransform;
    //Needed to load image
    import flash.net.URLRequest;

Step 4: Set up the Main Class

Add the Class declaration, make it extend Movie Clip, and set up our constructor function. Here we declare our variables and call our functions in the Main Constructor.

Add the following to Main.as

public class Main extends MovieClip {

    //Our onstage Components
    public var customLabel:Label;
    public var normalLabel:Label;
    public var customColorPicker:ColorPicker;
    public var normalColorPicker:ColorPicker;
    public var square:DisplayObject;
    public var imageScrollPane:ScrollPane;
    public var loadImageButton:Button;
    public function Main() {
		setupLabels();
		setupColorPickers();
		setupButton();
    }

Step 5: Main Constructor Functions

Here we define the functions that are used in our constructor.

In the setupLabels function we set the text on the Labels. In setupColorPickers we set the colors for our customColorpicker; these colors are an array of colors using Flash’s syntax for hexadecimal colors. We also add an event listener to our color pickers so that when a user chooses a color we fire off the relevant function.

In the setupButton function we set the Button’s Label property and add an Event Listener for when the user clicks on the Button.

Add the following to Main.as:

private function setupLabels():void{
    //Sets the Labels' text
    customLabel.text ="Custom Color Picker";
    normalLabel.text ="Normal Color Picker"
    }
private  function setupColorPickers():void{
    //Here we set the colors for the color picker
    customColorPicker.colors =[0x000FF,0xFF0000,0x00FF00,
                               0xFFFF00,0xFF33FF];
    //When the user picks a color we call the changeColor function
    customColorPicker.addEventListener(Event.CHANGE,changeColor);
    normalColorPicker.addEventListener(Event.CHANGE,changeColor);
}

private function setupButton():void{
    //Sets the Buttons Label(The Text on the Button)
    loadImageButton.label ="Load Image";
    //When user clicks on button we call loadImage function
    loadImageButton.addEventListener(MouseEvent.CLICK,loadImage);
}

Step 6: Code our Event Listeners

Here we code the functions for the event listeners we added above.

The changeColor function uses a ColorTransform object so that we can change the color of the rectangle on the stage. We set the ColorTransform’s color to the color the user selected by using e.target.selectedColor. The target is the ColorPicker whose color was just changed. Then, we use the transform property of the square movieClip and set the colorTransform to the color selected.

		private function changeColor(e:Event):void {
			//Need to set up a ColorTransform Object to change the MovieClip's Color
			var color:ColorTransform = new ColorTransform();
			//set the colorTransform color to the color user picked in colorPicker
			color.color = e.target.selectedColor;
			//Change the movieClip's color using the ColorTransform
			square.transform.colorTransform = color;
		}

		private function loadImage(e:Event):void {
			//Loads the image into the scrollPane
			imageScrollPane.load(new URLRequest("image.jpg"));
		}
	}//close out the class

}//close out the package

Conclusion

You’ll notice in the Component Parameters panel (which can be opened from the Window menu) that you can check and select certain properties.

colorpicker

The above image is for the ColorPicker component.

The properties are as follows for the ColorPicker component:

  • enabled: a Boolean value that indicates the whether the component can accept user input.
  • selectedColor: A hexadecimal value that sets the selected color of the ColorPicker.
  • showTextField: a Boolean value that indicates whether the internal text field of the ColorPicker component is displayed.
  • visible: a Boolean value that indicates whether or not the component is visible on the stage.

The properties for the ScrollPane are

  • enabled: a Boolean value that indicates the whether the component can accept user input.
  • horizontalLineScrollSize: a value that describes the amount of content to be scrolled, horizontally, when a scroll arrow is clicked.
  • horizontalPageScrollSize: he count of pixels by which to move the scroll thumb on the horizontal scroll bar when the scroll bar track is pressed.
  • horizontalScrollPolicy: a value that indicates the state of the horizontal scroll bar. Can be: ScrollPolicy.ON, ScrollPolicy.OFF, ScrollPolicy.AUTO.
  • scrollDrag: a Boolean value that indicates whether scrolling occurs when a user drags on content within the scroll pane.
  • verticalLineScrollSize: a value that describes how many pixels to scroll vertically when a scroll arrow is clicked.
  • verticalPageScrollSize: the count of pixels by which to move the scroll thumb on the vertical scroll bar when the scroll bar track is pressed.
  • verticalScrollPolicy: a value that indicates the state of the vertical scroll bar. Can be: ScrollPolicy.ON, ScrollPolicy.OFF, ScrollPolicy.AUTO.
  • visible: a Boolean value that indicates whether or not the component is visible on the stage.

The help files are a great place to learn more about these properties.

To learn more about the properties for Labels and Button be sure to check out the Quick Tip on the Button and Label components



View full post on Activetuts+

Mar 2, 2011 Posted on Mar 2, 2011 in Hints and Tips | 0 comments

Quick Roundup: Best of Tuts+ in February 2011

Didn’t catch your usual Tuts+ reading during February? Here’s a catch-up on the best we have to offer!

Cgtuts+ CG and 3D Tutorials

  • ‘The Soviet Machine’ – Day 1

    The Soviet Machine’ – Day 1

    February saw the release of “The Soviet Machine”, a brand new multi-part tutorial series from new Cgtuts+ author Martin Kostov. The ‘Soviet Machine’ is a high poly modeling tutorial for 3d Studio Max. Throughout this amazing series, Martin will show you how to create accurate, highly detailed objects using only a few reference images. This is a great and easy to follow tutorial for both beginner and intermediate 3ds Max users alike. We know you’re going to love it!

    Visit Article

  • Tattered Cloth In Cinema4D – Day 1

    Tattered Cloth In Cinema4D – Day 1

    February also saw the release of an in-depth two part tutorial by new Cgtuts+ author Tony Rivera. Throughout the tutorial Tony shares some of his techniques for creating tattered cloth in Maxon’s Cinema4D. You will learn how to create this effect by making a flag simulation using the power of C4D’s Spline and Boole tools. This is a great starting point for any artist interesting in exploring the possibilities of cloth simulation inside Cinema4D!

    Visit Article

  • 118 Tree Bark Textures – CG Premium Content Pack

    Tree Bark Textures – CG Premium Content Pack

    In February Cgtuts+ was pleased to release two amazing texture packs from regular author and contributor Chandan Kumar. Chandan put together a huge collection of 118 awesome, high resolution tree bark textures for our Premium subscribers. These unique textures are presented at full size and in high resolution, sure to meet all of your texturing needs!

    Visit Article

Aetuts+ After Effects News and Tutorials

  • Dave Scotland’s 5 Handy Workflow Tips

    Dave Scotland’s 5 Handy Workflow Tips

    Today I really wanted to share some workflow tricks that I use on a daily basis in a production environment. Many of you might be familiar with these techniques, but there will be a lot of people that will definitely benefit from these tips. With the exception of the Reel Smart Motion Blur plug-in, all of these processes are built into After Effects. Whether youre a newcomer to After Effects or a seasoned veteran, you will definitely get something out of these great timesavers…

    Visit Article

  • Burst Through the Earths Surface In Style

    Burst Through the Earths Surface In Style

    This tutorial has three main parts. It covers the panorama background plate for the scene. It does NOT cover the rotoscoping of the actor (grrrr). Then, the jump is animated with Action Essentials II dirt footage composited in. Finally, the “camera move” effect is demonstrated from an intriguing zoom to epic wide angle!! Get your Jump on!

    Visit Article

  • What The Heck Is A Hex Value Anyway?

    What The Heck Is A Hex Value Anyway?

    In today’s Quick Tip, I briefly explain the history of and logic behind a color’s hex value. Enjoy!

    Visit Article

Psdtuts+ Adobe Photoshop Tutorials

  • The Cosmos: Create a Red Giant Star in Photoshop

    The Cosmos: Create a Red Giant Star in Photoshop

    When a star like our own reaches the end of its life, it begins to run out of hydrogen fuel in its core. Like a car running out of gas, it will begin to sputter, swelling to a size that could encompass every planet in our solar system out to Mars. When this happens, the sun will swallow the Earth and will spell certain doom for all life on our planet. Today’s tutorial is part of a 4-part series depicting the journey of the inhabitance of a dying world that must travel into the unknown to find a new world to call home. In this series, we will explore the cosmos from the perspective of this fictional civilization making their way through the universe and will demonstrate the techniques that you can use in Photoshop to depict your own cosmic scenery. In addition to written content, this tutorial also includes about an hour of video instruction to help you along the way. So what are you waiting for? Let’s get started!

    Visit Article

  • Create a Fictional Arctic Snow Frog in Photoshop

    Create a Fictional Arctic Snow Frog in Photoshop

    Photoshop is a great tool to create scenarios that can’t or don’t exist in real life. In today’s tutorial, we will combine several stock images and effects to create a fictional arctic snow frog in Photoshop. As you can see, some of his unfortunate friends are frozen into the ice behind him and his meal is frozen just out of reach. Let’s get started!

    Visit Article

  • Does Photoshop Really Cost Too Much?

    Does Photoshop Really Cost Too Much?

    Let’s be honest, Photoshop isn’t cheap. Most of us have probably complained about the cost of Photoshop, and Adobe products in general at some point in our careers. The fact is that none of us could do our job without it. It’s an advanced application meant for professional users. It is used by people in all walks of life, from photographers to web designers; but is it worth the $699 price tag? In this article, we will take a balanced look at whether or not Photoshop costs too much, not enough, or if it is priced just right.

    Visit Article

Webdesigntuts+ Web Design Tutorials

  • 5 Pitfalls to Avoid for New Web Designers

    Pitfalls to Avoid for New Web Designers

    New web designers often find themselves in a common scenario: fresh out of college or just barely starting your career… but unlike other careers where there are defined training programs to show you the ropes, you end up wandering around the internet, hoping to pick up enough experience to land a job. Today, I am going to discuss a few areas where rookie web designers can drop the frustration and begin making high quality web sites faster.

    Visit Article

  • Design a Beautifully Detailed Web Button

    Design a Beautifully Detailed Web Button

    Today we’re going back to basics with a simple, elegant, and professional button tutorial from Liam McCabe. Liam creates all sorts of great web elements, so he’s going to be a great guide through the process. If you’ve been looking for a way to spice up your designs with a uniquely styled button or UI element, look no further…

    Visit Article

  • Dissecting Web Design: The “App” Site

    Dissecting Web Design: The “App” Site

    Web apps, Android apps, iPhone and iPad apps and now, with the release of Mac apps, the world appears to be going app crazy! It seems that there is an app to cater for almost every situation… but in a digital marketplace, how do these apps promote themselves? With web design of course!

    Visit Article

Mobiletuts+ iOS, Android & Sencha Tutorials

  • Developing RESTful iOS Apps with RestKit

    Developing RESTful iOS Apps with RestKit

    RestKit is a powerful library that simplifies interacting with web services for iOS applications. In this article, written by RestKit creator and Two Toasters CTO Blake Watters, we will take a quick tour of RestKit’s feature set, get familiar with the core concepts presented by the library, and then explore some code samples to get a feel for what working with RestKit is really like.

    Visit Article

  • Build a Titanium Mobile Pizza Ordering App: Crust Selection

    Build a Titanium Mobile Pizza Ordering App: Crust Selection

    In this multi-part tutorial series, I’ll be teaching you how to build a Titanium Mobile app from start to finish. Specifically, you’ll learn how to build a Pizza Shop app that will allow customers to order a custom pizza on the go. In this tutorial, I will demonstrate how to setup the project and create a “Crust Selection” screen.

    Visit Article

  • Android Tablet Virtual Device Configurations

    Android Tablet Virtual Device Configurations

    Back in mid-2010 you learned about common Android Virtual Device (AVD) configurations. We’re now in tablet-crazed early-2011. In this quick tutorial, you’ll extend your knowledge of AVDs by learning how to create configurations for two of the most popular Android tablets.

    Visit Article

Vectortuts+ Adobe Illustrator Tutorials

  • Illustrator CS5 Variable Width Stroke Tool: Perfect for Making Tribal Designs!

    Illustrator CS5 Variable Width Stroke Tool: Perfect for Making Tribal Designs!

    Adobe Illustrator CS5 features a slew of fantastic new tools and functionality, but the one that jumped out at me and really grabbed my attention was the Variable Width Stroke Tool. The concept was great. And when I actually put it to use – the experience was even greater than my expectations. In part one of this two part series we’ll be creating a tribal design and improving our Illustrator work flow along the way.

    Visit Article

  • Learning at the Speed of Technology

    Learning at the Speed of Technology

    If you’ve been using design software for as long as I have, you will no doubt have more than a few obsolete skills up your sleeve. Those of you who have mastered the notoriously difficult QuarkXPress will know what I mean. Dropping to a 25% market share, behind InDesign, many Quark users found themselves having to learn a new piece of software just to stay relevant in the workforce. With the current speed of software updates, how can you be sure that your skills will stay relevant in the future?

    Visit Article

  • Create a Retro Style, Airline Destination, Travel Poster – Vector Premium Tutorial

    Create a Retro Style, Airline Destination, Travel Poster – Vector Premium Tutorial

    Today, we have another Vector Premium tutorial exclusively available to Premium members. If you want to learn how to create a poster design, in the style of 1950′s air travel tourism. We’ll take a look at the typographic qualities and composition of late 50′s posters, then utilize modern digital rendering techniques to create an illustrated Australia tourism ad campaign.

    Visit Article

Phototuts+ Photography and Post-Processing Tutorials

  • Shooting an Amazing Product Photo That Tells a Story

    Shooting an Amazing Product Photo That Tells a Story

    In the United States, around $400 billion is spent on advertising each year. That’s “billion” with a “b.” A slice of that goes to producing photos for those advertisements. Commercial photographers can make a career out of shooting objects for advertisements, and in this tutorial, I’ll walk you through the process. I’ll explain how to decide about props, setting, lighting and toning. Mastering the “product shot” could lead to your next six-figure income (or maybe just some great eBay auctions) – either way it will be fun.

    Visit Article

  • Film Is Alive and Well: Tips, Cameras, and Beginners Advice

    Film Is Alive and Well: Tips, Cameras, and Beginners Advice

    When I first got into photography almost 20 years ago, film was the de facto standard and, obviously, the only standard. For over a hundred years film was the only option. The greatest names in photography all shot film; I’m sure you’ve heard of Ansel Adams.

    Visit Article

  • 100 Seriously Cool Self-Portraits (And Tips to Shoot Your Own!)

    Seriously Cool Self-Portraits (And Tips to Shoot Your Own!)

    The self-portrait has been a popular form of expression ever since man first saw his own reflection. Much like Narcissus, it’s often the case that we need not look beyond the tip of our own nose for a muse worth studying.

    Visit Article

Activetuts+ Flash, Flex and ActionScript Tutorials

  • Quick Tip: Displaying a 3D Model With Papervision3D

    Quick Tip: Displaying a 3D Model With Papervision3D

    In this Quick Tip we’ll take a look at how to embed and display a 3D model in Flash, using Papervision3D.

    Visit Article

  • Meet the New Activetuts+ Staff Writers!

    Meet the New Activetuts+ Staff Writers!

    A couple of weeks ago we advertised for a new Staff Writer at Activetuts+. The response was phenomenal! We had a pile of submissions to wade through and the quality of all applicants was of such a calibre that we chose to take on four new staff writers! There’s a good chance you’ll recognise these guys, come and meet them..

    Visit Article

  • Creating a Virtual Joystick for Touch Devices

    Creating a Virtual Joystick for Touch Devices

    A lot of Tablet Computers and Touch Screen devices have emerged, and it’s time to create games that have virtual joystick support on the screen for easier gameplay. Read on and discover how you can create a virtual joystick for your games on touch enabled devices..

    Visit Article

  • Audiotuts+ Music Theory, Production, Mixing Tutorials and More

  • 3D Mixing Part 5: Creative Routing

    D Mixing Part 5: Creative Routing

    Sorry for the long delay in continuing this series. I just moved across the country which took a bit more time and effort than I had originally hoped. In getting back on track with this tutorial, we are going to begin to look at some interesting ways of setting up our mix routing to maximize our mix-down flexibility; allowing us to shape our sounds into something with a more personal and artistic feel. As with any artistic endeavor, many of the settings and choice of effects shown here are going to be largely subjective, but much of the routing and underlying principals will help give you a solid jumping off point in making your mixes and sounds more diverse, interesting and personal.

    Visit Article

  • Quick Tip: Epic Drum Sequencing with QL Stormdrum – Part 1

    Quick Tip: Epic Drum Sequencing with QL Stormdrum – Part 1

    Probably most of you have played computer games or have watched movies, where the music is made with large percussion hits and really low ethnic drums. I remember watching the Warcraft 3 introduction video, where the attack of the orcs was accompanied by smashing drums. I always wanted to capture that sound and in this quick tip I’ll try to explain you some of the techniques I’ve come across in my experience.

    Visit Article

  • 4 Foolproof Ways to Make Your Home Studio Sound Better

    Foolproof Ways to Make Your Home Studio Sound Better

    It’s easy to make music at your home today. However, you can’t put up low budget monitors and a microphone and call yourself a studio. There is a difference between a nice home recording studio -” even if it’s just one spare room -” and a low-cost corner in your bedroom, especially if you want to make money with it. We all start somewhere, even if it is in the corner of our bedroom but what separates the men from the boys is being able to take it to the next level. What follows are some of the foolproof ideas to make your home recording studio sound better.

    Visit Article

Nettuts+ Web Development Tutorials and more

  • Why You’re a Bad PHP Programmer

    Why You’re a Bad PHP Programmer

    We all have our bad habits. In this article, we’ll go over a list of bad practices that are worth examining, reevaluating, and correcting immediately.

    Visit Article

  • 11 Lessons Learned After Running a Massively Popular Blog

    Lessons Learned After Running a Massively Popular Blog

    For the last three years, I’ve had the pleasure of managing Nettuts+ – a site with 80,000 subscribers, and over 3 million page views each month. In that course of time, I’ve learned a great deal about, not only what it takes to build an active community, but also the economics of running a sustainable and profitable blog. I’d like to share some of these lessons with you today.

    Visit Article

  • Canvas From Scratch: Introducing Canvas

    Canvas From Scratch: Introducing Canvas

    This is the first article in a series that will bring you up to speed with HTML5 canvas, the plugin-less drawing functionality built into modern browsers. In this introductory article, I’ll show you how to access the canvas element, draw shapes, change colours, and erase things. It’s a whistle-stop tour of the basics of this amazing new Web technology.

    Visit Article



View full post on Activetuts+

Mar 1, 2011 Posted on Mar 1, 2011 in Hints and Tips | 0 comments

Quick Freebie: Lip Sync Assets

Lip synching is the process of animating an illustrated character’s mouth to match its voice, creating the illusion that it is talking. This month, to tie in with our Quick Tip Week, we have a Quick Freebie from Santiago Degetau; a set of cartoon mouth graphics which you can use in your own projects to create speaking characters! Read on to find out more…


How to Use the Assets in Your Flash Project

First, download the zip file, and extract it to your hard drive.

Then, import the graphics into Flash: click File | Import | Import to Library, browse to the folder where you extracted the zip file and then to either the AI or EPS sub-folder (I’ll use AI, the Adobe Illustrator Format), select all the files, and click Open.

Flash Lip Sync assets

The default options are fine, so just keep clicking OK for every window that appears.

Flash Lip Sync assets

Tada! The assets are now in your Library:

Flash Lip Sync assets

As you can see, there are eight graphics. Each one corresponds to one or more manners of articulation — or, put more simply, one or more “letter sounds” — as indicated by its name. All you have to do is match the graphics to the sound track.

Having trouble? Don’t worry. An upcoming tutorial will explain how to handle the actual animation, in detail!



View full post on Activetuts+

Mar 1, 2011 Posted on Mar 1, 2011 in Hints and Tips | 0 comments

Quick Basix: Random Animated Blinking

Even when you’re animating on the timeline a touch of ActionScript can enhance what you’re doing. In this Quick Tip we’re going to use a single line of AS3 to add animated realism in the blink of an eye!


Step 1: Open Your Eyes

Grab the source files and open “basis.fla”. On the stage you’ll find the “head” movieclip, which comprises two layers containing the movieclips “face” and “eyes”.

Of course, if you want to start from scratch, using your own graphics, you’re welcome to do so..

Quick Basix: Random Animated Blinking

Step 2: The Eyes Have it

We’re going to make the eyes blink periodically, so begin by double-clicking the “eyes” movieclip to enter its timeline.


Step 3: Blinkered View

Lengthen the timeline by adding a keyframe at frame 80 on the “eyes” layer. This is where we’re going to place the eyes in their “blinked” state.

Quick Basix: Random Animated Blinking

Delete the open eyes from the stage and turn your attention to the library. In there, you’ll find “eyesClosed” which you can position on stage where the “eyesOpen” movieclip previously was.

With your eyesClosed selected, hit F5 to add a few more frames. Add as many as you want; doing so will increase the time your character’s eyes spend closed during any given blink. 3 frames is fine in our case.

Test your movie (Command/Ctrl + Enter) to get an idea of the blinking effect you’ve created.

The playhead moves along the timeline causing periodical blinking. Perfect! Right? Well not exactly. The uniform blinking would suggest that our character is either a robot or missing his frontal lobe.


Step 4: Randomeyes

Let’s improve the effect by randomising the blinking.

Add a second layer to the “eyes” movieclip, label it “actions” and lock it. Select the first frame and enter the following snippet in the actions panel (Window > Actions):

gotoAndPlay(uint(Math.random()*totalFrames)+1);

Step 5: Eye Examination

What does this snippet actually do? Well, the gotoAndPlay(); action sends the playhead along the current timeline, to whichever frame number we define within the braces. The contents within our braces will give us our frame number.

The Math.random() method will return a number between 0 and (though not including) 1. This is multiplied by totalFrames, a property of our movieclip – the amount of frames within it (in our case 83). uint() neatens up the outcome of our random number * totalFrames, by rounding down and giving us an integer.

The lowest integer we can expect is 0, since uint(0*83) is 0.

The highest integer we can hope for is 82, since uint(0.9999999999*83) is 82.

Therefore, we +1 to finish things off, giving us a destination frame somewhere between 1 and 83.

Once the playhead reaches the end of our timeline, it returns to frame 1 and is once again sent to a random frame.

Check the movie again!

Our character is still blinking, but now at irregular intervals, which looks far less lobotomised.

The effect becomes even clearer with two instances of our character on stage. In the example below, we have two different characters, but both make use of exactly the same “eyes” movieclip:

I’m not saying these two look like they’ve got it totally together, but you get the idea..


Improved Eyesight

This is a really simple end result, why not see if you can improve it?

  • Have a play with the timing; alter the framerate and number of frames within your blinking movie.
  • Why not try and alter the snippet to prevent the playhead from jumping to within the blinking action itself?
  • Perhaps you could even prevent the animation from blinking too rapidly in succession?

Conclusion

You’ve finished! This is a straight-forward and commonly used technique, but moving the playhead to random frames can be applied in thousands of situations. I hope you find use for it :)



View full post on Activetuts+

Mar 1, 2011 Posted on Mar 1, 2011 in Hints and Tips | 0 comments

Quick Tip: Conjure up a Jazzy Mouse Cursor Trail

In this Quick Tip you’ll learn how to use the Math functions in Flash to create trails of movie clips along whichever path the mouse cursor takes.

You’ll also learn the basics of the Math functions, such as varying the size, alpha, and color of the Movie Clip – and all this using AS3. I hope you find this Quick Tip useful!


Final Result Preview

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


Step 1: Make the Movie Clip

First, open a new Flash file (Ctrl + N) and choose “ActionScript 3.0″. We have to create the Movie Clip that will be duplicating around the scene. So go to Insert > New Symbol (Ctrl + F8). Call this symbol: “Ink”, choose Movie Clip, and finally check the “Export for Actionscript” box.

Flash cursor trails
Flash cursor trails
Flash cursor trails

Step 2: Adding the “Ink”

Now we have to create the ink in the Movie Clip. So, go to the first frame, take the Brush Tool (B) and draw a circle, then align it to the center. Make the same steps on three more frames and vary the color in each frame (first Frame: Red, second Frame: Blue, third Frame: Yellow, etc….). On each frame, open the Actions panel (hit F9) and add the stop action: stop();

Flash cursor trails
Flash cursor trails

Step 3: Organizing the Project

Save this file on a folder on your computer, call it: “MathFunctions_Tutorial.fla”. Create a new ActionScript file and save it in the same folder, give it a name of “MathFunctions_Flash.as”. Finally, go to the Properties of MathFunctions_Tutorial.fla and change the Class field for the Actionscript File.

If you’re not very familiar with using classes, I recommend you read this Quick Tip.

Flash cursor trails
Flash cursor trails
Flash cursor trails

Step 4: Let’s Start Coding!

Open the file called “MathFunctions_Flash.as” and write the following code:

package {
	import flash.display.MovieClip;
	import flash.events.*;

	public class MathFunctions_Flash extends MovieClip {

In this action we are defining the Class and its properties.

Now we have to tell Flash that when the mouse moves, the function called stageMouseMove() should be called. To do this, just write the following:

public function MathFunctions_Flash(){
   stage.addEventListener(MouseEvent.MOUSE_MOVE, stageMouseMove);
}

After that, we have to define this function and link the Movie Clip called “Ink” to the ActionScript.

public function stageMouseMove(event:MouseEvent):void {
	var ink:Ink=new Ink();

Now we are going to add the actions to the variable and the function called stageMouseMove(). And here are the magical Math functions.

OK, on the Math functions there a lot of things that make the magic. Here I leave you a small formula:

Flash cursor trails
   ink.x=stage.mouseX;
   ink.y=stage.mouseY;
   ink.gotoAndStop(Math.ceil(Math.random()*5));
   ink.scaleX=ink.scaleY=Math.random()*1;
   ink.alpha=Math.random()*10;
   stage.addChild(ink);
	}
  }
}

For more details on this formula, see Get a Random Number Within a Specified Range Using AS3.

And that’s all!


Conclusion

I hope you liked this Quick Tip, thanks for reading!



View full post on Activetuts+

Page 10 of 21« First«...89101112...20...»Last »
search search search search search
Find an Article
Categories
  • Flash Video Training
  • Hints and Tips
  • Recommended
Please Support Our Sponsors
Recent Posts
  • The Math and ActionScript of Curves: Drawing Quadratic and Cubic Curves
  • Weekend Lecture: Understanding Games, a Flash Game About Game Design
  • Weekend Lecture: Understanding Games, a Flash Game About Game Design
  • Workshop Coding Challenge: Fix This Breakout Game
  • Enable the Latest AIR SDK in Flash Professional CS5.5+
Tag Cloud
2011 ActionScript Active Activetuts+ Adobe animation Basic Basix Best Build Button Character 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+ Tween 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
May 2012
M T W T F S S
« Apr    
 123456
78910111213
14151617181920
21222324252627
28293031  
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

  • 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