【问题标题】:How to pass a reference of a movieClip made in one class to another?如何将一个类中制作的movieClip的引用传递给另一个类?
【发布时间】:2009-09-30 21:44:24
【问题描述】:

我有一个带有按钮的movieClip,该按钮是在我的显示类Thumbnail.as中创建的,并且我有一个按钮功能可以在我的ui类ThumbnailController.as中与之交互ThumbnailController.as。

我目前遇到的问题是;在我的 ui 类中,我无法定位在我的显示类中创建的 movieClip playGlow。

在我的显示类中创建 playGlow 按钮的代码(Thumbnail.as)

public function playBtns():void  {
playThumb = new PlayThumb;
playThumb.x = 642;
playThumb.y = 22;
playThumb.alpha = 1;

playGlow = new PlayGlow;
playGlow.x = 628;
playGlow.y = 8;
playGlow.alpha = 1;
}

public function buildRow ():void{
     thumbNailRow.addChild(thumbLoader);
     thumbNailRow.addChild(thumbTitle);
     thumbNailRow.addChild(thumbText);
     thumbNailRow.addChild(playGlow);
     thumbNailRow.addChild(playThumb);

playThumb.addEventListener(MouseEvent.ROLL_OVER, rowRollOver);

addChild(thumbNailRow);
}

现在是我的 ui 类中的代码 (ThumbnailController.as)

public function rowRollOver(e:MouseEvent):void
{
     dispatchEvent(new Event(Event.CHANGE, true ));

     TweenPlugin.activate([TintPlugin]);
     TweenLite.to(playGlow, .4, {alpha:.5, tint:0x99cc00});

 }

这是问题所在:TweenLite.to(playGlow, .4, {alpha:.5, tint:0x99cc00});

只有在这样的情况下才会起作用:TweenLite.to(this, .4, {alpha:.5, tint:0x99cc00});

但是如果我使用 this,整个 thumbNailRow 电影剪辑都会着色,我只想着色 thumbNailRow 内部的 playGlow 电影剪辑,但我不知道如何专门针对它。我得到 1120: Access of undefined property playGlow 否则。


如何将 playGlow 的实例传递到我的 ui 类中,以便我可以使用补间色调来定位该电影剪辑?

【问题讨论】:

    标签: flash actionscript-3 class inheritance casting


    【解决方案1】:

    尝试使用事件目标进行翻转?

    TweenLite.to(e.target, .4, {alpha:.5, tint:0x99cc00});
    

    你可能需要转换 e.target:

    TweenLite.to(Sprite(e.target), .4, {alpha:.5, tint:0x99cc00});
    

    至少,您应该尝试追踪 e.target 并告诉我们它是什么。

    【讨论】:

    • 谢谢!这行得通:D 我应该考虑过尝试 e.target... w00t!
    【解决方案2】:

    我对所有这些 AS3 东西都很陌生,但你尝试过吗:

    TweenLite.to(MovieClip(this).playGlow, .4, {alpha:.5, tint:0x99cc00});

    当我尝试定位目标时,这总是对我有用。

    【讨论】:

      【解决方案3】:

      问题似乎是 e.target 是对 thumbNailRow 的 playThumb 的引用,而不是您想要影响的 playGlow。

      如果在上面的原始代码中,thumbnailRow 是 Thumbnail 类的一个实例(我认为是,不能确定),那么以下应该没问题:

      public function rowRollOver(e:MouseEvent):void {
          dispatchEvent(new Event(Event.CHANGE, true ));
          TweenPlugin.activate([TintPlugin]);
          var parentThumb: Thumbnail = e.target.parent as Thumbnail; 
          TweenLite.to(parentThumb.playGlow, .4, {alpha:.5, tint:0x99cc00});
       }
      

      【讨论】:

      • 嗨,谢谢.. 刚刚尝试了这段代码,但收到此错误:1046:找不到类型或不是编译时常量:缩略图。以及未定义属性缩略图的访问。 thumbNailRow 是 Thumbnail 类的一个实例,它扩展了 ThumbnailController
      • 您至少必须将 Thumbnail 导入到您的控制器类中(您不能在函数体中对类进行类型引用而不导入它)。我没有包含 import 语句,因为您没有暗示您的包结构是什么。如果没有,则导入缩略图;在控制器的顶部就足够了。
      猜你喜欢
      • 1970-01-01
      • 2023-01-25
      • 1970-01-01
      • 2021-12-18
      • 1970-01-01
      • 2017-03-04
      • 1970-01-01
      • 2011-03-15
      • 1970-01-01
      相关资源
      最近更新 更多