AS3.0编程报错:1061: 调用可能未定义的方法 ballMovie (通过 static 类型 ball 引用)。
我做了个按钮控制小球运动的例子,小球绑定类ball,代码如下:package{importflash.display.MovieClip;publicclassballe...
我做了个按钮控制小球运动的例子,小球绑定类ball,代码如下:
package
{
import flash.display.MovieClip;
public class ball extends MovieClip
{
public function ball()
{
function ballMovie(mydir:String)
{
var speed:uint = 2;
switch (mydir)
{
case "left" :
this.x -= speed;
break;
case "right" :
this.x += speed;
break;
case "up" :
this.y -= speed;
break;
case "down" :
this.y += speed;
break;
case "stop" :
break;
}
}
}
}
}
主时间轴第一帧写代码如下:
var myBall:ball=new ball();
myBall.x=myBall.y=100;
addChild(myBall);
var dir:String;
addEventListener(Event.ENTER_FRAME,hdMovie);
function hdMovie(e:Event){
myBall.ballMovie(dir)
}
bLeft.addEventListener(MouseEvent.MOUSE_DOWN,bLeftHd);
function bLeftHd(e:MouseEvent){
dir="left";
}
bRight.addEventListener(MouseEvent.MOUSE_DOWN,bRightHd);
function bRightHd(e:MouseEvent){
dir="right";
}
bUp.addEventListener(MouseEvent.MOUSE_DOWN,bUpHd);
function bUpHd(e:MouseEvent){
dir="up";
}
bDown.addEventListener(MouseEvent.MOUSE_DOWN,bDownHd);
function bDownHd(e:MouseEvent){
dir="down";
}
bStop.addEventListener(MouseEvent.MOUSE_DOWN,bStopHd);
function bStopHd(e:MouseEvent){
dir="stop";
}
哪儿出问题了呢?
你说的是ballMovie方法加public属性吗?加了以后会报错1114: public 属性只能在包的内部使用。 展开
package
{
import flash.display.MovieClip;
public class ball extends MovieClip
{
public function ball()
{
function ballMovie(mydir:String)
{
var speed:uint = 2;
switch (mydir)
{
case "left" :
this.x -= speed;
break;
case "right" :
this.x += speed;
break;
case "up" :
this.y -= speed;
break;
case "down" :
this.y += speed;
break;
case "stop" :
break;
}
}
}
}
}
主时间轴第一帧写代码如下:
var myBall:ball=new ball();
myBall.x=myBall.y=100;
addChild(myBall);
var dir:String;
addEventListener(Event.ENTER_FRAME,hdMovie);
function hdMovie(e:Event){
myBall.ballMovie(dir)
}
bLeft.addEventListener(MouseEvent.MOUSE_DOWN,bLeftHd);
function bLeftHd(e:MouseEvent){
dir="left";
}
bRight.addEventListener(MouseEvent.MOUSE_DOWN,bRightHd);
function bRightHd(e:MouseEvent){
dir="right";
}
bUp.addEventListener(MouseEvent.MOUSE_DOWN,bUpHd);
function bUpHd(e:MouseEvent){
dir="up";
}
bDown.addEventListener(MouseEvent.MOUSE_DOWN,bDownHd);
function bDownHd(e:MouseEvent){
dir="down";
}
bStop.addEventListener(MouseEvent.MOUSE_DOWN,bStopHd);
function bStopHd(e:MouseEvent){
dir="stop";
}
哪儿出问题了呢?
你说的是ballMovie方法加public属性吗?加了以后会报错1114: public 属性只能在包的内部使用。 展开
2个回答
展开全部
缺少对外的实例的API,没有访问权,这样修改:
package
{
import flash.display.MovieClip;
public class ball extends MovieClip
{
public function ball()
{
public function ballMovie(mydir:String)
{
var speed:uint = 2;
switch (mydir)
{
case "left" :
this.x -= speed;
break;
case "right" :
this.x += speed;
break;
case "up" :
this.y -= speed;
break;
case "down" :
this.y += speed;
break;
case "stop" :
break;
}
}
}
}
}
package
{
import flash.display.MovieClip;
public class ball extends MovieClip
{
public function ball()
{
public function ballMovie(mydir:String)
{
var speed:uint = 2;
switch (mydir)
{
case "left" :
this.x -= speed;
break;
case "right" :
this.x += speed;
break;
case "up" :
this.y -= speed;
break;
case "down" :
this.y += speed;
break;
case "stop" :
break;
}
}
}
}
}
追问
兄弟,你修改的是那里呢,我怎么没找到呀?
追答
public function ballMovie(mydir:String)
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询