Posts

Showing posts from 2008

Flash CS3 - Circular Motion - Rotating Square

ActionScript Code: stage.frameRate=30; //draw square var square:Shape = new Shape(); square.graphics.beginFill(0xFF6600,1); square.graphics.drawRect(-25,-25,50,50); square.graphics.endFill(); square.x=stage.stageWidth/2; square.y=stage.stageHeight/2; addChild(square); //draw circle var circle:Shape = new Shape(); circle.graphics.lineStyle(1,0x00FFCC); circle.graphics.drawCircle(0,0,100); circle.x=stage.stageWidth/2; circle.y=stage.stageHeight/2; addChild(circle); //Animate SquaRE var radius:Number = 100; var speed:Number = .1; var xcenter:Number = square.x; var ycenter:Number = square.y; var degree:Number = 0; stage.addEventListener(Event.ENTER_FRAME,myFunction); function myFunction(e:Event):void { degree += speed; square.x = xcenter+Math.cos(degree)*radius; square.y = ycenter+Math.sin(degree)*radius; }

Flash CS3 - Flash Random Quiz with Timer (AS3)

Download FlashQuiz.zip (12 KB) ActionScript Code: package { import flash.display.MovieClip; import flash.display.Shape; import flash.text.TextField; import flash.text.TextFieldAutoSize; import flash.text.TextFormat; import flash.text.TextFormatAlign; import flash.text.AntiAliasType; import flash.utils.Timer; import flash.events.TimerEvent; import flash.events.MouseEvent; public class FlashQuiz extends MovieClip { var Circle=new Shape; var Line=new Shape; var time:Number=10;//edit it to change time limit duration var counter:Number=0; var rotator:Number=0; var myTimer:Timer=new Timer(1000); var newFormat:TextFormat=new TextFormat; var QuestionTextField=new TextField; var QuestionTextField2=new TextField; var questions:Array=new Array; var answers:Array=new Array; var questionsLength:Number; var questionsLengthCheck:Number=1; var arr_randumNumbers:Array=new Array; var arr_randumNumbers2:Array=new Array; var m_iIndex:uint; var Text; var Q

Magic Squares (Testing)

Flash CS3 - XML Guestbook (AS3)

view guestbook.xml Download  - XmlCs3GuestBook.zip XmlCs3GuestBook.as ActionScript Code: package { import flash.display.MovieClip; import flash.display.Loader; import flash.net.URLLoader; import flash.net.URLRequest; import flash.events.*; import flash.text.TextField; import flash.text.TextFieldType; import fl.controls.ScrollBar; import fl.controls.UIScrollBar; import flash.text.TextFieldAutoSize; import fl.transitions.Tween; import fl.transitions.TweenEvent; import fl.transitions.easing.*; import flash.net.navigateToURL; import flash.net.URLRequest; import flash.net.URLVariables; import flash.net.URLRequestMethod;   public class XmlCs3GuestBook extends MovieClip { var loader:Loader = new Loader(); var xmlData:XML= new XML(); var xmlLoader:URLLoader = new URLLoader(); var TxtMessges:TextField = new TextField(); var myScrollBar = new UIScrollBar(); var MSGCounter:int = 1; var form = new MovieClip(); public function XmlCs3GuestBook():void { stage.

Onam Greetings

Flash CS3 - Flash AutoComplete And Cookie

Image
Try it here Download AutoComplete.zip ActionScript Code: package { import flash.display.*; import flash.events.*; import flash.net.*; import flash.text.*; import fl.data.DataProvider; public class cookies extends Sprite { var soDomain:String="FlashAutoCompleteCookieTest"; //Returns a reference to a locally persistent shared object that is only available to the current client. If the shared object does not already exist, this method creates one. If any values passed to getLocal() are invalid or if the call fails, Flash Player throws an exception. var so:SharedObject=SharedObject.getLocal(soDomain); var ObjectCount=new int; var CookieArray:Array = new Array(); public function cookies():void { saveBtn.addEventListener(MouseEvent.CLICK,saveHandler); deleteBtn.addEventListener(MouseEvent.CLICK,deleteHandler); if (so.data['ObjectTotal'] == undefined) { so.data['ObjectTotal']=0; so.flush(); } ObjectCount=so.data['Objec

Flash CS3 - Text With Blur Effect - (Move your mouse over the text !!)

Move your mouse over the text !! ActionScript Code: stage.frameRate=30; var dragFactor:Number=.15; var newFormat:TextFormat = new TextFormat(); newFormat.size=20; newFormat.bold=true; newFormat.color=0xFF0000; newFormat.align=TextFormatAlign.LEFT; var MyTextField = new TextField(); MyTextField.text="AS3 ROCKS!!"; MyTextField.width=200; MyTextField.selectable=false; MyTextField.setTextFormat(newFormat); addChild(MyTextField); stage.addEventListener(Event.ENTER_FRAME,MOUSE_MOVE_Handler); function MOUSE_MOVE_Handler(e:Event):void { var xPos:Number=mouseX; var yPos:Number=mouseY; xPos=MyTextField.x; xPos -= (xPos-mouseX) * this.dragFactor; yPos=MyTextField.y; yPos -= (yPos-mouseY) * this.dragFactor; MyTextField.x=xPos; MyTextField.y=yPos; MyTextField.filters=[new BlurFilter(Math.abs(xPos-mouseX),Math.abs(yPos-mouseY),1)]; }

Flash CS3 - Sliding Menu

Download SlidingMenu.zip import fl.transitions.Tween; import fl.transitions.easing.*; import fl.transitions.TweenEvent; var i = new int; var MyRoot = root; //edit this no var BoxSize:Number = 100; //edit this no var BoxNum:Number = 4; var MainMenu = createManu(); var MenuMask = createBox(BoxSize,0xFFCC00); MainMenu.mask = MenuMask; MainMenu.animation=1; function createManu():MovieClip { var menu = new MovieClip(); for (i=0; i<BoxNum; i++) { var MenuItem = createBox(BoxSize,0xFFCC00/i); menu.addChild(MenuItem); MenuItem.x=BoxSize*i; var newFormat:TextFormat = new TextFormat(); newFormat.size=BoxSize; newFormat.color=0xFFFFFF; newFormat.align = TextFormatAlign.CENTER; var target = MenuItem.getChildAt(0); target.text = i; target.width = BoxSize; target.height = BoxSize; target.x=0; target.y=0; target.selectable = false; target.setTextFormat(newFormat); target.mouseEnabled = false; MenuItem.id=i; MenuItem.addEventListener(MouseEvent.CLICK,ClickHandler); MenuItem.buttonMode = true; }

Flash CS3 - Drag And Drop (Simple Game)

Download DragAndDrop.zip Paste this code in your AS panel . You dont need to create anything on the stage import fl.transitions.Tween; import fl.transitions.easing.*; stage.frameRate=30; var TargetCircle = CreateCircle(0x00FF00,100); TargetCircle.x=250; TargetCircle.y=200; addChild(TargetCircle); var SmallCircle = CreateCircle(0xFF6600,10); SmallCircle.x=50; SmallCircle.y=200; SmallCircle.buttonMode = true; SmallCircle.addEventListener(MouseEvent.MOUSE_DOWN,DOWNHandler); SmallCircle.addEventListener(MouseEvent.MOUSE_UP,UPHandler); addChild(SmallCircle); function DOWNHandler(e:MouseEvent) { e.target.startDrag(); } function UPHandler(e:MouseEvent) { e.target.stopDrag(); if (SmallCircle.hitTestObject(TargetCircle)==false) { TweenHandler(); } } function CreateCircle(color:Number,radius:Number):MovieClip { var circle:MovieClip = new MovieClip; circle.graphics.beginFill(color,1); circle.graphics.drawCircle(0,0,radius); circle.graphics.endFill(); return circle; } function TweenHandler() { var

Flash CS3 - Rotating Sunrays Animation

Copy and paste this AS3 code to the first frame of your flash CS3 document . You don't need to create anything on the stage ActionScript Code: function CreateRays():Shape { var ray:Shape = new Shape(); ray.graphics.beginFill(0xFF9900,.5); ray.graphics.lineStyle(1,0xFF9900,.5); ray.graphics.lineTo(600,-20); ray.graphics.lineTo(600,20); ray.graphics.lineTo(0,0); ray.graphics.endFill(); return ray; } var sun:Shape = new Shape(); sun.graphics.beginFill(0xFF9900,1); sun.graphics.drawCircle(0,0,30); sun.graphics.endFill(); //edit this no to change the no of rays :-) var SunaRays:Number=25; var rayShapes = new Shape(); var SunGlow:MovieClip = new MovieClip(); for (var i:int = 1; i<=SunaRays; i++) { rayShapes=CreateRays(); rayShapes.rotation=360/(SunaRays)*i; SunGlow.addChild(rayShapes); } SunGlow.addChild(sun); addChild(SunGlow); SunGlow.x=stage.stageWidth/2; SunGlow.y=stage.stageHeight/2; //you can change fps here stage.frameRate=30; stage.addEventListener(Event.ENTER_F

Flash CS3 - Flash website with a simple preloader

download preloader.zip ////////////////////////////////// stop(); var Circle = new Shape(); Circle.graphics.lineStyle(5,0x00FF00); Circle.graphics.drawCircle(100, 100, 50); var Line = new Shape(); Line.graphics.lineStyle(5,0x00FF00); Line.graphics.lineTo(0,-40); Line.x=100; Line.y=100; var Status = new TextField(); Status.autoSize =TextFieldAutoSize.CENTER; Status.selectable = false; Status.y = 100; Status.x = 100; addChild(Circle); addChild(Line); addChild(Status); function PreLoader() { this.loaderInfo.addEventListener(Event.COMPLETE, initApplication); this.loaderInfo.addEventListener(ProgressEvent.PROGRESS, showProgress); } function showProgress(theProgress:ProgressEvent):void { var percent:Number =(theProgress.bytesLoaded) / (theProgress.bytesTotal)*100; Line.rotation=percent*3.6; Status.text = Math.round(percent)+" %"; } function initApplication(myEvent:Event):void { removeChild(Circle); removeChild(Line); removeChild(Status); gotoAndStop("frm_main"); } PreLoa

Flash CS3 - AS3 Counter

Copy and paste this AS3 code to the first frame of your flash CS3 document . You don't need to create anything on the stage import fl.transitions.Tween; import fl.transitions.TweenEvent; import fl.transitions.easing.*; var counter:int = 0; var MyFormat:TextFormat=new TextFormat; MyFormat.bold=true; MyFormat.font="Arial"; MyFormat.size=50; MyFormat.color=0x000000; function createShape():MovieClip { var shape = new MovieClip(); var shapeBG = new MovieClip(); var shapeMask = new MovieClip(); var shapeText = new TextField(); shapeText.defaultTextFormat=MyFormat; shapeText.text="0"; shapeText.autoSize =TextFieldAutoSize.CENTER; shapeText.selectable = false; shapeText.name = "shapeText"; shapeText.y = -5; shapeText.x = 10; shapeText.mask = shapeMask; shapeText.name = "shapeText"; shapeBG.graphics.beginFill(0xE6E6E6, 1); shapeBG.graphics.drawRoundRect(0, 0, 50, 50, 25, 25); shapeBG.graphics.endFill(); shapeBG.name = "shapeBG"; shapeMas

Flash CS3 - Random Image Loader With Progress Bar

ImageLoader.zip package { import flash.display.*; import flash.events.*; import flash.net.*; import flash.text.*; import fl.controls.*; import fl.transitions.Tween; import fl.transitions.easing.*; public class ImageLoader extends Sprite { var imageLoader:Loader = new Loader(); var imagesArr:Array=new Array("image1.jpg","image2.jpg","image3.jpg","image4.jpg","image5.jpg"); var mc_ProgressBar:MovieClip = new MovieClip(); var StatusBar:MovieClip = new MovieClip(); var txtStatus:TextField = new TextField(); var LoadBtn = new Button(); public function ImageLoader():void { addChild(imageLoader); addChild(mc_ProgressBar); addChild(LoadBtn); LoadBtn.y=270; LoadBtn.label ="Load Image"; LoadBtn.width = 80; imageLoader.alpha=0; DrawProgressBar(); imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandler); imageLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, progressHandler); LoadBtn.addEvent

FlashCS3 - Full Screen Flash Website - II (True Full Screen)

Click HERE For Full Screen Window Click anywhere on the stage after you click on the link above. Source File - fullScreen2.zip package { import flash.display.*; import flash.events.*; import fl.transitions.Tween; import fl.transitions.TweenEvent; import fl.transitions.easing.*; import flash.text.*; public class fullScreen2 extends MovieClip { public function fullScreen2():void { stage.align=StageAlign.TOP_LEFT; stage.scaleMode=StageScaleMode.NO_SCALE; stage.addEventListener(Event.RESIZE,stageResized); StageElementMiddle.x=stage.stageWidth / 2; StageElementMiddle.y=stage.stageHeight / 2; ArrangeItems(); stage.addEventListener(MouseEvent.CLICK,FullScreen); } function stageResized(e:Event):void { ArrangeItems(); } function positionFn(TweenMC:MovieClip,StageWidth:Number,StageHeight:Number):void { var tween_handler_1 = new Tween(TweenMC,"x",Elastic.easeInOut,TweenMC.x,StageWidth,1,true); var tween_handler_2 = new Tween(TweenMC,"y"

FlashCS3 - Full Screen Flash Website - I

Click HERE For Full Screen Window Source File - fullScreen1.zip package { import flash.display.*; import flash.events.*; import fl.transitions.Tween; import fl.transitions.TweenEvent; import fl.transitions.easing.*; import flash.text.*; public class fullScreen1 extends MovieClip { public function fullScreen1():void { stage.align=StageAlign.TOP_LEFT; stage.scaleMode=StageScaleMode.NO_SCALE; stage.addEventListener(Event.RESIZE,stageResized); StageElementMiddle.x=stage.stageWidth / 2; StageElementMiddle.y=stage.stageHeight / 2; ArrangeItems(); } function stageResized(e:Event):void { ArrangeItems(); } function positionFn(TweenMC:MovieClip,StageWidth:Number,StageHeight:Number):void { var tween_handler_1 = new Tween(TweenMC,"x",Elastic.easeInOut,TweenMC.x,StageWidth,1,true); var tween_handler_2 = new Tween(TweenMC,"y",Elastic.easeInOut,TweenMC.y,StageHeight,1,true); tween_handler_1.addEventListener(TweenEvent.MOTION_FINISH,UpdateSta

Flash CS3 – Using Arrow Keys To Move An Object

Copy and paste this AS3 code to the first frame of your flash CS3 document . var UrShape:Shape = new Shape(); addChild(UrShape); UrShape.x = 250; UrShape.y = 150; UrShape.graphics.lineStyle(3, 0x000000); UrShape.graphics.beginFill(0x9900FF, 1); UrShape.graphics.drawRect(0, 0, 50,50); UrShape.graphics.endFill(); stage.addEventListener(KeyboardEvent.KEY_DOWN,MoveRectangle); function MoveRectangle(keyEvent:KeyboardEvent):void { switch (keyEvent.keyCode) { case 37 ://left arrow UrShape.x--; break; case 38 ://up arrow UrShape.y--; break; case 39 ://right arrow UrShape.x++; break; case 40 ://down arrow UrShape.y++; break; default : break; } }

Flash CS3 - Positioning An Object With Slider

Copy and paste this AS3 code to the first frame of your flash CS3 document. stage.frameRate=30; var MyShape:Shape = new Shape(); MyShape.graphics.lineStyle(1, 0x000000); MyShape.graphics.beginFill(0x6633CC, 1); MyShape.graphics.drawCircle(0, 0, 50); MyShape.graphics.endFill(); addChild(MyShape); ////////////////// var xLine:Shape = new Shape(); xLine.graphics.lineStyle(1, 0x666666); xLine.graphics.moveTo(30, 30); xLine.graphics.lineTo(500, 30); xLine.graphics.endFill(); addChild(xLine); ////////// var yLine:Shape = new Shape(); yLine.graphics.lineStyle(1, 0x666666); yLine.graphics.moveTo(30, 30); yLine.graphics.lineTo(30, 350); yLine.graphics.endFill(); addChild(yLine); /////////// var xSlider:MovieClip = new MovieClip(); xSlider.x =xLine.width/2; xSlider.y = 15; xSlider.graphics.lineStyle(1, 0x000000); xSlider.graphics.beginFill(0xFF6600, 1); xSlider.graphics.drawRoundRectComplex(0, 0, 10, 30, 20, 20, 20, 20); xSlider.graphics.endFill(); addChild(xSlider); /////////// var ySlider:Movi

Flash CS3 - Walk Cycle

walk_cycle.zip

Flash CS3 - Custom Mouse Pointer

Click on each mouse pointer pointer.as package { import flash.display.*; import flash.events.*; import flash.filters.*; import flash.text.*; import flash.ui.Mouse; public class pointer extends Sprite { //you can see them on the stage var pnt_1= new Pointer_1(); var pnt_2= new Pointer_2(); var pnt_3= new Pointer_3(); //your current Mouse Pointer var CurrentPointer = new MovieClip(); var Text1:TextField = new TextField(); var Text2:TextField = new TextField(); var Text3:TextField = new TextField(); var DropShadow:DropShadowFilter = new DropShadowFilter(); public function pointer():void { //add three custom pointers on the stage AddPointers(); AddText(); //give them a shadow effect ApplyFilter(); //we use this id in function PointerListener() pnt_1.id=1; pnt_2.id=2; pnt_3.id=3; pnt_1.addEventListener(MouseEvent.CLICK, PointerListener); pnt_2.addEventListener(MouseEvent.CLICK, PointerListener); pnt_3.addEventListener(MouseEvent.CLICK, PointerListener); addChild(CurrentPointer); } private f

Flash CS3 - A Simple Game

game.as package { import flash.display.*; import flash.ui.Mouse; import flash.events.*; import flash.text.*; public class game extends Sprite { var hits:int=0; var misses:int=0; var shots:int=0; var cDepth:int=100; var level:int=1; var xSpeed:Number=3; var stageWidth:Number=550; var stageHeight:Number=300; var AirCraft_MC:MovieClip = new MovieClip(); var AimMC:MovieClip=new Aim_mc;//MovieClip to aim your gun - we import this MovieClip direct from Lib var stats_txt:TextField=new TextField;// create a text field to display the player's statistics. public function game():void { black_mc.start_btn.addEventListener(MouseEvent.MOUSE_DOWN ,StartFunction); black_mc.start_btn.buttonMode=true; } private function StartFunction(event:MouseEvent ):void { black_mc.visible =false; aim(); stats_txt_fn(); stage.addEventListener(MouseEvent.MOUSE_MOVE,HideMouse); stage.addEventListener(MouseEvent.MOUSE_DOWN,GunShot); stage.addEventListener(Event.ENTER_FRAME,addAirCrafts); } private function aim() { A

Flash CS3 and XML - Loading XML in Flash

View PersonalDetails.xml loadxml.as package { import flash.display.*; import flash.net.*; import flash.events.*; import fl.controls.DataGrid; import fl.containers.UILoader; import flash.text.*; public class loadxml extends Sprite { var xmlFile:String="PersonalDetails.xml"; var datagrid=new DataGrid; var imgLoader=new UILoader; var nameTxt=new TextField; var occupationTxt=new TextField; var ageTxt=new TextField; var emailTxt=new TextField; public function loadxml():void { callBtn.addEventListener(MouseEvent.CLICK,callServer); } function callServer(e:MouseEvent):void { var urlRequest:URLRequest=new URLRequest(xmlFile); var loader:URLLoader=new URLLoader; loader.addEventListener(Event.COMPLETE,xmlLoaded); loader.load(urlRequest); } function xmlLoaded(e:Event):void { var loader:URLLoader=URLLoader(e.target); var xml:XML=new XML(loader.data); createDataGrid(); createTextFields(); createImageLoader(); // loop through the details and insert each one into the DataGrid for each (var i

Flash CS3 and PHP - File Upload

ActionScript 3 package { import flash.display.Sprite; import flash.text.TextField; import flash.events.*; import flash.net.*; import fl.controls.Button; public class FileUpload extends Sprite { private var _output:TextField; private var _fileReference:FileReference; var browseButton:Button = new Button(); var uploadButton:Button = new Button(); public function FileUpload() { browseButton.move(10, 30); browseButton.buttonMode = true; browseButton.label = "Browse"; browseButton.addEventListener(MouseEvent.CLICK, browseHandler); addChild(browseButton); uploadButton.move(120,30); uploadButton.buttonMode=true; uploadButton.label ="Upload"; uploadButton.addEventListener(MouseEvent.CLICK, uploadHandler); uploadButton.visible = false; addChild(uploadButton); _output = new TextField(); _output.width = 400; _output.height = 400; _output.y = 75; addChild(_output); _fileReference = new FileReference(); _fileReference.addEventListener(Event.SELECT, selectHandler); _fileReference

Flash CS3 and PHP - Send and Receive data

Codes sendtophp.as package { import flash.display.*; import flash.events.*; import flash.net.*; import flash.text.*; public class sendtophp extends Sprite { var phpFile:String = "sendDataToServer.php"; public function sendtophp():void { callBtn.addEventListener(MouseEvent.CLICK, callServer); } function callServer(e:MouseEvent):void { var urlRequest:URLRequest = new URLRequest(phpFile); var urlParams:URLVariables = new URLVariables(); urlParams.sampleVal = sendTxt.text; urlRequest.method = URLRequestMethod.POST; urlRequest.data = urlParams; var loader:URLLoader = new URLLoader(); loader.addEventListener(Event.COMPLETE, serverResponse); loader.load(urlRequest); } function serverResponse(e:Event):void { var loader:URLLoader = URLLoader(e.target); var variables:URLVariables = new URLVariables(loader.data); responseTxt.text = variables.returnValue; } }//end of class sendtophp }//end of package sendDataToServer.php < ? php print "returnValue= Hi ".$_POST['sampleVal

A Simple Car Animation

Image
What you see on the stage What actually happens We need 6 graphics for this animation Draw them as shown in the above image (You don’t need to write the name, only graphics) Now you have 6 graphics on the stage 1. SKY 2. CLOUD 3. LOG 4. CAR BODY 5. TYRE 6. ROAD Click on Selection Tool (V) and draw a rectangle around the cloud to select it. Press F8 You should immediately see a popup dialogue box Name - cloud Type – Movie Clip Registration – Center Then press OK See the drawing has been converted to a Movie clip symbol Do the same steps for · SKY · LOG · CAR BODY · TYRE · ROAD Select the tyre Movie clip with Selection Tool (V) Press the Alt key and drag the tyre to right side Release the mouse and Alt key Now you have two tyres !!!! Now we are ready for the animation Arrange car and tyres and select them all (Car and two tyres). (For multiple section use Shift key) Press F8 Name it car Now we need a fence like this Select the log Press Ctrl+C – (copy) then Ctrl +Shift+ V (Paste in Place

Classes

Image
Classes Before AS3 you don’t need thorough knowledge in flash to do animations and interactive presentations. But in case of AS3 the scenario is different. Even if you try to learn it from online tutorials you will certainly be blocked by some barriers knows as classes. This tutorial is only for beginners in AS3 which will explain the functioning of a simple class. Create a folder named MyClass anywhere in your computer Create next folder classes as a subfolder of MyClass Open Adobe Flash CS3 Professional then create a new Flash file (ActionScript 3) and save it as MyFirstClassFile.fla in your MyClass folder In file menu select New > ActionScript File Save it as MyFirstClass in your folder MyClass > classes Now you can see two tabs named MyFirstClassFile.fla and MyFirstClass.as in your window Select MyFirstClass.as and type the following package classes{ public class MyFirstClass { public function MyFirstClass() { trace("MyFirstClass is working"); } } } back to MyFirstC