Reclaimer Effect
This is the result of a little experiment I was trying. Calling this one a “reclaimer” effect. One object pulling another object, one particle at a time.
Sorry but the code is uncommented.
/** * VERSION: 1.0 * DATE: 3/12/2010 * AS3 * UPDATES AND DOCUMENTATION AT: http://www.FreeActionScript.com **/ package { import flash.display.BitmapData; import flash.display.Sprite; import flash.display.MovieClip; import flash.events.Event; import flash.events.MouseEvent; public class Reclaimer extends Sprite { private var particlesCurrent:Number = 0; private var particlesTotal:Number = 50; private var particleSpeed:Number = 10; private var particleFadeoutSpeed:Number = .05; private var particlesArray:Array; private var radians:Number; public function Reclaimer():void { init(); } private function init():void { radians = 180 / Math.PI; particlesArray = []; addEventListener(Event.ENTER_FRAME, onEnterFrameLoop); thing1.addEventListener(MouseEvent.MOUSE_DOWN, onThingDown); thing2.addEventListener(MouseEvent.MOUSE_DOWN, onThingDown); thing1.addEventListener(MouseEvent.MOUSE_UP, onThingUp); thing2.addEventListener(MouseEvent.MOUSE_UP, onThingUp); } private function onThingDown(event:MouseEvent):void { event.currentTarget.startDrag(); } private function onThingUp(event:MouseEvent):void { event.currentTarget.stopDrag(); } private function createThing(target1:MovieClip, target2:MovieClip):void { if(particlesTotal <= particlesCurrent) { return; } particlesCurrent++; var tempParticle:Particle = new Particle(); tempParticle.x = target1.x + Math.random() * target1.width; tempParticle.y = target1.y + Math.random() * target1.height; tempParticle.rotation = Math.random()*360; tempParticle.rot = Math.atan2(target1.y - target2.y, target1.x - target2.x); tempParticle.xSpeed = Math.cos(tempParticle.rot) * radians / particleSpeed; tempParticle.ySpeed = Math.sin(tempParticle.rot) * radians / particleSpeed; particlesArray.push(tempParticle); addChild(tempParticle); } private function updateParticle():void { for (var i = 0; i < particlesArray.length; i++) { var tempParticle:MovieClip = particlesArray[i]; tempParticle.x -= tempParticle.xSpeed; tempParticle.y -= tempParticle.ySpeed; tempParticle.alpha -= particleFadeoutSpeed; if(tempParticle.hitTestObject(thing2)) { destroyParticle(tempParticle); } else if (tempParticle.alpha <= 0) { destroyParticle(tempParticle); } else if (tempParticle.x < 0) { destroyParticle(tempParticle); } else if (tempParticle.x > stage.stageWidth) { destroyParticle(tempParticle); } else if (tempParticle.y < 0) { destroyParticle(tempParticle); } else if (tempParticle.y > stage.stageHeight) { destroyParticle(tempParticle); } } } private function destroyParticle(particle:MovieClip):void { for (var i = 0; i < particlesArray.length; i++) { var tempParticle:MovieClip = particlesArray[i]; if (tempParticle == particle) { particlesCurrent--; particlesArray.splice(i,1); removeChild(tempParticle); } } } private function onEnterFrameLoop(event:Event):void { createThing(thing1, thing2); updateParticle(); } } } |
Contact form
Last week I added a contact form to the site. Unfortunately it wasn’t working correctly due to wordpress (shame on me for not doing additional tests!). So, if you used the contact form in the last week, I did not get your request. Please resend.
OOP: XML Loader & Display Manager
Here is an OOP XML Loader & Display Manager class that can be used in your projects to load and display XML data.
The XML comes in the following form:
<?xml version="1.0" encoding="utf-8" ?> <data> <person name="Bob"></person> <person name="Jack"></person> <person name="Jill"></person> </data> |
Here is the SWF that loads it:
Class structure:

Player Movement with Velocity
Expending on the previous space shooter example, I’ve added velocity to player movement.
AS3 Basics - Naming Conventions
Use precise, meaningful, contextually relevant names that are as descriptive as possible. Limit the use of unnecessary abbreviations.
- Example: defaultImagePreview
NOT: dfltImgPrv
Start each instance name with a lowercase letter, and intercap the remaining words.
- Examples: menuItem, sectionTitle
Apply the same conventions to variable names.
- Examples: accountNumber, startingPoint, currentProductName
Begin a class name with an uppercase letter. Write class names in mixed case when it’s a compound or concatenated word. Keep package names as short as possible, using reverse domain naming conventions.
- Examples: com.client.project.component.ClassName
Name functions and methods in the form of verbs, since they perform actions.
- Examples: getUserName(), calculateTaxes(), createSubMenu()
Name booleans with an appropriate, positive prefix, such as “is”, “has”, “can”, or “should”, for an easier determination between true and false.
- Examples: isSoundOn, isFinished, isOpen, isLoggedIn, hasLicense, canEvaluate
Use complement names for complement entities: get/set, add/remove, create/destroy, start/stop, insert/delete, increment/decrement, old/new, begin/end, first/last, up/down, min/max, next/previous, open/close, show/hide.
- Examples: getUserName, setUserName
addThumbnailImage, removeThumbnailImage
showAnimation, hideAnimation
Private variable names may be prefixed with an underscore or $ symbol as long as consistency is maintained.
Center MovieClip based on browser size
Put the code below on the first frame of your flash movie. Add a movieclip to stage and give it the instance name “myMovie”. This AS3 code will dynamically center your movieclip based on browser size.
import flash.display.StageAlign; import flash.display.StageScaleMode; import flash.events.Event; function resizeHandler(e:Event):void { myMovie.x = (myMovie.stage.stageWidth / 2) - (myMovie.width / 2); myMovie.y = (myMovie.stage.stageHeight / 2) - (myMovie.height / 2); } stage.align = StageAlign.TOP_LEFT; stage.scaleMode = StageScaleMode.NO_SCALE; stage.addEventListener(Event.RESIZE, resizeHandler); stage.dispatchEvent(new Event(Event.RESIZE)); //the end |
CategoriesLinks |
