Posts tagged with “actionscript”

a warning would be nice

    import flash.display.Sprite;

    public class Foo extends Sprite {
        public var bar:Object;

        public function Foo() {
            bar = 5;

        public function baz():void {
            var bar:String = "not 5";


What do you think the output is? "not 5", as would be expected. But if you are stupid enough to do something like this (I was, after some refactoring), I would expect the compiler to at least throw a warning. Nope!

Also this is interesting:

public function baz2():void {
    bar = 2;
    var bar:String = "not 2";

does in fact throw this warning:

/Users/greay/projs/Test/ col: 10 Error: Implicit coercion of a value of type int to an unrelated type String.


The FlexEvent.CREATION_COMPLETE constant defines the value of the type property of the event object for a creationComplete event.


another AS3 annoyance

XMLLists. What the fuck: from the documentation,

The XMLList class contains methods for working with one or more XML elements. An XMLList object can represent one or more XML objects or elements (including multiple nodes or attributes), so you can call methods on the elements as a group or on the individual elements in the collection.

If an XMLList object has only one XML element, you can use the XML class methods on the XMLList object directly. In the following example, example.two is an XMLList object of length 1, so you can call any XML method on it.

Which is great, if I don't care about properly typing my variables.

TypeError: Error #1034: Type Coercion failed: cannot convert XMLList@1f51a779 to XML.

And of course there's no builtin way to convert a length-of-one XMLList into a normal XML object. Have to resort to the ugly (but simple)

var xml:XML = new XML(bullshitXMLList.toXMLString());

And really. Why wouldn't XMLList inherit from XML? Seriously?

Fuck AS3.

It supports associative arrays, which is great, but they're broken: the length of an associative array is 0. This is because, as far as I can see, length is just a normal property that's updated when you call foo[n]. But it's just fucking ignored if you call foo[string].

Hell, the documentation even says as much, but seriously?

There is no advantage in using the Array constructor to create an associative array. You cannot use the Array.length property or any of the methods of the Array class with associative arrays, even if you use the Array constructor or the Array data type. The use of the Array constructor is best left for the creation of indexed arrays.

Why even write that? As soon as the words hit the screen, you'd think someone would say, "this is bullshit. what the fuck were we thinking?" and file a bug. There's even a stack overflow thread on how to find the length of an associative array. How is this not built in?