【发布时间】:2011-12-25 17:49:57
【问题描述】:
*编辑 - 我发现错误是当我尝试更改影片剪辑的图形属性时。*
我收到此错误。 “ReferenceError:错误 #1069:在 flash.events.MouseEvent 上找不到属性项,并且没有默认值。在 PlayScreen/onClick() 中”。 我做了一些研究,大多数网站都说这是由于拼写错误。但据我所知,它看起来不错?
据我所知,我有两个事件的设置完全相同。一个是 onclick 触发的,另一个是 onhover 触发的。悬停事件工作正常,但是当我使用 onclick 事件时,我收到上面的错误。但是,即使我收到错误,该功能仍然可以正常工作。
这是我的代码。 下面的代码创建了一个新的网格。然后添加自定义事件。悬停事件工作正常,没有错误。 onclick 事件工作正常,但我得到了错误。
package {
import flash.events.MouseEvent;
import flash.display.MovieClip;
public class PlayScreen extends MovieClip {
public var grid:Grid;
public function PlayScreen() {
grid = new Grid();
grid.addEventListener( GridEvent.HOVER, onHover);
grid.addEventListener( GridEvent.TILECLICK, onClick);
grid.x = 0;
grid.y = 0;
addChild( grid );
}
public function onHover(event:*){
event.item.graphics.beginFill(0x66ff66);
event.item.graphics.lineStyle(2, 0x22ff22);
event.item.graphics.drawRect(-30*0.5, -30*0.5, 30, 30);
event.item.graphics.endFill();
}
public function onClick(event:*){
event.item.graphics.beginFill(0x000000);
event.item.graphics.lineStyle(2, 0x22ff22);
event.item.graphics.drawRect(-30*0.5, -30*0.5, 30, 30);
event.item.graphics.endFill();
}
下面是我的网格类。它包含一个movieclip,其中添加了两个mouseEvents,然后触发自定义事件。
package {
import flash.display.MovieClip;
import flash.events.MouseEvent;
public class Grid extends MovieClip {
public function Grid() {
var test = new MovieClip();
test.x = 0;
test.y = 0;
test.graphics.beginFill(0x66ff66);
test.graphics.drawRect(-tileWidth*0.5, -tileHeight*0.5, tileWidth, tileHeight);
test.graphics.endFill();
test.addEventListener(MouseEvent.MOUSE_OVER, overTile);
test.addEventListener(MouseEvent.MOUSE_DOWN, clickTile);
addChild(test);
}
function overTile (event:*) {
dispatchEvent( new GridEvent( GridEvent.HOVER, event.target) );
}
function clickTile(event:*) {
dispatchEvent( new GridEvent( GridEvent.TILECLICK, event.target) );
}
}
以下是我的自定义事件
package
{
import flash.events.Event;
public class GridEvent extends Event
{
public static const HOVER :String = "hover";
public static const TILECLICK :String = "click";
public var item;
public function GridEvent (type:String, item)
{
this.item = item;
super(type);
}
}
}
【问题讨论】:
-
那是你的完整源代码吗?当您甚至没有为事件提供类型时,Flash 没有理由给出有关 MouseEvent 的错误。肯定有其他问题。
-
这不是所有的代码,因为完整的代码相当广泛。但是我遇到了同样的问题。我发现这是我尝试更改图形属性的时候。如果我不这样做,我不会收到错误消息。所以我不明白为什么它给我一个 onclick 功能而不是悬停功能的错误?也谢谢你的回复:)
标签: flash actionscript-3