• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Using variables to add and subtract a number in a text field?

Engaged ,
Jan 22, 2014 Jan 22, 2014

Copy link to clipboard

Copied

The adding bit works fine:

// get this pconn count

var this_p_conn:Number = Object(this).parent.p_conn;

// get current pconn total

var c_this_p_conn:Number = Object(root).part_count.p_conn_count.text    

                                                                                                                                            

// add this pconn count to total pconn

var v_this_p_conn:Number = Number(this_p_conn+c_this_p_conn);

// Update total pconn with new value

Object(root).part_count.p_conn_count.text = String(v_this_p_conn)

Removing a value from the total is another story, this looks like it should work but it does not:

// get this pconn count

var count_p_conn:Number = Object(this).parent.p_conn;

// get current pconn total

var total_p_conn:Number = Object(root).part_count.p_conn_count.text;

// subtract this pconn count from total pconn

var new_p_conn:Number = Number(total_p_conn-count_p_conn);

// Update total pconn with new value

Object(root).part_count.p_conn_count.text = String(new_p_conn);

Any ideas or suggestions? My eyes are a bit blurry from looking at code, maybe I missed something obvious. Thanks in advance!

TOPICS
ActionScript

Views

766

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jan 22, 2014 Jan 22, 2014

Copy link to clipboard

Copied

LATEST

Never mind, I got it worked out now.

I had the subtraction code firing AFTER my remove self code, so the player never got to fire the subtract code:

var b:MovieClip = Object(this).parent;

Object(this).parent.parent.removeChild(b);

I placed the subtract code before the above code and now it works fine... I think I need powernap...

The lesson here is that apparently code fires from the top to the bottom, mind the order of how your code is stacked.

Sorry for the fuss! Carry on.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines