as3编程 1、为什么类里面要加个动态标识符,2、TypeError: Error #1006: value 不是函数。
package{dynamicpublicclassSampleClass{publicvarsampleA:String="aproperty!";publicvars...
package
{
dynamic public class SampleClass
{
public var sampleA:String="a property!";
public var sampleB:String="b property!";
public function samepleAMethod():void{trace("method a!")};
public function samepleBMethod():void{trace("method b!")};
}
}
package
{
import flash.display.Sprite;
public class XueXi extends Sprite
{
public function XueXi()
{
var foo2:SampleClass=new SampleClass();
foo2['sample'+getLetter()+'Method'](); /*TypeError: Error #1006: value 不是函数。*/ }
private function getLetter():String
{var currentTime:Date=new Date();
if(currentTime.getMilliseconds()%2==1)
{ return'A';}
else {return 'B';}
}
}
} 展开
{
dynamic public class SampleClass
{
public var sampleA:String="a property!";
public var sampleB:String="b property!";
public function samepleAMethod():void{trace("method a!")};
public function samepleBMethod():void{trace("method b!")};
}
}
package
{
import flash.display.Sprite;
public class XueXi extends Sprite
{
public function XueXi()
{
var foo2:SampleClass=new SampleClass();
foo2['sample'+getLetter()+'Method'](); /*TypeError: Error #1006: value 不是函数。*/ }
private function getLetter():String
{var currentTime:Date=new Date();
if(currentTime.getMilliseconds()%2==1)
{ return'A';}
else {return 'B';}
}
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询