我正在尝试从类中访问主时间轴上硬编码的变量,函数和对象。当我在类中调用函数时,会加载对象,变量等... :
主时间轴中的一些代码:
import com.beauMoves;
var bm = new beauMoves();
bm.thisWorks();
以下是班级。但它没有访问主时间轴。在这种情况下,我试图访问从lib加载的显示对象并放置在时间轴上。该对象称为“Beau”,如下面的代码所示。
package com {
import flash.display.MovieClip;
import com.*;
public class beauMoves extends MovieClip
{
public function beauMoves()
{
// constructor code
trace("BeauMoves");
}
public function thisWorks()
{
trace("Cool Beans! This one worked");
// THESE TWO LINES BELOW ARE NOT WORKING
var main:MovieClip = MovieClip(this.parent);
main.Beau.alpha = .3;
}
}
}
答案 0 :(得分:0)
假设下面的两行是在主时间轴上,传递给beauMoves()这个作为构造函数参数:
import com.beauMoves;
var bm = new beauMoves( this );
然后在你的beauMoves()类中:
package com {
import flash.display.MovieClip;
import com.*;
public class beauMoves extends MovieClip
{
private var _mainTimeline:MovieClip;
public function beauMoves( mainTimeLine:MovieClip )
{
// constructor code
trace("BeauMoves");
_mainTimeline = mainTimeLine;
}
public function thisWorks()
{
trace("Cool Beans! This one worked");
_mainTimeline.bm.alpha = .3;
}
}
}