var i:uint;
for( i=arr.length-1; i>=0; i-- )
{
}
The mistake was simple, I had set i as a uint, so it could never go below 0, so just had to make i an int. It sounds stupid once you realize it, but it wasted enough of my time!
package
{
import flash.utils.getDefinitionByName;
import flash.utils.getQualifiedClassName;
public class AbstractExample
{
public function AbstractExample()
{
if( Class( getDefinitionByName( getQualifiedClassName( this ) ) ) == AbstractExample ) throw new Error( 'AbstractExample must be extended' );
// rest of constructor here...
}
}
}
package
{
public class Singleton
{
public static var instance:Singleton;
public static function getInstance():Singleton
{
if( instance == null ) instance = new Singleton( getInstance );
return instance;
}
public function Singleton( caller:Function )
{
if( caller == Singleton.getInstance )
{
// instantiate class here
}
else
{
throw new Error( 'Singleton is a singleton, use getInstance();' );
}
}
}
}
It's pretty simple, you can't call new Singleton() because the compiler will be expecting an argument, and if you do pass an argument, it will throw an Error because the caller is not the Singleton.getInstance method.
Singleton.getInstance();
Have a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.
Comments (0)