我接触 AS3 已经好几年了,但有一个项目需要一些脚本编写。
我试图让目录菜单向下滑动,然后向上滑动,具体取决于通用的打开/关闭按钮。这个概念与在 jQuery 中使用 .slideToggle() 相同。
我创建了一个 MovieClip,给它一个实例名称,并在我的库中为 ActionScript 导出它,但出于某种原因,当我尝试运行一个方法将其向下移动 325px 时,我不断收到此错误:
1046:类型未找到或不是编译时常量:toc。
我意识到该库缺少某些内容的引用,但是由于 MC 具有实例名称并且已为 AS 导出,因此我对它可能是什么感到有些困惑。我的所有脚本都在第 1 帧中,我没有使用任何外部类。任何帮助/指针将不胜感激!当我尝试在代码底部创建电子邮件链接时,我也遇到了同样的问题。
再次,任何帮助将不胜感激!谢谢!!
import flash.events.MouseEvent;
import flash.display.MovieClip;
import flash.display.SimpleButton;
// Initial load elements
gotoAndStop("Frame1");
UpdateFrame();
// Mouse events
btnNextSlide.addEventListener(MouseEvent.CLICK, NextSlide);
btnPrevSlide.addEventListener(MouseEvent.CLICK, PrevSlide);
btnTOC.addEventListener(MouseEvent.CLICK, ShowToC);
//btnDifferenceLink.addEventListener(MouseEvent.CLICK, Email);
// Various Methods
function NextSlide(event:MouseEvent):void
{
// find current slide, go to next slide
var currentFrame = this.currentFrame;
var nextFrame = currentFrame + 1;
if (int(nextFrame) == this.totalFrames)
{
// stop
gotoAndStop("Frame" + this.framesLoaded);
}
else
{
// go to next slide
gotoAndStop("Frame" + nextFrame);
}
// go to and stop at the next frame
UpdateFrame();
}
function PrevSlide(event:MouseEvent):void
{
// find current slide
var currentFrame = this.currentFrame;
var prevFrame = currentFrame - 1;
if (int(prevFrame) == 1)
{
// stop
gotoAndStop("Frame1");
}
else
{
// go to next slide
gotoAndStop("Frame" + prevFrame);
}
// go to and stop at the next frame
UpdateFrame();
}
function UpdateFrame():void
{
txtCurrentSlide.text = this.currentFrame.toString();
}
function Email():void
{
var email:URLRequest = new URLRequest("mailto:emailaddress");
navigateToURL(email, "_blank");
}
function ShowToC():void
{
// slide Table of Contents down
toc.y = 325;
}
function HideToC():void
{
// slide Table of Contents up
toc.y = -325;
}
最佳答案
我刚刚找到了解决方案!
curtismorley.com/2007/06/20/flash-cs3-flex-2-as3-error-1046
在他的第一段中,他提到舞台上和图书馆中的物品不能同名。就我而言,我在库中有一个名为“toc”的 Assets ,并通过实例名称引用“toc”。通过改变这一点,问题已经解决。我一直在寻找这个愚蠢的错误一天半..
关于actionscript-3 - 闪存/AS3 : Type was not found or was not a compile-time constant,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17214015/