Archive for the ‘ Actionscript ’ Category

bring to highest depth in as3 – set highest depth

hi friends,

as3 is completely different from as2 in depth management,

So if you try with as2 code or ideas, it gives the negative result only.

here i have given you the code to bring a Movieclip or other displayObject to top of the neighbour objects in the same parent.

Mc.parent.setChildIndex(Mc, Mc.parent.numChildren-1);

its the simple one.

focus to input textField in as3, Move you cursor to..

hi friends,

Here I have given you the simple way to make your cursor focus to a particular textField,

yourTextField.type="input";
yourTextField.stage.focus = yourTextField;
ourTextField.setSelection(yourTextField.length,yourTextField.length);
yourTextField.text = "";

If you find this in your own flash software, its not given the result,. But no worries about, It works perfectly on the standalone and browsers.

call stage or root from class in as3

hi friends,

I have given you the method to call stage from inside class,

It’ll help to you get stage properties and call a function which is in stage .

import flash.display.*;
var _timeline:DisplayObjectContainer=null;

_timeline=getMainTimeline(this);

trace(_timeline)

public static function getMainTimeline(d:DisplayObject):DisplayObjectContainer {
var p:DisplayObjectContainer;

if (d.parent!=null) {
p=d.parent;
} else {
p=DisplayObjectContainer(d);
}

if (p.parent!=null) {
p=getMainTimeline(p.parent);
}
return p;
}

Random Array in as3

hi guys here I have given you the function to make an array random….

function randomArray(Arr:Array):Array {
var dummy:Array=new Array();
var dummy2:Array=new Array();
for (var i=0; i<Arr.length; i++) {
var d:int=Math.round(Math.random()*(Arr.length-1));
while  (dummy.indexOf(d)!=-1) {
d=Math.round(Math.random()*(Arr.length-1));
}
dummy.push(d);
}
for (var j=0; j<dummy.length; j++) {
dummy2.push(Arr[dummy[j]]);
}
return dummy2;
}

var  Arr:Array=new Array("1","2","3","4","5","6","7","8");
trace(randomArray(Arr));

Is there any simple idea, please given that is appreciated…

Basic Timer in AS3

Flash's Timer Class requires two parameters.
The first is the delay (in  milliseconds), 
the second is the amount of times you want the delay to  fire.
import flash.events.*;
flash.utils.Timer;

var myTimer:Timer=new Timer(1000,1);
myTimer.addEventListener(TimerEvent.TIMER_COMPLETE, timerHandler);
myTimer.start();

function timerHandler(evt:TimerEvent):void {
objectMC.x=200;
objectMC.y=200;
}

To create a loop using timer..

var myTimer:Timer=new Timer(1000,5);
myTimer.addEventListener(TimerEvent.TIMER_COMPLETE, timerHandler);
myTimer.start();

function timerHandler(evt:TimerEvent):void {
objectMC.x+=20;
objectMC.y+=20;

}
var myTimer:Timer=new Timer(1000,1);
myTimer.addEventListener(TimerEvent.TIMER_COMPLETE, timerHandler);
myTimer.start();

function timerHandler(evt:TimerEvent):void {
objectMC.x+=20;
objectMC.y+=20;

<pre>
<pre>
myTimer.start();</pre>
</pre>
}

Flash BitmapExporter: Compress and Save Images

Here is a demo for something that I hope may prove useful for some people. I have written a BitmapExporter class which allows to save PNGs or JPEGs out of swf files. There have been some Flash 8 demos already that show this possibility, so the novelty factors of my class are that the images get compressed before they are sent to the server and that Flash remoting is used to transfer the data. On the server side I’m running this with AMFPHP (I have exchanged that for a regular PHP script which works with loadVars and POST requests) in conjunction GD (which comes usually pre-installed with PHP) to recreate the images.

The demo allows you to doodle some drawings and to save them to your hard drive as a JPEG. Because of its security sandbox Flash cannot access your harddrive directly. It first has to send the image data to the server and then commence a download from there. We are so used to the small filesizes of JPEGs or PNG that it’s quite surprising to see what size an uncompressed image really has. The canvas in this demo for example has a dimension of 500×425 pixels. That’s 212500 pixel x 4 bytes per pixel = 850000 Bytes or about 830K.

The challenge is to create a compression algorithm in ActionScript which will process the image data with reasonable speed without overexerting Flash. I didn’t want to start studying the JPEG or PNG format specifications, so I rolled my own method. It uses an indexed color palette (but without reducing the amount of colors) and a run-length encoded table of the offsets of the colorindices of the consecutive pixels (wow, that sounds complicated). In reality that means that it will compress noisy images not so good as graphics. Therefore I have built in an optional method to reduce the bit-depths of images which does improve the compression ratio for photos and webcam shots.

The image is not necessarily processed in one block – the blocksize can be varied based on package size as well as processing time. Doing this the Flash plugin remains responsive and on top of that it allows for a bit “parallel processing”: whilst the server is receiving data and creating the first part of the image (which takes the longest time in the process), the swf file is already compressing the next data block. Now isn’t that clever?

So here comes the demo. You can vary the brush’s start and end size by using the arrow keys on your keyboard. Clicking in the palette will change the brush color. And one more thing: please be kind with my traffic bill – this is a functional demo, please don’t use it to save hundreds of images. Even though the images do get compressed it still uses up quite some bandwidth if thousands of people do this.

Source file here

[Update:] Here’s the link to the source code: http://www.quasimondo.com/scrapyard/BitmapExporter_v22.zip

Thanks Quasimondo to share his stuff…

More details about him http://www.quasimondo.com/