1

我正在尝试从一个类访问主时间线上硬编码的变量、函数和对象。当我在类中调用这样的函数时,会加载对象、变量等:

来自主时间线的一些代码:

import com.beauMoves;
var bm = new beauMoves();

bm.thisWorks();

下面是课程。但它没有访问主时间线。在这种情况下,我试图访问从库加载的显示对象并放置在时间轴上。如您在下面的代码中所见,该对象称为“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;

        }

}


}
4

1 回答 1

0

假设下面的两行在主时间线上,将this作为构造函数参数传递给 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;

        }

    }

}

于 2013-09-05T19:43:01.887 回答