var target_mc:MovieClip = this.duplicateMovieClip(this._name + "_copy", _root.getNextHighestDepth());是什么意思 改为全局变量
时间: 2023-11-28 10:49:12 浏览: 54
这段代码的意思是将当前 MovieClip 对象复制一份,并将其命名为原对象名加上 "_copy" 后缀,然后将复制的 MovieClip 对象赋值给变量 target_mc。
如果要将其改为全局变量,则需要将变量声明放在全局作用域中,例如:
```
_global.target_mc = this.duplicateMovieClip(this._name + "_copy", _root.getNextHighestDepth());
```
这样就可以在任何地方访问和使用该变量了。但是请注意,过度使用全局变量可能会导致命名冲突和不必要的耦合,建议尽量避免使用全局变量。
相关问题
for (var i = 1; i <= 9; i++) { var img_mc:MovieClip = this["tu" + i]; // 添加点击事件监听器 img_mc.onPress = function() { // 创建该图像的副本,并将其设置为可拖动 var target_mc:MovieClip = this.duplicateMovieClip(this._name + "_copy", _root.getNextHighestDepth()); target_mc.startDrag(); target_mc.onPress = function() { this.startDrag(); }; // 在鼠标移动事件处理程序中,将图像的位置设置为鼠标位置 target_mc.onMouseMove = function() { if(Key.isDown(Key.H)) { // 从舞台上删除该剪辑 this.removeMovieClip(); return; this._x = _root._xmouse; this._y = _root._ymouse; } // 检查图像是否与其他图像重叠,并根据需要更新其透明度 for (var j = 1; j <= 9; j++) { var other_mc:MovieClip = _root["tu" + j]; if (target_mc != other_mc && target_mc.hitTest(other_mc)) { target_mc._alpha = 50; return; } } target_mc._alpha = 100; }; // 在鼠标释放事件处理程序中,检查图像是否与其他图像重叠 target_mc.onRelease = target_mc.onReleaseOutside = function () { this.stopDrag(); this.onMouseMove = null; target_mc.onRelease = target_mc.onReleaseOutside = function () { this.stopDrag(); }; // 检查图像是否与其他图像重叠,并根据需要更新其透明度 for (var j = 1; j <= 9; j++) { var other_mc:MovieClip = _root["tu" + j]; if (target_mc != other_mc && target_mc.hitTest(other_mc)) { target_mc._alpha = 50; return; } } // 将图像放置在当前位置,并将其透明度设置为100% target_mc._alpha = 100; target_mc.swapDepths(_root.getNextHighestDepth()); }; }; }运行时提示没有h的属性 要怎么做
这段代码是使用 ActionScript 2.0 编写的,而在 ActionScript 2.0 中,Key 类是用来检测键盘事件的,但是它不支持检测单独的按键。如果想要检测单独的按键,可以使用 Key.getCode() 方法来获取按键的 ASCII 码值,然后进行比较。
在这段代码中,你可以修改如下部分:
```
if (Key.isDown(Key.H)) {
// 从舞台上删除该剪辑
this.removeMovieClip();
return;
this._x = _root._xmouse;
this._y = _root._ymouse;
}
```
改为:
```
if (Key.getCode() == 72) { // H键的ASCII码值为72
// 从舞台上删除该剪辑
this.removeMovieClip();
return;
this._x = _root._xmouse;
this._y = _root._ymouse;
}
```
这样就可以检测到按下 H 键的事件了。
var clips:Array = [tu1, tu2, tu3, tu4, tu5, tu6, tu7, tu8, tu9]; // 存储所有影视剪辑的数组 var STATE_NORMAL:Number = 1; var STATE_OVER:Number = 2; var STATE_SELECTED:Number = 3; for (var i:Number = 0; i < clips.length; i++) { var clip:MovieClip = clips[i]; clip.gotoAndStop(STATE_NORMAL); clip.selected = false; // 添加一个selected属性并初始化为false clip.useHandCursor = true; clip.addEventListener(MouseEvent.ROLL_OVER, onRollOver); clip.addEventListener(MouseEvent.ROLL_OUT, onRollOut); clip.addEventListener(MouseEvent.CLICK, onClick); } function onRollOver(event:MouseEvent):void { trace("onRollOver called"); updateState(event.currentTarget as MovieClip, STATE_OVER); } function onRollOut(event:MouseEvent):void { trace("onRollOut called"); var clip:MovieClip = event.currentTarget as MovieClip; if (!clip.selected) { updateState(clip, STATE_NORMAL); } } function onClick(event:MouseEvent):void { trace("onClick called"); var clip:MovieClip = event.currentTarget as MovieClip; if (clip.selected) { return; } for (var j:Number = 0; j < clips.length; j++) { var c:MovieClip = clips[j]; c.selected = false; updateState(c, STATE_NORMAL); } clip.selected = true; updateState(clip, STATE_SELECTED); } function updateState(clip:MovieClip, state:Number):void { clip.gotoAndStop(state); if (state == STATE_SELECTED) { clip.mc_normal.visible = false; clip.mc_over.visible = false; clip.mc_selected.visible = true; } else if (state == STATE_OVER) { clip.mc_normal.visible = false; clip.mc_over.visible = true; clip.mc_selected.visible = false; } else { // STATE_NORMAL clip.mc_normal.visible = true; clip.mc_over.visible = false; clip.mc_selected.visible = false; } }改为as2语言
var clips:Array = [tu1, tu2, tu3, tu4, tu5, tu6, tu7, tu8, tu9]; // 存储所有影视剪辑的数组
var STATE_NORMAL:Number = 1;
var STATE_OVER:Number = 2;
var STATE_SELECTED:Number = 3;
for (var i:Number = 0; i < clips.length; i++) {
var clip:MovieClip = clips[i];
clip.gotoAndStop(STATE_NORMAL);
clip.selected = false; // 添加一个selected属性并初始化为false
clip.useHandCursor = true;
clip.onRollOver = function() {
trace("onRollOver called");
updateState(this, STATE_OVER);
};
clip.onRollOut = function() {
trace("onRollOut called");
var clip:MovieClip = this;
if (!clip.selected) {
updateState(clip, STATE_NORMAL);
}
};
clip.onClick = function() {
trace("onClick called");
var clip:MovieClip = this;
if (clip.selected) {
return;
}
for (var j:Number = 0; j < clips.length; j++) {
var c:MovieClip = clips[j];
c.selected = false;
updateState(c, STATE_NORMAL);
}
clip.selected = true;
updateState(clip, STATE_SELECTED);
};
}
function updateState(clip:MovieClip, state:Number):void {
clip.gotoAndStop(state);
if (state == STATE_SELECTED) {
clip.mc_normal._visible = false;
clip.mc_over._visible = false;
clip.mc_selected._visible = true;
} else if (state == STATE_OVER) {
clip.mc_normal._visible = false;
clip.mc_over._visible = true;
clip.mc_selected._visible = false;
} else {
// STATE_NORMAL
clip.mc_normal._visible = true;
clip.mc_over._visible = false;
clip.mc_selected._visible = false;
}
}
阅读全文