Skip to main content
Known Participant
August 6, 2013
Answered

Function not returning the right value

  • August 6, 2013
  • 1 reply
  • 671 views

Hi, I'm having a strange problem and am hoping someone knows how to fix it....

I'm trying to send a string to a function in another class and have it return it in a textfield, so I can add it to a movieclip and to the stage. I am using it for several buttons.The problem is when I put a string value in it returns a string value for the previous call to the function which is not the string value I want to use. Here's the function:

public function replaceMCTxt( mcString:String, xPos:Number,

                                                                                           yPos:Number, Width:uint, Height:uint, newFontSize:uint, rolloverText:Boolean = false):TextField {

                                                  var newMCTxt:TextField = new TextField();

                                                  newMCTxt.x = xPos;

                                                  newMCTxt.y = yPos;

                                                  newMCTxt.width = Width;

                                                  newMCTxt.height = Height;

                                                  var textFormat:TextFormat = new TextFormat();

 

                                                  textFormat.align = _gameModel.screenFontAlign;

 

                                                  textFormat.size = newFontSize;

                                                  textFormat.font = _gameModel.screenFont;

                                                  textFormat.color = _gameModel.screenFontColor;

                                                  newMCTxt.defaultTextFormat=textFormat;

 

                                                  newMCTxt.text = _languageClass.getTranslation(mcString);

                                                  newMCTxt.selectable = false;

                              return newMCTxt;

                    }

i'm trying to call it with this statement in another class:

_moreGamesTxtField = _updateLanguageClass.

                                        replaceMCTxt("MORE GAMES", _gameModel.moreGamesTxtXPos,

                                                                       _gameModel.moreGamesTxtYPos, _gameModel.moreGamesTxtWidth,

                                                                       _gameModel.moreGamesTxtHeight, _gameModel.moreGamesTxtFontSize);

Instead of giving me a "MORE GAMES" movieclip it gives me a "PLAY" movieclip which is what the previous call to the function used. I also had a similar problem in another function where it was doing the same thing with filtering different buttons, so I think the problem is in the function ,but I'm not a good enough programmer to know what it is. If anyone has an idea please let me know. Thank you.....

This topic has been closed for replies.
Correct answer Ned Murphy

Start the investigation by using the trace() function to see what value is being passed to and returned by whatever _languageClass.getTranslation() is.

1 reply

Ned Murphy
Ned MurphyCorrect answer
Legend
August 6, 2013

Start the investigation by using the trace() function to see what value is being passed to and returned by whatever _languageClass.getTranslation() is.

Known Participant
August 6, 2013

Ok, I figured it out, it was not returning the correct value from the _languageClass.getTransation(). I had to fix the _languageClass. Thanks

Ned Murphy
Legend
August 6, 2013

You're welcome