1
votes

To start off, I am quite new at Actionscipt, so please bear with me. I am trying to make a text field that changes as the variable date goes up. This is my coding (it is on a layer):

var day:int = 1;
var date:TextField = new TextField();
if (day = 1) date.txt = "August 1";
if (day = 2) date.txt = "August 2";
date.x = 548.1
date.y = 58.5

var format: TextFormat = new TextFormat
format.color = 0xFFFFFF;
format.font = "Constantia";
format.bold = false
txt.setTextFormat( format);

 stage.addChild(date)

I am getting errors for this however, and I am confused as to why. The error is this:

1151: A conflict exists with definition date in namespace internal. Source: var date:TextField = new TextField();

Again, I am new at all of this, and I would appreciate any help at all. Thank-you.

(Edit)

I've fixed these problems, and given my textfield the instance name dateTextField. The coding is now:

var day:int = 1;

var dateTextField:TextField = new TextField();
if (day == 1) dateTextField.text = "August 1";
if (day == 2) dateTextField.text = "August 2";
dateTextField.x = 548;
dateTextField.y = 58;

var format: TextFormat = new TextFormat ();
format.color = 0xFFFFFF;
format.font = "Constantia";
format.bold = false;
txt.setTextFormat( format);

 stage.addChild(dateTextField);

Yet I still get the same error?

1151: A conflict exists with definition dateTextField in namespace internal.

Source: var dateTextField:TextField = new TextField();

4
It seems you may have a previously created variable called date. - Marty
As a side note: you should use integer values for x and y coordinates - this is to avoid weird anti-aliasing effects. - strah
You are mixing and matching names, there's a confusion between date, txt, and now dateTextField. You're also using the property txt instead of text. Consider rewritting the code from scratch and try to make it work one line at a time. - laurent

4 Answers

2
votes

Most likely, you have already defined date somewhere else. Rename the variable to something more specific, for example dateTextField.

0
votes

You are missing some colons and an ='s sign. change this var format: TextFormat = new TextFormat format.color - 0xFFFFFF; to

var format: TextFormat = new TextFormat();
format.color = 0xFFFFFF;

and also check that at the end of each line you are have a ";" I can see one other line that is missing the ;

0
votes

lines 3 and four should be:

if (day == 1) dateTextField.text = "August 1";

if (day == 2) dateTextField.text = "August 2";

  1. if you use only one "=" instead of two "==" you will assign the value instead of checking it.
  2. you used date again and only changed it in the first line
  3. the member to set text is not "txt" but "text"
0
votes

Wow, I just realized how complicated I was making this all. I simply named the text field date, set my font and size there, and made my coding:

var day:int = 1;

if (day==1) date.text = "July 1";

But thank-you for your help, it helped me see the coding in a new light.