Flash CS3 - Flash CS4

Free tutorials and scripts for all.
Actionscript 3.0

Using NumericStepper - Flash CS3 component

This is a discussion on Using NumericStepper - Flash CS3 component within the Tutorials forums, part of the English Forums category; Today I would like to introduce the NumericStepper component to carry on the series of tutorials on how to use ...


Go Back   Forum Flash CS3 Flash CS4 > English Forums > Tutorials

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 27-11-07, 06:26
Administrator
 
Join Date: Jul 2007
Location: Cesena
Posts: 4,446
Rep Power: 6
Flep is on a distinguished road
Using NumericStepper - Flash CS3 component

Today I would like to introduce the NumericStepper component to carry on the series of tutorials on how to use the Flash CS3 components.
Normally this component is used in application containing lots of numerical data or also is useful when developing forms to send data.
In this tutorial, I will used it applied to a MovieClip using Actionscript 3.0 .



I create a FLA and I save it as "main.fla" into which I have a MovieClip of square shape with an instance name "clip_mc".
I create the Document Class, an AS file saved as "Main.as", implemented the following way:


Code:
package
{
	import flash.display.MovieClip;
	import flash.events.Event;
	import fl.controls.NumericStepper;
	
	public class Main extends MovieClip
	{
		private var num_x:NumericStepper;
		private var num_y:NumericStepper;
		private var num_w:NumericStepper;
		private var num_h:NumericStepper;
		
		public function Main()
		{
			init();
			initSteppers();
		}
		
		private function init():void
		{
			stage.frameRate=31;
		}
		
		private function initSteppers():void
		{
			num_x=new NumericStepper();
			num_x.move(30,30);
			num_x.minimum=0;
			num_x.maximum=stage.stageWidth;
			num_x.value=clip_mc.x;
			num_x.stepSize=1;
			addChild(num_x);
			
			num_y=new NumericStepper();
			num_y.move(num_x.x+num_x.width,30);
			num_y.minimum=0;
			num_y.maximum=stage.stageHeight;
			num_y.value=clip_mc.y;
			num_y.stepSize=1;
			addChild(num_y);
			
			num_w=new NumericStepper();
			num_w.move(num_y.x+num_y.width,30);
			num_w.minimum=clip_mc.width/2;
			num_w.maximum=clip_mc.width*2;
			num_w.value=clip_mc.width;
			num_w.stepSize=1;
			addChild(num_w);
			
			num_h=new NumericStepper();
			num_h.move(num_w.x+num_w.width,30);
			num_h.minimum=clip_mc.height/2;
			num_h.maximum=clip_mc.height*2;
			num_h.value=clip_mc.height;
			num_h.stepSize=1;
			addChild(num_h);
			
			num_x.addEventListener(Event.CHANGE,moveX);
			num_y.addEventListener(Event.CHANGE,moveY);
			num_w.addEventListener(Event.CHANGE,resizeW);
			num_h.addEventListener(Event.CHANGE,resizeH);
		}
		
		private function moveX(evt:Event):void
		{
			clip_mc.x=evt.target.value;
		}
		
		private function moveY(evt:Event):void
		{
			clip_mc.y=evt.target.value;
		}
		
		private function resizeW(evt:Event):void
		{
			clip_mc.width=evt.target.value;
		}
		
		private function resizeH(evt:Event):void
		{
			clip_mc.height=evt.target.value;
		}
	}
}

The result is the following:









Let us analyse the code


I import the needed classes
import flash.display.MovieClip;
import flash.events.Event;
import fl.controls.NumericStepper;


Properties
4 variables type NumerciStepper
private var num_x:NumericStepper;
private var num_y:NumericStepper;
private var num_w:NumericStepper;
private var num_h:NumericStepper;


Constructor function
I call the method init()
init();
I call the method initSteppers
initSteppers();


Methods
init();
I impost the frame rate
stage.frameRate=31;


initSteppers();
I create the 4 NumericStepper, assign a position, a minimal value, a maximal value, an initial value, a step value (the added value at each click) and I add them to the stage
num_x=new NumericStepper();
num_x.move(30,30);
num_x.minimum=0;
num_x.maximum=stage.stageWidth;
num_x.value=clip_mc.x;
num_x.stepSize=1;
addChild(num_x);


num_y=new NumericStepper();
num_y.move(num_x.x+num_x.width,30);
num_y.minimum=0;
num_y.maximum=stage.stageHeight;
num_y.value=clip_mc.y;
num_y.stepSize=1;
addChild(num_y);


num_w=new NumericStepper();
num_w.move(num_y.x+num_y.width,30);
num_w.minimum=clip_mc.width/2;
num_w.maximum=clip_mc.width*2;
num_w.value=clip_mc.width;
num_w.stepSize=1;
addChild(num_w);


num_h=new NumericStepper();
num_h.move(num_w.x+num_w.width,30);
num_h.minimum=clip_mc.height/2;
num_h.maximum=clip_mc.height*2;
num_h.value=clip_mc.height;
num_h.stepSize=1;
addChild(num_h);
I add to each NumericStepper a listener to the event Event.CHANGE which will call the respective functions
num_x.addEventListener(Event.CHANGE,moveX);
num_y.addEventListener(Event.CHANGE,moveY);
num_w.addEventListener(Event.CHANGE,resizeW);
num_h.addEventListener(Event.CHANGE,resizeH);


moveX(evt:Event):void
I move the clip_mc x based on the value of the correspondent NumericStepper (retrieved with evt.target which is the numeric stepper with the changed value and then .value, its value)


moveY(evt:Event):void
I move the clip_mc y based on the value of the correspondent NumericStepper


resizeW(evt:Event):void
I change the clip_mc width based on the value of the correspondent NumericStepper


resizeY(evt:Event):void
I change the clip_mc height based on the value of the correspondent NumericStepper


See you soon!


Last edited by Flep; 28-08-08 at 06:40..
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

  #2 (permalink)  
Old 09-02-08, 18:12
Junior Member
 
Join Date: Feb 2008
Posts: 1
Rep Power: 0
soytofu is on a distinguished road
Re: Using NumericStepper - Flash CS3 component

i want to create something like this,

http://www.wral.com/news/local/flash/1989625/

and do you know how to make it?

Thank you.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads

Thread Thread Starter Forum Replies Last Post
ProgressBar Component of Flash CS3 Flep Tutorials 1 28-10-08 06:28
RadioButton component of Flash CS3 Flep Tutorials 1 05-08-08 09:52
The Slider component of Flash CS3 Flep Tutorials 14 07-07-08 23:41
NumericStepper - componente di Flash CS3 Flep Articoli e tutorials 0 29-10-07 06:43
ColorPicker - Flash CS3 Component Flep Tutorials 0 08-10-07 16:14


All times are GMT. The time now is 23:19.


Powered by vBulletin versione 3.7.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC4
Forum SiteMap


FlepStudio
by Filippo Lughi
P.IVA 03605860406