0

我有几个库中的影片剪辑将添加到舞台,影片剪辑内部有一些我想控制它的 mc,这是我的脚本。

if (selectDiffText.text == "Collection 1 Easy")
    {
        var c1_easy:cartoonEasy = new cartoonEasy();
        addChild(c1_easy);
        c1_easy.x = 412;
        c1_easy.y = 400;
        TweenMax.from(c1_easy, 0.5, {alpha:0, ease:Expo.easeOut});
    }
    else if (selectDiffText.text == "Collection 1 Medium")
    {
        var c1_medium:cartoonMedium = new cartoonMedium();
        addChild(c1_medium);
        c1_medium.x = 412;
        c1_medium.y = 400;
        TweenMax.from(c1_medium, 0.5, {alpha:0, ease:Expo.easeOut});
    }
else
    {
        trace("ERROR!");
    }

如果selectDiffText发生变化,上面的代码将从库中加载特定的影片剪辑。

var movieList:Array = [cartoonMedium1,cartoonMedium2,cartoonMedium3,cartoonMedium4,cartoonMedium5,cartoonMedium6];

function getRandomMovie():MovieClip
{
    var index:int = Math.floor(Math.random() * movieList.length);
    var mcClass:Class = movieList.splice(index,1)[0];
    return new mcClass();
}
playGame = getRandomMovie();
addChild(playGame);

假设如果将 c1_medium 添加到舞台,c1_medium 也会从库中随机添加 1 个影片剪辑。

playGame mc 里面,我有mouseTarget.alpha = 0; ...如何从根级别控制它?c1_easy 也有 mouseTarget.alpha=0 。

4

1 回答 1

0

要轻松做到这一点,c1_easy并且c1_medium应该都扩展同一个类。例如:

class c1_easy extends CartoonGenericClass{[...]}

class c1_medium extends CartoonGenericClass{[...]}

CartoonGenericClass中,您将拥有变量mouseTarget。您使用 getter/setter 将其公开:

protected var _mouseTarget:Number;

public function get mouseTarget():Number{
    return _mouseTarget;
}

public function set mouseTarget(value:Number):void{
    // (should probably do some verification on "value" here)
    _mouseTarget.alpha = value;
}

这将允许从任何可以访问或mouseTarget的对象访问变量(注意没有下划线):c1_easyc1_medium

c1_easy.mouseTarget = 0;
c1_medium.mouseTarget = .3;

等等等等。这是标准的 OOP,所以可能是时候破解一个文档了。!

于 2012-04-11T03:10:27.590 回答