as3.0函数里的变量问题
for(vari:int=0;i<6;i++){this["mc"+i].addEventListener(MouseEvent.MOUSE_DOWN,MouseDown...
for(var i:int=0;i<6;i++)
{
this["mc"+i].addEventListener(MouseEvent.MOUSE_DOWN,MouseDownEvent);
}
//拖放
function MouseDownEvent(e:MouseEvent):void
{
var obj:Object=e.currentTarget;
obj.startDrag();
}
//停止拖放
stage.addEventListener(MouseEvent.MOUSE_UP, fl_ReleaseToDrop);
function fl_ReleaseToDrop(event:MouseEvent):void
{
this.stopDrag();
}
//拖放碰撞事件
addEventListener(Event.ENTER_FRAME, fl2_EnterFrameHandler);
function fl2_EnterFrameHandler(event:Event):void
{
for(var i:int=0;i<6;i++)
{
//var l:Object=MouseDownEvent.obj
if(this["mc"+i].hitTestObject(this["ma"+i])){
obj.alpha=0
}
}
}
显示错误
obj
为定义,或是我的方法不对,不能这样做拖拽。 展开
{
this["mc"+i].addEventListener(MouseEvent.MOUSE_DOWN,MouseDownEvent);
}
//拖放
function MouseDownEvent(e:MouseEvent):void
{
var obj:Object=e.currentTarget;
obj.startDrag();
}
//停止拖放
stage.addEventListener(MouseEvent.MOUSE_UP, fl_ReleaseToDrop);
function fl_ReleaseToDrop(event:MouseEvent):void
{
this.stopDrag();
}
//拖放碰撞事件
addEventListener(Event.ENTER_FRAME, fl2_EnterFrameHandler);
function fl2_EnterFrameHandler(event:Event):void
{
for(var i:int=0;i<6;i++)
{
//var l:Object=MouseDownEvent.obj
if(this["mc"+i].hitTestObject(this["ma"+i])){
obj.alpha=0
}
}
}
显示错误
obj
为定义,或是我的方法不对,不能这样做拖拽。 展开
2个回答
展开全部
你的obj应该放在函数外面定义。我帮你修改了代码:
for (var i:int=0; i<6; i++)
{
this["mc" + i].addEventListener(MouseEvent.MOUSE_DOWN,MouseDownEvent);
}
//拖放;
var obj:Object = new Object();
function MouseDownEvent(e:MouseEvent):void
{
obj = e.currentTarget;
obj.startDrag();
}
//停止拖放
stage.addEventListener(MouseEvent.MOUSE_UP, fl_ReleaseToDrop);
function fl_ReleaseToDrop(event:MouseEvent):void
{
this.stopDrag();
}
//拖放碰撞事件
addEventListener(Event.ENTER_FRAME, fl2_EnterFrameHandler);
function fl2_EnterFrameHandler(event:Event):void
{
for (var i:int=0; i<6; i++)
{
if (this["mc" + i].hitTestObject(this["ma" + i]))
{
obj.alpha = 0;
}
}
}
for (var i:int=0; i<6; i++)
{
this["mc" + i].addEventListener(MouseEvent.MOUSE_DOWN,MouseDownEvent);
}
//拖放;
var obj:Object = new Object();
function MouseDownEvent(e:MouseEvent):void
{
obj = e.currentTarget;
obj.startDrag();
}
//停止拖放
stage.addEventListener(MouseEvent.MOUSE_UP, fl_ReleaseToDrop);
function fl_ReleaseToDrop(event:MouseEvent):void
{
this.stopDrag();
}
//拖放碰撞事件
addEventListener(Event.ENTER_FRAME, fl2_EnterFrameHandler);
function fl2_EnterFrameHandler(event:Event):void
{
for (var i:int=0; i<6; i++)
{
if (this["mc" + i].hitTestObject(this["ma" + i]))
{
obj.alpha = 0;
}
}
}
大雅新科技有限公司
2024-11-19 广告
2024-11-19 广告
这方面更多更全面的信息其实可以找下大雅新。深圳市大雅新科技有限公司从事KVM延长器,DVI延长器,USB延长器,键盘鼠标延长器,双绞线视频传输器,VGA视频双绞线传输器,VGA延长器,VGA视频延长器,DVI KVM 切换器等,优质供应商,...
点击进入详情页
本回答由大雅新科技有限公司提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询