Random Stuff :: shuffling array in actionscript 3
Posted by irevolBlogs in Other on January 29, 2010
Hello everyone.
i am writing this post because i found it very useful and necessary must have function/method for every ActionScript developer, just want to show you how to shuffle an sorted array…
Shuffling an Array in ActionScript3
// Lets make a Array first and fill with some Integers var myArray:Array = new Array(); for (var i:int = 0; i <10; i++) { myArray[i] = i; } //Tracing output trace("My sorted Array: " + myArray); var s:Array = shuffle(myArray); trace("Unsorted array: " + s); // Logics for Shuffle function shuffle(arr:Array):Array { var sArray:Array = new Array(); var j:int = 0; while (myArray.length > 0) { var r:int = Math.floor(Math.random()*myArray.length); sArray[j] = myArray[r]; j+=1; myArray.splice(r,1); } //finally return shuffle array. return sArray; }
that’s all folks.
Google Weather API and Flash – Part 2
Posted by irevolBlogs in ActionScript3, Other, Tutorial, flash on July 3, 2009
This is multipart tutorial, and this is second part of this tutorial. part 1 of this tutorial is here.
Lets move ahead and try to call google weather API. for this lets first make result component(Text Area) to read-only, because we just wanted to display XML result from google weather API in result Field. here is the code.
package { //Because Label are Components we must call him. import fl.controls.Button; import fl.controls.Label; import fl.controls.TextArea; import fl.controls.TextInput; import flash.display.MovieClip; public class mainClass extends MovieClip { private var labelComponent:Label; private var cityInputComponent:TextInput; private var goButton:Button; private var result:TextArea; public function mainClass() { //calling componentSetup() function in Constructor Function. componentSetup(); } private function componentSetup():void { //placing components in Stage remember to import fl.controls.Label for Label Control // First of all lets place Label and move it x=20 and y=20 px in stage labelComponent = new Label(); labelComponent.text = "City Name"; labelComponent.move(20, 20); addChild(labelComponent); //Now add TextInput component Remember to Import fl.controls.TextInput cityInputComponent = new TextInput(); cityInputComponent.move(100, 20); cityInputComponent.width = 200; addChild(cityInputComponent); //Adding Button Control. Remember to import fl.controls.Button; goButton = new Button(); goButton.move(320, 20); goButton.label = "Show Weather"; addChild(goButton); // Now time to add TextArea Component..Remember to import fl.controls.TextArea for TextArea Component result = new TextArea(); result.width = 400; result.height = 200; result.move(20, 50); // lets make result field READ-ONLY result.editable = false; addChild(result); } } }
line 43 - makes result field read only.
Twitter Weekly Updates for 2009-06-28
Posted by irevolBlogs in ActionScript3 on June 28, 2009
- Published a new blog post: Some Good blog on Flash Game Development. http://bit.ly/gKdEb #
- Published a new blog post: Why you must switch into AS3 from AS2? http://bit.ly/L8hOb #
- Published a new blog post: Best ActionScript Editing Software http://bit.ly/WGGuV #
- Published a new blog post: Dynamic MovieClip and Collision in ActionScript3 http://bit.ly/1359zB #
- Published a new blog post: A Basic tutorial to KeyPress in ActionScript3 http://bit.ly/1Cn4yy #
- Fiddling with my blog post: Custom Mouse Pointer in Flash http://bit.ly/XYIkE #
- Fiddling with my blog post: Basic tutorial to keyPress in ActionScript3 –Updated http://bit.ly/10SsIR #
- Published a new blog post: Back in Action http://bit.ly/OAsqS #
Flash game tutorial- Bubble shooter- part 1
Posted by irevolBlogs in ActionScript3, Tutorial on June 24, 2009
In this tutorial we will learn how to create a balloon shooter like game, so i just changed name to Bubble Shooter. this is very basic tutorial particularly helpful if you are moving from ActionScript2 to ActionScript3.
During this tutorial we learn how to organize classes in ActionScript3, how to overcome problem step-by-step and how ActionScript3 makes Flash Game development very easy. Also we will cover the best practices like-
- Just one frame in source .fla file
- No ActionScript in Source and/or MovieClips.
- Organizing multiple .as files
- Organizing multiple Classes.
Actually this is quite long tutorial so i decided to break it into multiple part. this is the first part of Bubble Shooter Game.
I am using Adobe Flash to create graphics and FlashDevelop to edit ActionScript Because I find FlashDevelop more convenient then any other ActionScript editing software. if you don’t know more about FlashDevelop than read this article to know more about FlashDevelop. however if you do not prefer FlashDevelop fell free to use any actionscript editing tool.
Lets start tutorial by setting up games.
Recent Comments