[Flashcoders] bitwise question

2009-09-15 Thread Jiri
When i have a 8 bit int where only one of the bit can be 1, what is then 
the quickest way to get that bit position with value 1?

Now I use this.

function getBit():int{
var tCount:int = 0;
for (var i:int=0; i  8; i++) {
  if (8  (1  i))   return i;
}
return 0;
}
Can this be done faster?

Jiri
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] bitwise question

2009-09-15 Thread Hans Wichman
Hey,
not sure if it's faster, but this would work as well:
var i:Number = 32;
trace (Math.log(i)/Math.LN2);
returns bit number 5.
Lookuptable might be faster in this case.

greetz
JC



On Tue, Sep 15, 2009 at 10:04 AM, Jiri jiriheitla...@googlemail.com wrote:

 When i have a 8 bit int where only one of the bit can be 1, what is then
 the quickest way to get that bit position with value 1?
 Now I use this.

 function getBit():int{
var tCount:int = 0;
for (var i:int=0; i  8; i++) {
  if (8  (1  i)) return i;
}
return 0;
}
 Can this be done faster?

 Jiri
 ___
 Flashcoders mailing list
 Flashcoders@chattyfig.figleaf.com
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] bitwise question

2009-09-15 Thread Paul Andrews

Jiri wrote:
When i have a 8 bit int where only one of the bit can be 1, what is 
then the quickest way to get that bit position with value 1?

Now I use this.

function getBit():int{
var tCount:int = 0;
for (var i:int=0; i  8; i++) {
  if (8  (1  i))return i;
}
return 0;
}
Can this be done faster?

Yes. Use a lookup table;

var lookup:Array=[];
for (var n:int=0; n128;n++)
{
   lookup.push(0);
}
lookup[2]=1;
lookup[4]=2;
lookup[8]=4;
//etc..

function getBit(n:int):int{
   return lookup[n];
}

Paul
  






Jiri
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders



___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] bitwise question

2009-09-15 Thread Paul Andrews

Paul Andrews wrote:

Jiri wrote:
When i have a 8 bit int where only one of the bit can be 1, what is 
then the quickest way to get that bit position with value 1?

Now I use this.

function getBit():int{
var tCount:int = 0;
for (var i:int=0; i  8; i++) {
  if (8  (1  i))return i;
}
return 0;
}
Can this be done faster?

Yes. Use a lookup table;

var lookup:Array=[];
for (var n:int=0; n128;n++)
{
   lookup.push(0);
}
lookup[2]=1;
lookup[4]=2;
lookup[8]=4;
//etc..

function getBit(n:int):int{
   return lookup[n];
}

LOL, better still, just ditch the function altogether and use 
lookup[somevariable] directly.


I might as well comment that this is lean and mean without any safety 
net to make sure the int is in range and indeed has only one bit set.

Paul
 





Jiri
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders



___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders



___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] closures

2009-09-15 Thread Steven Sacks

AS3 is based entirely on closures. Not sure what you mean by it being an option.

Anthony Pace wrote:
I was wondering if anyone here uses closures in AS3? I like them a ton; 
yet, I am wondering if they are ever used in a real world development 
projects in AS3?


Can you see an excuse for using them?  I know it does make somethings 
easier to port to and from JS if coded right.

___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] bitwise question

2009-09-15 Thread Jiri
Thnx, i tought that there would be some kind of smart bitwise operation 
to do that. This will do fine. Cheers.


Jiri

Paul Andrews wrote:

Paul Andrews wrote:

Jiri wrote:
When i have a 8 bit int where only one of the bit can be 1, what is 
then the quickest way to get that bit position with value 1?

Now I use this.

function getBit():int{
var tCount:int = 0;
for (var i:int=0; i  8; i++) {
  if (8  (1  i))return i;
}
return 0;
}
Can this be done faster?

Yes. Use a lookup table;

var lookup:Array=[];
for (var n:int=0; n128;n++)
{
   lookup.push(0);
}
lookup[2]=1;
lookup[4]=2;
lookup[8]=4;
//etc..

function getBit(n:int):int{
   return lookup[n];
}

LOL, better still, just ditch the function altogether and use 
lookup[somevariable] directly.


I might as well comment that this is lean and mean without any safety 
net to make sure the int is in range and indeed has only one bit set.

Paul




Jiri
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders



___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders



___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] bitwise question

2009-09-15 Thread Juan Pablo Califano
Another option:

function test(value:int):int {
 // just to be safe...
 value = value  0xff;
 switch(value) {
  case 0x01:  return 0;
  case 0x02:  return 1;
  case 0x04:  return 2;
  case 0x08:  return 3;
  case 0x10:  return 4;
  case 0x20:  return 5;
  case 0x40:  return 6;
  case 0x80:  return 7;
  default:  return -1;
 }
}

Cheers
Juan Pablo Califano
2009/9/15 Paul Andrews p...@ipauland.com

 Paul Andrews wrote:

 Jiri wrote:

 When i have a 8 bit int where only one of the bit can be 1, what is then
 the quickest way to get that bit position with value 1?
 Now I use this.

 function getBit():int{
var tCount:int = 0;
for (var i:int=0; i  8; i++) {
  if (8  (1  i))return i;
}
return 0;
}
 Can this be done faster?

 Yes. Use a lookup table;

 var lookup:Array=[];
 for (var n:int=0; n128;n++)
 {
   lookup.push(0);
 }
 lookup[2]=1;
 lookup[4]=2;
 lookup[8]=4;
 //etc..

 function getBit(n:int):int{
   return lookup[n];
 }

 LOL, better still, just ditch the function altogether and use
 lookup[somevariable] directly.

 I might as well comment that this is lean and mean without any safety net
 to make sure the int is in range and indeed has only one bit set.

 Paul



 Jiri
 ___
 Flashcoders mailing list
 Flashcoders@chattyfig.figleaf.com
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


 ___
 Flashcoders mailing list
 Flashcoders@chattyfig.figleaf.com
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


 ___
 Flashcoders mailing list
 Flashcoders@chattyfig.figleaf.com
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] bitwise question

2009-09-15 Thread Paul Andrews

Juan Pablo Califano wrote:

Another option:

function test(value:int):int {
 // just to be safe...
 value = value  0xff;
 switch(value) {
  case 0x01:  return 0;
  case 0x02:  return 1;
  case 0x04:  return 2;
  case 0x08:  return 3;
  case 0x10:  return 4;
  case 0x20:  return 5;
  case 0x40:  return 6;
  case 0x80:  return 7;
  default:  return -1;
 }
}

Cheers
Juan Pablo Califano
  

Yes, this is the best way to do it.

Paul
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] PHP Socket Question

2009-09-15 Thread mike donnelly
Er, doesn't Flash Media Server do exactly what you want to do? I recommend
Influxis hosting, pretty cheap FMS hosting and they're super developer
friendly.

You have to learn a bit of arcane server-side actionscript. It's
actionscript 1, yurrk, with a weird API for manipulating sockets and server
stuff, but it's fine once you get your head around it.

hah just realised this was posted months ago. how helpful of me!

2009/7/22 John McCormack j...@easypeasy.co.uk

  http://www.tufat.com/s_flash_chat_chatroom.htm

 Thanks for that Glen,
 That looks really interesting.

 John


 Glen Pike wrote:

 You can use a database to store data in for a chat server, but you will
 need to have some kind of server side maintenance script to weed out the
 database.

 With a socket server system, you usually have to have a dedicated server,
 or at least one which lets you log into the shell and create scripts - most
 hosting does not let you run stuff like socket servers easily - which is why
 the database version may be used, because most hosting comes with this as
 standard.
 To test if your system could use a socket server, grab a free script and
 try exec()'ing it from a webserver PHP script to see if you could
 theoretically start and stop your server.  I would guess most hosting locks
 this down and it may violate your TOS.

 Alternatively, look at hosted systems - Electrotank used to do a socket
 server and possibly provide hosting for that, it's in Java, but you would
 not have to write all that stuff...  Also look at Moock's Multi-user Unity
 system - can't remember if that's useful or not.

 There is a program called Flash Chat for $5 which is probably worth
 looking at - http://www.tufat.com/s_flash_chat_chatroom.htm - there used
 to be a version called AMFIChat, but it has been discontinued (possibly
 because the guy was violating the terms of the AMF license)

 Anyway, in terms of time vs money $5 to spend looking at someone elses
 ready made system could be very cheap and you can see what server side stuff
 it does too.

 Omar Fouad wrote:

 hey,
 My boss asked me to develop a Cards Game called Estimation (I don't
 know
 if you heard about it). It is a Cards game similar to spades, where there
 are tricks, bids, etc.
 The game is going to be a Facebook application, so it is required a
 multi-player option (real time).
 At first I thought I would create a database and continuously let the
 client
 send queries using AMF, to check for changes and update the display. But
 a
 friend of mine told me this is insane. The data on the database he would
 buge, and I have to take in mind, that anyone could leave the game at
 anytime, so the data will remain in the database uselessly. He told me to
 use sockets, and store the variables I need, such as the rooms, the
 player
 nickname, the bids, the calls, the tricks, the scores, the rounds, the
 hands, and all the crap that I would need in the server side script
 (PHP).
 Is this true? If I will have to use sockets, should I store the data as
 variables in the server side script?

 I really need to figure out how to start. Thanks.




 ___
 Flashcoders mailing list
 Flashcoders@chattyfig.figleaf.com
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders




 ___
 Flashcoders mailing list
 Flashcoders@chattyfig.figleaf.com
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] bitwise question

2009-09-15 Thread John McCormack

Jiri,

I haven't done much bit twiddling yet in AS3 but I think you were fast 
already, but your i was being incremented and shifted.

Also i8 would only get you bits 2,1,0
In binary that would be i1000
How about:

function getBit(var numb:int):int {
 var bit:int=1;
 var count:int=0;

 if (numb==0 || numb0x80) return -1; // error

 while (bit  numb == 0) {
   1  bit;
   count++;
 }

 return count;
}

John

Jiri wrote:
When i have a 8 bit int where only one of the bit can be 1, what is 
then the quickest way to get that bit position with value 1?

Now I use this.

function getBit():int{
var tCount:int = 0;
for (var i:int=0; i  8; i++) {
  if (8  (1  i))return i;
}
return 0;
}
Can this be done faster?



___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] closures

2009-09-15 Thread Anthony Pace

JS style Function scope instead of classical oop.

Steven Sacks wrote:
AS3 is based entirely on closures. Not sure what you mean by it being 
an option.


Anthony Pace wrote:
I was wondering if anyone here uses closures in AS3? I like them a 
ton; yet, I am wondering if they are ever used in a real world 
development projects in AS3?


Can you see an excuse for using them?  I know it does make somethings 
easier to port to and from JS if coded right.

___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] bitwise question

2009-09-15 Thread Glen Pike

I think his i  8 was valid as the i is used for the shift, not the value...

The only thing that might be faster is using i-- rather than i++ - for 
some reason decrementing through a loop is suppsoed to be faster.


Glen :)

John McCormack wrote:

Jiri,

I haven't done much bit twiddling yet in AS3 but I think you were fast 
already, but your i was being incremented and shifted.

Also i8 would only get you bits 2,1,0
In binary that would be i1000
How about:

function getBit(var numb:int):int {
 var bit:int=1;
 var count:int=0;

 if (numb==0 || numb0x80) return -1; // error

 while (bit  numb == 0) {
   1  bit;
   count++;
 }

 return count;
}

John

Jiri wrote:
When i have a 8 bit int where only one of the bit can be 1, what is 
then the quickest way to get that bit position with value 1?

Now I use this.

function getBit():int{
var tCount:int = 0;
for (var i:int=0; i  8; i++) {
  if (8  (1  i))return i;
}
return 0;
}
Can this be done faster?



___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders




___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


[Flashcoders] RegExp vs. CDATA in E4X

2009-09-15 Thread Mendelsohn, Michael
Hi list...

I'm debating using a RegExp to search for a value in E4X, or do it by searching 
the below data within CDATA.  I think the RegEx would be cooler to use, making 
for a smaller XML file, but I wonder if it would be faster to simply loop 
through an array of these values.  Anyone have any thoughts?

I think this would work, but I don't think it's foolproof:
/A1E(3|4)\d[0-5]/i

thanks,
- Michael M.

A1E441
A1E440
A1E433
A1E432
A1E431
A1E430
A1E422
A1E421
A1E410
A1E390
A1E370
A1E350
A1E340
A1E320
A1E300
A1E413
A1E412
A1E411
A1E402
A1E401
A1E400
A1E394
A1E393
A1E392
A1E391
A1E384
A1E383
A1E382
A1E381
A1E374
A1E373
A1E372
A1E371
A1E364
A1E363
A1E362
A1E361
A1E355
A1E354
A1E353
A1E352
A1E351
A1E345
A1E344
A1E343
A1E342
A1E341
A1E333
A1E332
A1E331
A1E330
A1E324
A1E323
A1E322
A1E321
A1E344
A1E343
A1E342
A1E314
A1E313
A1E312
A1E311
A1E310
A1E305
A1E304
A1E303
A1E302
A1E301

___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] closures

2009-09-15 Thread Glen Pike

You mean like

button.onRelease = function() { trace(hello from  + this);

obviously not in AS3, you would have to write few more lines...

I guess it's okay as long as it works and does what you want along with 
the hope that you can easily fix it when it breaks in the latest browser 
6 months down the line :)


Questions  is/are:
Are you writing code you want to re-use?
Are you wanting to decouple stuff?
Are you wanting to make stuff easy to fix?
Are you just chucking something together?

There are loads of arguments for and against I guess, it's just what you 
are happy working with and what suits the job.


Glen



Anthony Pace wrote:

JS style Function scope instead of classical oop.

Steven Sacks wrote:
AS3 is based entirely on closures. Not sure what you mean by it being 
an option.


Anthony Pace wrote:
I was wondering if anyone here uses closures in AS3? I like them a 
ton; yet, I am wondering if they are ever used in a real world 
development projects in AS3?


Can you see an excuse for using them?  I know it does make 
somethings easier to port to and from JS if coded right.

___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders




___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] bitwise question

2009-09-15 Thread John McCormack

It's a little curious loop!

i=0
i shifted = 0

i++ gives = 1 binary  0001
i shifted   = 2 binary  0010

i++ gives i=3 binary  0011
i shifted=6 binary  0110

i++ gives i= 7 binary  0111
i shifted=14 binary  1110

End of loop because i=8

i++ gives i= 15 binary  
i shifted= 30 binary 0001 1110

John

Glen Pike wrote:
I think his i  8 was valid as the i is used for the shift, not the 
value...


The only thing that might be faster is using i-- rather than i++ - for 
some reason decrementing through a loop is suppsoed to be faster.


Glen :)

John McCormack wrote:

Jiri,

I haven't done much bit twiddling yet in AS3 but I think you were 
fast already, but your i was being incremented and shifted.

Also i8 would only get you bits 2,1,0
In binary that would be i1000
How about:

function getBit(var numb:int):int {
 var bit:int=1;
 var count:int=0;

 if (numb==0 || numb0x80) return -1; // error

 while (bit  numb == 0) {
   1  bit;
   count++;
 }

 return count;
}

John

Jiri wrote:
When i have a 8 bit int where only one of the bit can be 1, what is 
then the quickest way to get that bit position with value 1?

Now I use this.

function getBit():int{
var tCount:int = 0;
for (var i:int=0; i  8; i++) {
  if (8  (1  i))return i;
}
return 0;
}
Can this be done faster?



___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders




___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders





___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


RE: [Flashcoders] closures

2009-09-15 Thread Merrill, Jason
 JS style Function scope instead of classical oop.

 You mean like button.onRelease = function() { trace(hello from  +
this);

(I know that was said tongue in cheek, so this is not a criticism...)
that's going back to AS1/AS2 anonymous functions - why would anyone in
their right mind, unless they had to target earlier versions of
Actionscript, want to go back to that?


Jason Merrill 

Bank of  America   Global Learning 
Learning  Performance Soluions

Monthly meetings on making the most of the Adobe Flash Platform -
presented by bank associates, Adobe engineers, and outside experts in
the borader multimedia community - join the Bank of America Flash
Platform Community  (note: this is for Bank of America employees only)



___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] closures

2009-09-15 Thread Glen Pike

Hi,

   I was sort off slightly off the mark with my example, but having 
read up on function closures in AS3 I can sort of see what Anthony 
means...
  
   From what I gather, Function Closures in AS3 are any functions / 
methods, but people generally mean functions outside of classes when 
they talk about function closures, so my example was sort of there 
somehow..


   Anyway, you may need global functions and package functions - I 
guess these would be considered okay by most OOP people, whereas some 
people may shun timeline code, although you can use it in AS3 and you 
can do some very quick tests with it.


   Like I said before, it's down to choice and whether it suits your 
needs, so if you need to nest functions, or whatever, it might be easier 
and more efficient to do so, it might not - depends on your brief/spec I 
guess.


   Sometimes just writing functional code is really nice and 
therapeutic for me, but it never seems to scale very nicely beyond a 
certain point (probably because I have learned too much about classes 
and objects to go back).


   Glen

Merrill, Jason wrote:

JS style Function scope instead of classical oop.
  


  

You mean like button.onRelease = function() { trace(hello from  +
  

this);

(I know that was said tongue in cheek, so this is not a criticism...)
that's going back to AS1/AS2 anonymous functions - why would anyone in
their right mind, unless they had to target earlier versions of
Actionscript, want to go back to that?


Jason Merrill 

Bank of  America   Global Learning 
Learning  Performance Soluions


Monthly meetings on making the most of the Adobe Flash Platform -
presented by bank associates, Adobe engineers, and outside experts in
the borader multimedia community - join the Bank of America Flash
Platform Community  (note: this is for Bank of America employees only)



___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

  


--

Glen Pike
01326 218440
www.glenpike.co.uk http://www.glenpike.co.uk

___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] RegExp vs. CDATA in E4X

2009-09-15 Thread Steven Sacks

You, sir, are a victim of premature optimization.

Write it the easy way. If it proves to be a bottleneck later, optimize it then.
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


RE: [Flashcoders] RegExp vs. CDATA in E4X

2009-09-15 Thread Mendelsohn, Michael
Will do, sage advice.

- MM 



 Write it the easy way. If it proves to be a bottleneck later, optimize it 
 then.


___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] bitwise question

2009-09-15 Thread Jiri
Can't confirm your findings right now, and also wonder which loop you 
are talking about. My initially posted one?


 function getBit():int{
 var tCount:int = 0;
 for (var i:int=0; i  8; i++) {
   if (8  (1  i))return i;
 }
 return 0;
 }

or the one suggested by John McCormack. I cant remember have faulty 
result with my loop because like Glen Pike mentioned the i is used for 
the shifting.


Also the 8bit to test will always only have one bit set to 1. Which 
could be a potential dangerous assumption i guess.

 0001
 0010
 0100
etc..

Will do testing tomorrow.

jiri


John McCormack wrote:

It's a little curious loop!

i=0
i shifted = 0

i++ gives = 1 binary  0001
i shifted   = 2 binary  0010

i++ gives i=3 binary  0011
i shifted=6 binary  0110

i++ gives i= 7 binary  0111
i shifted=14 binary  1110

End of loop because i=8

i++ gives i= 15 binary  
i shifted= 30 binary 0001 1110

John

Glen Pike wrote:
I think his i  8 was valid as the i is used for the shift, not the 
value...


The only thing that might be faster is using i-- rather than i++ - for 
some reason decrementing through a loop is suppsoed to be faster.


Glen :)

John McCormack wrote:

Jiri,

I haven't done much bit twiddling yet in AS3 but I think you were 
fast already, but your i was being incremented and shifted.

Also i8 would only get you bits 2,1,0
In binary that would be i1000
How about:

function getBit(var numb:int):int {
 var bit:int=1;
 var count:int=0;

 if (numb==0 || numb0x80) return -1; // error

 while (bit  numb == 0) {
   1  bit;
   count++;
 }

 return count;
}

John

Jiri wrote:
When i have a 8 bit int where only one of the bit can be 1, what is 
then the quickest way to get that bit position with value 1?

Now I use this.

function getBit():int{
var tCount:int = 0;
for (var i:int=0; i  8; i++) {
  if (8  (1  i))return i;
}
return 0;
}
Can this be done faster?



___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders




___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders





___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] bitwise question

2009-09-15 Thread Jiri

Cheers.

Jiri

Paul Andrews wrote:

Juan Pablo Califano wrote:

Another option:

function test(value:int):int {
 // just to be safe...
 value = value  0xff;
 switch(value) {
  case 0x01:  return 0;
  case 0x02:  return 1;
  case 0x04:  return 2;
  case 0x08:  return 3;
  case 0x10:  return 4;
  case 0x20:  return 5;
  case 0x40:  return 6;
  case 0x80:  return 7;
  default:  return -1;
 }
}

Cheers
Juan Pablo Califano
  

Yes, this is the best way to do it.

Paul
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


[Flashcoders] help. mouseEvent doesn´t work o n SWF loaded with JavaScript.

2009-09-15 Thread Isaac Alves
solved !!
 xml problem...
thanks .
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


[Flashcoders] RE: Re: time based smooth animation w/ GTween. HELP! (Jack Doyle)

2009-09-15 Thread Isaac Alves
Hi Jack,

Thank you for the explanations. I've been gradually changing to
TweenLite  TweenMax, and so far I'm very happy with it, I've achieved
good results with the filter tween and color matrix.  yoyo's really
cool too.

About that other situation, I was trying to have a time-based tween
animation, in order to have a smoother animation . I guess I
misunderstood the renderTime method. I wanted the flash player to
render the tween each 10ms. (cause with a 30fps frame rate, it would
render each 33ms, right? ) just to see what happened... the default
timing mode is frame based, right ?

cheers!

Hey Isaac. What exactly are you trying to accomplish with the
renderTime(10)? Your example tween was only 1 second long, so where does the
10 come from? If you want to skip to a certain time in a TweenMax tween,
make sure you're using the latest v11 (http://blog.greensock.com/v11beta/)
and just set the currentTime property like myTween.currentTime = 10 would
make it go to the 10-second point. Or use the currentProgress property
(always between 0 and 1 where 0.5 is halfway finished) like
myTween.currentProgress = 0.5. Don’t use renderTime() - use the currentTime,
currentProgress, totalTime, or totalProgress getters/setters. The
convenience of these getters/setters is that they can easily be tweened for
advanced effects.

And there's an easier way to accomplish your repeatReverse() functionality.
Just use the yoyo and repeat features like:

var plantaTween:TweenMax = new TweenMax(planta, 1, {y:414, repeat:1,
yoyo:true, ease:Sine.easeInOut});

That'll repeat it once and since yoyo is true, it'll play forward the first
time through and backwards the second time through.

Full ASDoc documentation is at http://www.greensock.com/as/docs/tween/

Again, make sure you've got v11: http://blog.greensock.com/v11beta/. Feel
free to use the forums at http://forums.greensock.com for these types of
questions. I try to be pretty active in responding there.

Jack

PS For the record, TweenLite/Max does NOT use a Timer to drive updates. It's
ENTER_FRAME driven which is generally optimal for many reasons (I won't bore
you with an explanation here). You can have any tween base its timing on
frames instead of time if you prefer (new in v11) by setting useFrames:true.

___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders