Welcome, Guest. Please login or register.
Did you miss your activation email?
05/21/12, 03:52
Home Help Search Login Register
News: Parsley Flex framework review featuring quiz application, in our Flex frameworks series
Flex SDK 4.5 mobile roadmap: begin with your mobile development
Swiz Flex framework review featuring quiz application
New homepage we release our new Homepage, take a look ...

+  Flash-db
|-+  General
| |-+  Flash 8 (Moderators: Jorge Solis, ..:: Mazhar Hasan ::.., Andresss)
| | |-+  moving an object as fast as possible to create alpha channel
0 Members and 1 Guest are viewing this topic. « previous next »
Pages: [1] 2 Print
Author Topic: moving an object as fast as possible to create alpha channel  (Read 6862 times)
Andresss
Moderator
Systems Administrator
*****
Posts: 738


check me out at www.asb-labs.com/blog


View Profile WWW Email
« on: 09/27/05, 10:01 »

does anyone know how to move an object at a fast speed this is something what i mean:

scan1 is a mc with _width=1 and _height=1

for (j=0; j<550; j++) {
   for(g=0; g<400; g++){
   scan1._x=j;
   scan1._y=g
   }
}
}
-----------------------------------------
and also i used the new cacheAsBitmap but flash is still too slow

for(j=0; j<550; j++) {
_root.createEmptyMovieClip("mc"+j, getNextHighestDepth());
eval("mc"+j).attachMovie("scan1", "scan1")
eval("mc"+j).cacheAsBitmap;
}


u may wonder... what is this for.. well i want a little mc (scan1) fills in every pixel of the stage as fast as possible....
« Last Edit: 10/13/05, 08:55 by Andresss » Logged

halemos de flash en espaņol!....wondering about crazy flash experiments?
papachan
Systems Administrator
*****
Posts: 507


View Profile WWW
« Reply #1 on: 09/27/05, 12:42 »

hey andress, if you find this. i am interested !
Logged

Jorge Solis
Administrator
Systems Administrator
*****
Posts: 14600


View Profile
« Reply #2 on: 09/27/05, 13:43 »

The cache feature allows to convert a MC to a bitmap and move whitout loss of performance, not exactly what you're trying. You need to use the BitmapData class and setPixel method. This way you have a more advanced control, including filters, copy, etc. You can check something about the BitmapData class in http://www.flash-db.com/Tutorials/snapshot/

Jorge
Logged

Andresss
Moderator
Systems Administrator
*****
Posts: 738


check me out at www.asb-labs.com/blog


View Profile WWW Email
« Reply #3 on: 09/27/05, 21:29 »

nop... it seems that the task im trying to perform is not supported yet... it is toooo slow to get a simple square check this code if u wanna try:

import flash.display.BitmapData;
var pix:BitmapData=new BitmapData(1,1, false, 0x000000);
for(i=0; i<16; i++){
   for(u=0; u<12; u++){
this.createEmptyMovieClip("mc"+i, this.getNextHighestDepth());
this["mc"+i].attachBitmap(pix, this.getNextHighestDepth());
//this["mc"+i].cacheAsBitmap;
this["mc"+i]._x=i;
this["mc"+i]._y=u
   }
}
Logged

halemos de flash en espaņol!....wondering about crazy flash experiments?
Jorge Solis
Administrator
Systems Administrator
*****
Posts: 14600


View Profile
« Reply #4 on: 09/28/05, 02:51 »

Create 192 objects? Why?. Not sure your goal, but here's a routine to fill a square using setPixel:

import flash.display.BitmapData;
var 
pix:BitmapData = new BitmapData(100,100false0xFF0000);
this.createEmptyMovieClip("holder"1)
holder._x 100holder._y=100
holder
.attachBitmap(pix1)
i=0u=0;
setInterval(function(t){
	
t.pix.setPixel(t.it.u++, 0x000000)
	
t.pix.setPixel(t.i+1t.u++, 0x000000)
	
if(
t.u==100){
	
	
t.i+=2t.u=0;
	
}
	
if(
t.i==100clearInterval(t)
}, 
10this)

Jorge
Logged

Andresss
Moderator
Systems Administrator
*****
Posts: 738


check me out at www.asb-labs.com/blog


View Profile WWW Email
« Reply #5 on: 09/28/05, 16:36 »

kinda crazy isnt it? imagine the first time i did it, i tried with 100 by 80 that is the same that 8000 squares! the computer was like crazy and many times prompt to abort the script..
why is it? i want to take control of every pixel on the stage, i mean i wanna know which color is in certain pixel, according of what i read if i use a statement named getColorBoundsRect() it does what i want but..yep there is the but it only returns the last pixel that contains certain color so  i dont know how to get all the pixels data so far
Logged

halemos de flash en espaņol!....wondering about crazy flash experiments?
Jorge Solis
Administrator
Systems Administrator
*****
Posts: 14600


View Profile
« Reply #6 on: 09/29/05, 02:39 »

If you read the snapshot tutorial, you will find the getPixel method of BitmapData class. The trick is to copy any MC content trough BitmapData.draw method

Jorge
Logged

Andresss
Moderator
Systems Administrator
*****
Posts: 738


check me out at www.asb-labs.com/blog


View Profile WWW Email
« Reply #7 on: 09/29/05, 10:21 »

yeah i read it boss... but it is still too slow actually the movie doesnt load using a statement like this:

function pipi(){
mybd=new BitmapData(mymc._width, mymc._height)
mybd.draw(mymc)
for(i=0; i<200;i++){
for(p=0; p<200;p++){
pixi=mybd.getPixel(i,p)
if(pixi==0124578){
trace("ok!")
}
}
}
setInterval(pipi, 50)


although when i tested the code u suggested to me it was cool! but it is too slow to fill all the squares even if i switch the frame speed to 120... i'll try to modify it to see what happens
Logged

halemos de flash en espaņol!....wondering about crazy flash experiments?
Mattias Robo
Mods
Systems Administrator
*****
Posts: 555



View Profile WWW
« Reply #8 on: 10/01/05, 10:15 »

Sorry to interrupt here, but aren't you missing something Andresss?

Jorge has with one single post explained how you should go about this. setInterval is not dependent of framerate. It doesn't get faster than that. In that case you would have to prepare the animation.

In your last example you have used setInterval to every 50 milliseconds run 200 x 200 getPixel functions!!? That's 40.000! Man, this is not NASA.. it's Flash. Started out as a simple web browser plug-in.

I don't really now what you're up to, but I think you maybe need to re-think.

regards :: robo
Logged

     "I've figured it out. It's not the fords... it's what's IN them!.."
Andresss
Moderator
Systems Administrator
*****
Posts: 738


check me out at www.asb-labs.com/blog


View Profile WWW Email
« Reply #9 on: 10/01/05, 19:36 »

well what i really want to do is to setPixels according to specific colors, like for example black pixels to white ones and so on... so my first idea was to create a little square scanner that goes through the movieclip i want to filter so this scanner must have gone very fast to set every pixel where it must be at, now the question is why that fast, because if i want to use my camera the scanner must have almost or the same frame rate that the camera or a video has so the colors would be "filter".... it was not a good idea ofcourse i couldnt have the "filter" on time beacause the scanner was too slow... my second idea came when i thought in setting pixels via AS at the beggining it seemed it was gonna work but it was such a difficult task for flash due to i had to set a pixel for each mc's pixel and at the same time test it every 100 miliseconds to know if the pixel contained the color i was looking for...it was also a bad idea because i never had it working, actually flash prompted many times to abort the script... so i decided to look up a statement that changes the color values if that color fits in a range, i found this:

getColorBoundsRect()--->looks for a certain rectangle returns x, y, width and height
floodFill()---> fills a rectangle with a color
threshold()--> it is supposed to do what i want "Tests pixel values in an image against a specified threshold and sets pixels that pass the test to new color values."

i havent found the solution to my project but i keep working in this crazy idea...

Quote
you should go about this. setInterval is not dependent of framerate
well u should try it out Mattias
« Last Edit: 10/01/05, 19:42 by Andresss » Logged

halemos de flash en espaņol!....wondering about crazy flash experiments?
Mattias Robo
Mods
Systems Administrator
*****
Posts: 555



View Profile WWW
« Reply #10 on: 10/02/05, 04:41 »

Quote
you should go about this. setInterval is not dependent of framerate
well u should try it out Mattias

Well..  Andressss. Believe me I have.

With "not dependent" I mean that the setInterval doesn't "follow" frame rate, as you might think. The higher frame rate doesn't necessarily mean faster setInterval.
However, setInterval is affected by frame rate. Ie, it behaves slightly different depending of the frame rate.

Try this code:
Code:
timerFunc = function () {
var newTimer:Number = getTimer();
var val = newTimer-oldTimer;
trace(val);
timerList.push(val);
oldTimer = newTimer;
};
onMouseDown = function () {
trace("#### STAR TIMER")
timerList = [];
timer = setInterval(timerFunc, 10);
};
onMouseUp = function () {
clearInterval(timer);
//
timerList.shift();
var count = 0;
for (i in timerList) {
count += timerList[i];
}
count /= timerList.length;
trace("\rAverage: "+count);
trace("#### END TIMER\r")
};

Try different frame rates and see what happens. Framerates below 10 have problems.
As you probably will notice the timer tend to be more stable at frame rates that is fairly even to the interval value.
In this example 10 performs better than 25.. AND 120 wich is just as bad as 12.
100 is slightly better than 10 though, but you wouldn't really notice the difference in a code.
The most stable timer in this example is about 60. Wich is kind of interesting.
You can try with different intervals as well.

If you have a slow computer you might not get the same results.

:: robot
Logged

     "I've figured it out. It's not the fords... it's what's IN them!.."
..:: Mazhar Hasan ::..
Moderator
Systems Administrator
*****
Posts: 828


Cheers


View Profile WWW
« Reply #11 on: 10/02/05, 16:26 »

if you just want to invert the colors of a MC, then why dont you use the blending options of movieclip, you can use invert, subtract or hardlight for +- purposes
Logged

Your wish is my command
Andresss
Moderator
Systems Administrator
*****
Posts: 738


check me out at www.asb-labs.com/blog


View Profile WWW Email
« Reply #12 on: 10/03/05, 07:57 »

ok i'll test them...
Logged

halemos de flash en espaņol!....wondering about crazy flash experiments?
Andresss
Moderator
Systems Administrator
*****
Posts: 738


check me out at www.asb-labs.com/blog


View Profile WWW Email
« Reply #13 on: 10/04/05, 16:23 »

im a little sad... what i wanted to do is "flv with alpha channel" thats the way macromedia call it... but it just filters flv files with the alpha channel... im not sure yet if u can have ur web camera and at the same time filters in runtime... i give u a link with a sample http://www.macromedia.com/support/documentation/en/flash/
Logged

halemos de flash en espaņol!....wondering about crazy flash experiments?
Andresss
Moderator
Systems Administrator
*****
Posts: 738


check me out at www.asb-labs.com/blog


View Profile WWW Email
« Reply #14 on: 10/13/05, 08:54 »

and... i give u a link on how to cretae true alpha channel in flv's, its alsoa a tutorial http://www.macromedia.com/devnet/flash/articles/alpha_video.html
Logged

halemos de flash en espaņol!....wondering about crazy flash experiments?
Pages: [1] 2 Print 
« previous next »
Jump to:  


Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!
anything