Visualizzazione dei risultati da 1 a 5 su 5

Discussione: cicli

  1. #1

    cicli

    sono un vero novellino e di programmazione ne so poco o nulla.

    mi ritrovo con una serie di if da semplificare con un ciclo, come si fa?

    il codice da semplificare è questo:

    if (Math.round(_root.mc1._y) == /:x) {
    _root.mc1._y = Math.round(_root.mc1._y);
    }
    if (Math.round(_root.mc2._y) == /:x) {
    _root.mc2._y = Math.round(_root.mc2._y);
    }
    if (Math.round(_root.mc3._y) == /:x) {
    _root.mc3._y = Math.round(_root.mc3._y);
    }
    if (Math.round(_root.mc4._y) == /:x) {
    _root.mc4._y = Math.round(_root.mc4._y);
    }
    if (Math.round(_root.mc5._y) == /:x) {
    _root.mc5._y = Math.round(_root.mc5._y);
    }
    if (Math.round(_root.mc6._y) == /:x) {
    _root.mc6._y = Math.round(_root.mc6._y);
    }
    if (Math.round(_root.mc7._y) == /:x) {
    _root.mc7._y = Math.round(_root.mc7._y);
    }
    if (Math.round(_root.mc8._y) == /:x) {
    _root.mc8._y = Math.round(_root.mc8._y);
    }
    if (Math.round(_root.mc9._y) == /:x) {
    _root.mc9._y = Math.round(_root.mc9._y);
    }
    if (Math.round(_root.mc10._y) == /:x) {
    _root.mc10._y = Math.round(_root.mc10._y);
    }
    if (Math.round(_root.mc11._y) == /:x) {
    _root.mc11._y = Math.round(_root.mc11._y);
    }
    if (Math.round(_root.mc12._y) == /:x) {
    _root.mc12._y = Math.round(_root.mc12._y);
    }

    grazie degli eventuali suggerimenti

  2. #2
    Utente di HTML.it L'avatar di negatyve
    Registrato dal
    Feb 2001
    Messaggi
    9,479
    codice:
    for(var i = 1; i < 13; i++){
    	var item = _root["mc" + i];
    	if(Math.round(item._y) == _root.x)item._y = Math.round(item._y);
    }

  3. #3
    Utente di HTML.it
    Registrato dal
    Jul 2000
    Messaggi
    321
    grazie molto gentile e scusa l'ignoranza.
    ciao

  4. #4
    Utente di HTML.it L'avatar di negatyve
    Registrato dal
    Feb 2001
    Messaggi
    9,479
    Sdoppiamento di personalità? :)

  5. #5
    Utente di HTML.it
    Registrato dal
    Jul 2000
    Messaggi
    321
    ehm no è l'uso del pc del titolare, anzi, mi sa che si incazza proprio.

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.