0
votes

I've few movieclip from library that will add to stage, inside of the movieclip have some mc that I want to control it, here is my script.

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!");
    }

Code above will load particular movieclip from library if the selectDiffText change.

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);

let say if c1_medium is added to stage, c1_medium will also randomly added 1 of the movieclip from library on it.

inside of the playGame mc, I've mouseTarget.alpha = 0;...how can I control it from root level? c1_easy also have the mouseTarget.alpha=0 too.

1
What exactly are you wanting this code to do?Jordan
each of the c1_easy and c1_medium have the mc called mouseTarget, but each time I just loaded either c1_easy or c1_medium to the stage only. I want to control the alpha value of the mouseTarget. The level is like this Stage>c1_easy/c1_medium>playGame what i want is from root/stage to control mouseTarget which in playGame which added by either c1_easy or c1_mediumpizza0502

1 Answers

0
votes

To do this easily, c1_easy and c1_medium should both extend the same class. For example:

class c1_easy extends CartoonGenericClass{[...]}

and

class c1_medium extends CartoonGenericClass{[...]}

In CartoonGenericClass, you would have the variable mouseTarget. You make this public using the 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;
}

This will allow access to the variable mouseTarget (note that there is no underscore) from any object that can access either c1_easy or c1_medium:

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

etc. etc. This is standard OOP, so it may be time to crack a doc. HTH!