Previously valid static method references ignored by Flash 10.1 compiler
I have a program that I wrote in ActionScript 3 that I have been compiling without errors up through Flash CS4 (FP10). Now I'm trying to compile for Flash CS5 (FP 10.1?) and am getting crazy errors over what seems to be a mundane point. I wonder if someone could offer insight...
This blocker that I'm getting a 1061 compiler error (Call to a possibly undefined method parseBoolean through a reference with static type Class
) becaus开发者_C百科e it apparently can't read a public static method on a utility class that I wrote. Basic reference structure as follows:
Utility Class:
package com.lassie.utils
{
public final class XMLUtil
{
public static function parseBoolean($value:String, $defaultValue:Boolean=false):Boolean {
if ($value == null || $value == "") return $defaultValue;
return ($value == "1" || $value == "true");
}
}
}
Referencing Script:
import com.lassie.utils.XMLUtil;
function parseXML($xml:XML, $tween:PuppetTween):PuppetTween
{
$tween.followGrid = XMLUtil.parseBoolean( $xml.@followGrid, true );
$tween.animateMoves = XMLUtil.parseBoolean( $xml.@animateMoves, true );
$tween.confineToWalkarea = XMLUtil.parseBoolean( $xml.@confineToWalkarea, false );
return $tween;
}
For whatever reason, I'm getting hit with an error 1061: Call to a possibly undefined method parseBoolean through a reference with static type Class
for each reference to the static parseBoolean
helper method. It's like the compiler is completely blind to the fact that the method exists on the XMLUtil
class, despite it being declared as both public and static. Again, this did work in both Flash 9 and Flash 10 compilers. It's just CS5 that suddenly throws this issue.
Any ideas? Has anyone else had a similar migration issue? Thanks.
I've encountered this too and in my case it had nothing to do with the member being static, but somehow the compiler got confused because I had used an already existing class name (in a different package though!!!) The code compiled perfectly in CS4, but broke in CS5.
The solution was to use the fully qualified name:
import com.lassie.utils.XMLUtil;
function parseXML($xml:XML, $tween:PuppetTween):PuppetTween
{
$tween.followGrid = com.lassie.utils.XMLUtil.parseBoolean( $xml.@followGrid, true );
$tween.animateMoves = com.lassie.utils.XMLUtil.parseBoolean( $xml.@animateMoves, true );
$tween.confineToWalkarea = com.lassie.utils.XMLUtil.parseBoolean( $xml.@confineToWalkarea, false );
return $tween;
}
I never found out why this happened (and didn't take the time to search for it) Hope this helps
When you do this sort of thing you need to remember a Singleton still has one instance.
Here is a good link explaining it.
And more in-depth here.
Basically, what you are doing is calling a static function on a class not set up for Singleton use.
If you just want a helper class make your life easy and just make it a normal public class.
精彩评论