Dynamic Flash

Confessions of a serial code abuser
  • rss
  • Home
  • MTASC
  • Archives
  • About me
  • Goodies
    • Base64 encoder/decoder class
  • My Bookshelf
  • My Talks

Boolean operators and getter functions

Friday, 08 April 2005

A while back I came across an obscure bug with the type checking in Macromedia's Actionscript compiler. It seems that the compiler calculates that the result of a boolean expression involving only getter functions is of type Function.

Take the following class:

PLAIN TEXT
Actionscript:
  1. class Test1 {   
  2.     // Field 1 getter
  3.     public function get field1():Boolean {
  4.         return true;
  5.     }
  6.    
  7.     // Field 2 getter
  8.     public function get field2():Boolean {
  9.         return false;
  10.     }
  11.    
  12.     // Constructor
  13.     public function Test() {
  14.         var test:Boolean = field1 || field2;
  15.         trace(test);
  16.     }
  17. }

If you try and compile this, you will get the following error:

**Error** [...] Test.as: Line 14: Type mismatch in assignment statement: found Function where Boolean is required.
var test:Boolean = field1 || field2;

This only seems to be a compile time checking issue. If you remove the data type from the test variable the code will compile fine, and the trace statement will output true as it should.

Changing line 14 to...

PLAIN TEXT
Actionscript:
  1. var test:Boolean = field1 == true || field2 == true;

...seems to fix the problem.

Categories
General
Comments rss
Comments rss
Trackback
Trackback

« Obligatory GMail invites post An Open Source Actionscript 2.0 component framework »

4 responses

Have you reported this bug to MM?

Paul Neave | Friday, 08 April 2005 | 1:45 pm

Have you reported this bug to MM?

I've run into a similar problem before, except I don't

Keith Wilcox | Friday, 08 April 2005 | 10:33 pm

I’ve run into a similar problem before, except I don’t remember it being related to Booleans. I seem to remember it involved the compiler flipping out about passing a getter into a function which wanted a string datatype.

Yeah, I think I've had that one too. It seems

Steve | Saturday, 09 April 2005 | 8:16 am

Yeah, I think I’ve had that one too. It seems that the type checking routines in the compiler doesn’t quite handle getters properly. It’s particularly annoying because once you get around the type checking, the code actually works just fine.

Would (field1 || field2) or ((field1) || (field2)) help solve

Tangent | Friday, 27 May 2005 | 1:28 am

Would (field1 || field2) or ((field1) || (field2)) help solve the issue?

Leave a comment

You can use these tags : <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

About Dynamic Flash

Steve Webster is a Senior Web Developer for Yahoo! in London, UK.

He is more than a little concerned that he defines himself in terms of his career, and that he talks about himself in the third person.

Find out more

Recent Posts

  • FotB ‘08 Schedule: iCal feeds
  • Read and write local files with Flash Player 10
  • The problem with SproutCore
  • Yahoo! London seeks Junior Developers
  • I am Singularity

Tags

Accessibility ActionScript actionscript3 actionscript 3.0 air apple astro book calendar conference designer filereference file upload Flash flex fotb08 framework ical internet internet explorer JavaScript jobs junior microsoft opportunities ria schedule singularity08 skin tutorial urlrequest web developer web development Web Standards Yahoo!

del.icio.us-ed

Stuff

Singularity?
Flex.org - The Directory for Flex
rss Comments rss valid xhtml 1.1 design by jide powered by Wordpress get firefox