我有一个项目,我需要将表单AS2更新为AS3,因为我需要一些可用于垂直居中文本的新功能。
我在时间线上的当前AS2代码如下。
var dataField = _root.dataField;
var dataType = _root.dataType;
var dataPage = _root.dataPage;
var dataVar = _root.dataVar;
_root.mc.onRelease = function() {
getURL("index.php?page="+dataPage+"&num="+dataNum+"&"+dataType+"="+dataVar, "_self");
};
我的外部AS文件如下。
import mx.transitions.Tween;
/**
*
* StandardKey is attached to a movieclip in the library.
* It handles the basic button behavior of the keyboard keys.
* When each button is placed on the stage, it's instance name
* will be the unique ID of the key.
*
*/
class StandardKey extends MovieClip {
///////////////////////////////////////
//Stage Elements
var highlight:MovieClip;
//End Stage Elements
var highlightTween:Tween;
function StandardKey(Void) {
//Repaint the key with 0 alpha
highlight._alpha = 0;
}
function onPress(Void):Void {
//Do the highlight animation
highlightTween.stop();
highlightTween = new Tween(highlight, "_alpha", mx.transitions.easing.Regular.easeInOut, 100, 0, 10, false);
}
}
这是我尝试将时间轴和外部AS2移动到AS3
时间轴我现在有:
var dataField = this.dataField;
var dataType = this.dataType;
var dataPage = this.dataPage;
var dataVar = this.dataVar;
var dataNum = this.dataNum;
_root.mc.onRelease = function() {
navigateToURL(new URLRequest("index.php?page="+dataPage+"&num="+dataNum+"&"+dataType+"="+dataVar, "_self"));
};
我有外部AS3
package {
import fl.transitions.Tween;
import fl.transitions.easing.*;
import flash.display.MovieClip;
/**
*
* StandardKey is attached to a movieclip in the library.
* It handles the basic button behavior of the keyboard keys.
* When each button is placed on the stage, it's instance name
* will be the unique ID of the key.
*
*/
public class StandardKey extends MovieClip {
///////////////////////////////////////
//Stage Elements
var highlight:MovieClip;
//End Stage Elements
var highlightTween:Tween;
public function StandardKey(Void) {
//Repaint the key with 0 alpha
highlight._alpha = 0;
}
public function onPress(Void):void {
//Do the highlight animation
highlightTween.stop();
highlightTween = new Tween(highlight, "_alpha", fl.transitions.easing.Regular.easeInOut, 100, 0, 10, false);
}
}
}
我目前得到的错误是:
场景1,图层'标签',第1帧,第6行1120:访问未定义的属性_root。 场景1,图层'标签',第1帧,第7行1137:参数数量不正确。预计不超过1个。
如果有人能帮我解决这个问题,我会非常感激。
亲切的问候 垫。
答案 0 :(得分:1)
不要使用_root,如果你绝对需要向上引用,那么最接近的AS3等价物就是阶段。
DisplayObject属性不再以下划线开头(在您的情况下为_alpha
与alpha
。)
你不能使用onRelease,你需要使用addEventListener()
你的时间轴代码没什么意义,为什么你要制作本地变量呢?
总而言之,我建议你阅读Adobe's migration guide。
答案 1 :(得分:0)
变化
_root.mc.onRelease = function() {
navigateToURL(new URLRequest("index.php?page="+dataPage+"&num="+dataNum+"&"+dataType+"="+dataVar, "_self"));
}
到
mc.addEventListener(MouseEvent.CLICK, mcClicked)
function mcClicked(e:Event) {
navigateToURL(new URLRequest("index.php?page="+dataPage+"&num="+dataNum+"&"+dataType+"="+dataVar, "_self"));
}
highlight._alpha = 0;
至highlight.alpha = 0;
highlightTween = new Tween(highlight, "_alpha", fl.transitions.easing.Regular.easeInOut, 100, 0, 10, false);
到
highlightTween = new Tween(highlight, "alpha", Regular.easeInOut, 100, 0, 10, false);
http://www.republicofcode.com/tutorials/flash/as3tweenclass/