Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Variable targetting help 1

Status
Not open for further replies.

frozenpeas

Technical User
Sep 13, 2001
893
CA
This:

Code:
        if (_root.count<=20) {
            rdm = &quot;gainer&quot;+(Math.ceil(Math.random()*gainerQuantity));
            label = labelArray[Math.floor(Math.random()*labelArray.length)];
            tellTarget (_root.rdm) {
                gotoAndPlay (label);
                trace (&quot;rdm = &quot;+rdm+&quot; and label = &quot;+label);
            }
        }

traces:

Code:
rdm = gainer7 and label = good
rdm = gainer1 and label = good
rdm = gainer6 and label = bad

or some such thing.

The problem is, I can't get the movie clips (gainer#) to do anything with the telltarget. I've tried referencing it the short-hand way, but that makes no difference.

Help? Thanks.
 
That's probably because you have your movie looking for &quot;_root.rdm&quot;, instead of &quot;_root.gainer7&quot;, etc. Try this:

Code:
tellTarget(eval&quot;_root.&quot; + rdm){
    //actions here
}

That should sort it out. The short-hand way (as you described it) should look like this:

_root[rdm].gotoAndPlay(1)

with whatever action you want tagged on the end.
 
For some reason, I can't get this to work at all:

Code:
            rdm = &quot;gainer&quot;+(Math.ceil(Math.random()*gainerQuantity));
            label = labelArray[Math.floor(Math.random()*labelArray.length)];
            tellTarget (eval(&quot;_root.&quot;+rdm)) {
                gotoAndPlay (label);
                _root.text = &quot;rdm = &quot;+rdm+&quot; and label = &quot;+label;            }

So I am using this:

Code:
            rdm = &quot;gainer&quot;+(Math.ceil(Math.random()*gainerQuantity));
            label = labelArray[Math.floor(Math.random()*labelArray.length)];
            _root[rdm].gotoAndPlay(label);
            _root.text = &quot;rdm = &quot;+rdm+&quot; and label = &quot;+label;

The strange thing is, only &quot;gainer2&quot; will react to the gotoAndPlay. But it reacts when &quot;gainer1&quot; is called. When I remove &quot;gainer&quot; from the instance names and code (and use just numbers) &quot;1&quot; WILL react when &quot;1&quot; is called. None of the other instances will react at all. Strange. Not good.

Any ideas? I'd like to post an FLA but I am not able to.

Thanks.
 
Okay, for a problem like this with targets, since you are unable to supply a FLA, you will have to give me some clues as to the hierarchy of movieClips involved, specifically:

1. The absolute address of the MCs being called
2. The absolute address of the MC containing the code which is calling the other MCs
3. The absolute address of the MC in which both &quot;gainerQuantity&quot; and &quot;labelArray&quot; are set.

Maybe with this info we can start formulating a solution ...
 
Sure thing. Here is the AS on the controller movie clip that's at _root:

Code:
onClipEvent (load) {
    _root.wait = 10;
    gainerQuantity = 7;
    labelArray = new Array(&quot;good&quot;, &quot;good&quot;, &quot;bad&quot;);
}
onClipEvent (enterFrame) {
    if (_root.delay) {
        if (Math.floor(getTimer()/1000) == _root.lastTime+1) {
            _root.delay = false;
        }
    } else if (Math.floor(getTimer()/1000) == _root.lastTime+_root.wait) {
        _root.lastTime = Math.floor(getTimer()/1000);
        _root.delay = true;
        // select random Gainer MC
        _root.count++;
        if (_root.count<=20) {
            rdm = &quot;gainer&quot;+(Math.ceil(Math.random()*gainerQuantity));
            label = labelArray[Math.floor(Math.random()*labelArray.length)];
            _root[rdm].gotoAndPlay(label);
            _root.text = &quot;rdm = &quot;+rdm+&quot; and label = &quot;+label;
        }
    }
}

The gainer# MCs I'm calling are all on _root. There are seven of them, all labelled &quot;gainer1&quot; through &quot;gainer7&quot;.

I think it's strange that one clip will react, but not the others. The only thing changing is the number, so it should work.
 
Okay, I ran a simulation using your script, and I must say that it worked perfectly for me. If you have an email account I can send the test FLA I made to I'd be happy to let you see it.
 
I wonder if there is a glitch somewhere. Flash seems to like to do that sometimes.

You can send your FLA to warrenuhll@yahoo.com

That's not my real name, btw. Thanks very much.
 
I just copied and pasted the 7 instances and the controller MC to a new file and tested it. All I did was copy/paste. It works perfectly.

Ridiculous.
 
Yep, that's how it goes sometimes! I'm glad it worked out anyways.
 
I spoke too soon. It sort of works...

Strangeness:

gainer1 variable activates gainer7 instance.
gainer2 variable activates gainer2 instance (good).
gainer6 variable activates gainer4 instance.

This kind of quirkiness is enough to drive someone crazy.

Ideas?

 
I tried emailing you at the address above, and warrenhull@yahoo.com (which I presume is what you meant to type) - I keep getting delivery failure notices ... ??
 
Oh, sorry. It should have been warrenuhll@yahoo.ca

Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top