Pasar un valor en la piel a una matriz

I have a skin attached to a button. The skin has an image and a label on it. My question is how to pass the value of the label and place it into an array (when clicked) and remove the value (when clicked again)?

preguntado el 25 de agosto de 12 a las 18:08

Con the value of the label, you mean its text ¿propiedad? -

Yes, its text property. I have no idea how to get the "text" property of the label from the skin. -

1 Respuestas

The Label's text property in your Button's skin is actually an exact mirror of the Button's label property. When you set a Button's label, you automatically set the Label's text in its skin. And the other way around for getting the property.

So to answer your question more concretely:

<s:Button label="hello" click="addOrRemove(event.currentTarget as Button)" />


private var myArray:Array = [];

private function addOrRemove(button:Button):void {
    var label:String = button.label;
    var index:int = myArray.indexOf(label);

    if (index == -1) myArray.push(label);
    else myArray.splice(index, 1);

Respondido 25 ago 12, 18:08

Actually i have a code in skin that randomize the text in label public function randomNumber(min:Number, max:Number):Number{ var Results:Number = Math.floor(Math.random()*max)+min; return Results; } I pass it in the text property of the label: <s:Label includeIn="disabled,down,over,up" horizontalCenter="0" text="{randomNumber(1,10)}" verticalCenter="0"/> <s:Label includeIn="disabled,down,over,up" horizontalCenter="0" text="{randomNumber(1,10)}" verticalCenter="0"/> I assigned the skin on the button and when I trace the label of the button, it has no label. - Mirage01

In the future, please provide that kind of relevant information in your question. Also, you shouldn't do this: you're putting logic in a Skin. The logical consequence is that you can't access the property from the host component. So, take that randomization logic out of the skin and apply it to the Button's 'label' property instead. - RIAstar

i tried to randomize the label property of a button. it is displayed. but when i put a skin into the button the text disappeared. so i created a label inside the skin so the text is displayed. Is there a way to pass the value of the label in skin into the button's label property? - Mirage01

I can only repeat: you shouldn't do this. If you absolutely have to: dispatch a custom event carrying the data. But I strongly advise against it. - RIAstar

You can store the button itself in the array, instead of its label. That would be unique. You can still retrieve its label whenever you need it. - RIAstar

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.