Вопрос

thank you for your time.

I have 2 labels with numerical values i would like to add together.

<s:Label id="cost_1" x="261" y="138" text="150" />
<s:Label id="cost_2" x="280" y="138" text="220"/>
<s:Label id="totals" x="291" y="138" text=""/>

I need to the third label (id="totals") to visually display the sum of first two labels. (150+220=totals.text)

Thank you!

Это было полезно?

Решение

Lots of ways to do this; but given your code the simplest way would be something like this:

<s:Label id="totals" x="291" y="138" text="{int(cost_1.text) + int(cost_2.text)}" />

Although the labels may display numeric values; they are actually string values; so this code casts them to ints. From there, it's just a simple arithmetic operation.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top