简体   繁体   English

Flash CS5 Actionscript 3.0使用影片剪辑作为带有链接的按钮

[英]Flash CS5 Actionscript 3.0 Using a movie clip as a button with linking

So I have an animated button in the form of a movie clip that I want to be able to use as a link. 因此,我有一个影片剪辑形式的动画按钮,希望可以用作链接。 The movie clip is animated on mouse over and mouse off using a script I found online, and that works perfectly. 使用我在网上找到的脚本在鼠标悬停和鼠标悬停时为影片剪辑设置了动画,并且效果很好。 However, when I try to create a simple actionscript command to also have the movie clip act as a link, I get the following error thrown at me: 但是,当我尝试创建一个简单的动作脚本命令以使影片剪辑也充当链接时,出现以下错误:

TypeError: Error #1009: Cannot access a property or method of a null object reference. TypeError:错误#1009:无法访问空对象引用的属性或方法。 at PheV3_fla::MainTimeline/frame185() 在PheV3_fla :: MainTimeline / frame185()

All of the tutorials I found online use the "button" type for linking as opposed to a movie clip, which seems to work fine, but I need this to be a movie clip for the animation. 我在网上找到的所有教程都使用“按钮”类型进行链接,而不是使用影片剪辑,这似乎可以正常工作,但是我需要将其用作动画的影片剪辑。 Here is the code I'm using: 这是我正在使用的代码:

import flash.events.MouseEvent
import flash.net.URLRequest

MixesButtonTop.addEventListener(MouseEvent.CLICK, fl_ClickToGoToWebPage_2);

function fl_ClickToGoToWebPage_2(event:MouseEvent):void
{
    navigateToURL(new URLRequest("http://www.adobe.com"), "_blank");
}

Do I need to reference one of the symbols inside the movie clip button itself or something? 我是否需要引用影片剪辑按钮本身内部的某个符号或其他内容? I'm very new to all this so if I missed anything please let me know, thanks so much for the help! 我对这一切都很陌生,所以如果我错过了任何事情,请告诉我,非常感谢您的帮助!

You should give your button an instance name under the properties tab, and then reference to it by that name, and not by how it is called in the library. 您应该在属性选项卡下为按钮指定一个实例名称,然后通过该名称而不是在库中如何调用该名称来对其进行引用。 To do that you need 为此,您需要

  1. Select the button instance on the Stage. 在舞台上选择按钮实例。
  2. Select Window > Properties, and enter a name in the Instance Name box. 选择“窗口”>“属性”,然后在“实例名称”框中输入名称。

So for example you set instance name MixesButtonTop . 因此,例如,您设置实例名称MixesButtonTop Then you should declare a variable in your code like this: 然后,您应该在代码中声明一个变量,如下所示:

var buttonMC:MovieClip = MixesButtonTop;

And that should fix your problem. 那应该可以解决您的问题。

If your button exists in the timeline, you need to give it an instance name (see the response of jfgi). 如果您的按钮在时间轴中存在,则需要为其指定一个实例名称(请参阅jfgi的响应)。 By this instance name you can reference it in your code. 通过此实例名称,您可以在代码中引用它。 It is not necessary to assign it to a variable (in contrast to what jfgi wrote) - however assigning it to a variable and adding the type (:MovieClip) will help you with code-hinting if you are working with Flash IDE, otherwise the IDE cannot figure out what type the symbol is. 不必将其分配给变量(与jfgi编写的相反)-但是,如果使用Flash IDE,则将其分配给变量并添加类型(:MovieClip)将有助于代码提示。 IDE无法确定符号的类型。 Note: the name of the symbol in the library is a 'Class name' (Linkage). 注意:库中符号的名称是“类名”(链接)。 You cannot use the class name to command and INSTANCE of the class. 您不能使用类名称来命令和实例化该类。 You need to assign it to a variable/give it an instance name in the properties window. 您需要将其分配给变量/在属性窗口中为其指定实例名称。 If you manually place a symbol from the library to the stage and you want to control it, you 'always' need to add an instance name. 如果您手动将符号从库放置到舞台上并想要对其进行控制,则“总是”需要添加实例名称。 ('always'... as there are other ways to retrieve the reference, eg getChildAt, etc...) (“总是” ...,因为还有其他检索引用的方法,例如getChildAt等)。

I had to post this as an answer, it was too long for a comment. 我不得不将其发布为答案,评论太久了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM