How to concatenate a variable in Actionscript 3?

Asked

Viewed 54 times

0

Hello, I have a list of clips Movie to be called inside an if, but I’m not able to concatenate the variable that contains the name of these clips. Imagine that:

I have three clips: P1, P2 and P3. And I want to call them dynamically, I tried that but it doesn’t work. Someone knows how?

if (qtdd == variavel_num) {

    this."caminho_do_mc.p" + var_numero_do_mc + .gotoAndStop(2); //o problema está aqui

    } 
  • 2

    You can try it like this this["caminho_do_mc.p"+var_numero_do_mc].gotoAndStop(2); or so this.caminho_do_mc["p"+var_numero_do_mc].gotoAndStop(2)

  • Pass the clip declaration code.

  • I tried this way Icarus but it didn’t work :( Thanks for the help.

1 answer

1

Before that assume that this is DisplayObjectContainer. In general you can try:

MovieClip(this.getChildByName('p'+ n)).gotoAndPlay(2)
// assumindo que ` mc_1.name = 'p1' `

(Using lists in addition to containers is something extra.)

Or you can use the method container getChildAt(): (depending on the case!)

(this.getChildAt(0) as MovieClip).gotoAndPlay(2) // mc_1

// ou usando n (0, 2)

(this.getChildAt(n) as MovieClip).gotoAndPlay(2) // mc_1

Remembering to import settings:

import flash.display.*

Browser other questions tagged

You are not signed in. Login or sign up in order to post.