Skip to main content
didier_31
Participant
February 19, 2021
質問

Propriété .visible avec une variable

  • February 19, 2021
  • 返信数 1.
  • 266 ビュー

Bonjour,
Je souhaite, à partir d'un menu déroulant, rendre visible certains éléments (clips).
J'ai pour cela écrit ce bout de code

 

if(!this.menu_hom_change_cbk) {
	function menu_hom_change(evt) {
		// Début de votre code personnalisé
		console.log(evt.target.value);
		var choix_h = ((evt.target.value)+"_mc");
		//alert (choix_h);
		this.choix_h.visible = true;
	}
	$("#dom_overlay_container").on("change", "#menu_hom", menu_hom_change.bind(this));
	this.menu_hom_change_cbk = true;
}

 

qui récupère l'option de menu cliquée dans une variable, puis je réutilise cette variable pour afficher l'objet sélectionné comme ceci : this. ma_variable.visible = true
Mais cela ne fonctionne pas : le nom du clip obtenu avec la variable est correct (vérifié avec la fonction "alert").
Je pense que la syntaxe est incorrect dans la ligne de la propriété .visible et je ne sais pas comment il faut l'écrire.
Merci de votre aide.

***

Hello, I want, from a drop-down menu, to make certain elements (clips) visible. For that I wrote this piece of code which gets the menu option clicked in a variable, then I reuse that variable to display the selected object like this: this. my_variable.visible = true But that does not work: the name of the clip obtained with the variable is correct (checked with the "alert" function). I think the syntax is incorrect in the line for the .visible property and I don't know how to write it. Thank you for your help.

    このトピックへの返信は締め切られました。

    返信数 1

    kglad
    Community Expert
    Community Expert
    February 19, 2021

    your code is assigning a string's visible proptery to true and strings don't have visible properties.

     

    you need to first convert that string to an object and then assign the object's visible property:  to coerce a string to an object use array notation:

     

     

     

    var choix_h = ((evt.target.value)+"_mc");
    		//alert (choix_h);
    		this[choix_h].visible = true

     

     

    didier_31
    didier_31作成者
    Participant
    February 19, 2021

    It works.
    Thank you very much.

    kglad
    Community Expert
    Community Expert
    February 19, 2021

    you're welcome.