A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Duplicate variable definition

  1. #1
    Junior Member
    Join Date
    Jan 2005
    Posts
    11

    Duplicate variable definition

    I am having a problem with creating new textfields.
    With a simple curAttraction (it is 1 or 3 defined before) I defined the amount of textfields I need to display texts.
    But with the code below, I am having a warning (ok, it will run, but i want to clean this up): Warning: 3596: Duplicate variable definition
    I assigned the rows with this warning.

    Code:
    if (curAttraction == 1)
    {
    	var textField1:TextField = new TextField();
    	var textField2:TextField = new TextField();
    	var textField3:TextField = new TextField();
    	var textField4:TextField = new TextField();
    	var targetFields:Array = [textField1,textField2,textField3,textField4];
    }
    else if (curAttraction == 3)
    {
    	var textField1:TextField = new TextField(); // warning
    	var textField2:TextField = new TextField(); // warning
    	var textField3:TextField = new TextField(); // warning
    	var textField4:TextField = new TextField(); // warning
    	var textField5:TextField = new TextField();
    	var textField6:TextField = new TextField();
    	var textField7:TextField = new TextField();
    	var textField8:TextField = new TextField();
    	var textField9:TextField = new TextField();
    	var textField10:TextField = new TextField();
    	var targetFields:Array = [textField1,textField2,textField3,textField4,textField5,textField6,textField7,textField8,textField9,textField10]; // warning
    }
    var targetFieldsLength = targetFields.length;
    
    var j:int;
    for (j = 0; j < targetFieldsLength; j++)
    {
    	targetFields[j].defaultTextFormat = textFormat;
    	targetFields[j].width = 500;
    	targetFields[j].height = 500;
    	targetFields[j].border = false;
    	targetFields[j].wordWrap = true;
    	targetFields[j].x = 70;
    	targetFields[j].y = 400;
    	targetFields[j].alpha = 0;
    	targetFields[j].embedFonts = true;
    }
    
    if (curAttraction == 1)
    {
    	textField1.text = "test start\n...";
    	textField2.text = "test\n...";
    	textField3.text = "test\n...";
    	textField4.text = "test end.";
    }
    else if (curAttraction == 3)
    {
    	textField1.text = "test start\n...";
    	textField2.text = "test\n...";
    	textField3.text = "test\n...";
    	(..)
    	textField10.text = "test end.";
    }
    Someone who knows the problem and how to solve?

  2. #2
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    You declare the variable only once the first time
    var textField1:TextField = new TextField();
    and after that you refer to it as
    textField1 = new TextField();
    - The right of the People to create Flash movies shall not be infringed. -

  3. #3
    Junior Member
    Join Date
    Jan 2005
    Posts
    11
    But is that not weird?
    If curAttraction == 3, I never reach to the var textField1 in the first if statement (from curAttraction == 1).
    Then the first 'var textField1' isn't declared yet.
    Last edited by dragonlau; 12-10-2012 at 12:55 PM.

  4. #4
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    When you compile your movie the compiler reads the whole script and then throws an error.
    - The right of the People to create Flash movies shall not be infringed. -

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center