cdeforge
asked on
Button text appears at the cost of knowing which answer was clicked
The code runs fine, but the problem I'm having is that the text box that is suppose to go onto of my answer buttons is behind the button itself... however, if I change two lines of code around, the answer validation code doesn't pick up the which answer was clicked (it returns undefined). This is infuriating!
Look for the line "//INSERT HERE." If I take the line, "var answerField:TextField = createText(answer,answerFo rmat,answe rSprite,0, 0,450);" and put it there instead, it returns the right answers (doesn't return undefined), but I can no longer see the text. I've included the createText function as well.
Ideas?
If uploading a .zip of the project would really help, I can arrange for that.
Look for the line "//INSERT HERE." If I take the line, "var answerField:TextField = createText(answer,answerFo
Ideas?
If uploading a .zip of the project would really help, I can arrange for that.
private function askQuestion()
{
trace("asking question...");
// prepare new question sprite
qBox = new QuestionBox();
questionSprite = new Sprite();
gameSprite.addChild(qBox);
gameSprite.addChild(questionSprite);
qBox.x = 240;
qBox.y = 45;
// create text field for question
var question:String = dataXML.item[questionNum].question;
questionField = createText(question,questionFormat,questionSprite,120,30,250);
// create sprite for answers, get correct answer and shuffle all
correctAnswer = dataXML.item[questionNum].answers.answer[0];
trace("----" + correctAnswer + "----");
answers = shuffleAnswers(dataXML.item[questionNum].answers);
// put each answer into a new sprite with a circle icon
answerSprites = new Sprite();
for (var i:int=0; i<answers.length; i++)
{
trace("generating answers...");
switch (i)
{
case 0 :
column = 135;
row = 150;
break;
case 1 :
column = 135;
row = 260;
break;
case 2 :
column = 340;
row = 150;
break;
case 3 :
column = 340;
row = 260;
break;
}
var answer:String = answers[i];
var answerSprite:Sprite = new Sprite();
//INSERT HERE
var button:Button = new Button();
answerSprite.addChild(button);
answerSprite.x = column;
answerSprite.y = row;
//TAKE THE LINE BELOW
var answerField:TextField = createText(answer,answerFormat,answerSprite,0,0,450);
answerSprite.addEventListener(MouseEvent.CLICK,clickAnswer);
answerSprite.buttonMode = true;
answerSprites.addChild(answerSprite);
}
trace("answers generated!");
questionSprite.addChild(answerSprites);
trace("question asked!");
trace(":::awaiting user input:::");
}
public function createText(text:String, tf:TextFormat, sprite:Sprite, x,y: Number, width:Number):TextField
{
var tField:TextField = new TextField();
tField.x = x;
tField.y = y;
tField.width = width;
tField.wordWrap = true;
tField.multiline = true;
tField.selectable = false;
tField.defaultTextFormat = tf;
tField.text = text;
sprite.addChild(tField);
return tField;
}
ASKER
Woah, nice trick there. Here you go! The file in question is test.as and the issue is around line 195. You can just control+f "Insert the line" and you should find it.
brainbuster.png
brainbuster.png
Sorry cdeforge,
I forgot to mention I am using CS4 can you export your FLA to CS4 and you will able to upload FLA into this thread without my trick :)
I forgot to mention I am using CS4 can you export your FLA to CS4 and you will able to upload FLA into this thread without my trick :)
ASKER
No problem, here you go.
BrainBuster.fla
BrainBuster.fla
Nice, one more request can you create a screenshot of your problem I don't know where exactly I need to look your textbox (may be you can draw a line using MS Paint Brash or SnagIt)
By the way what is better do not answer on any questions (timeout) and get 0 score or provide wrong answers and get -600 :)
ASKER
Okay, in the image, you see how in the top picture the button names are there but when I click it the answer validation comes back and say's the answer was undefined? It's not seeing what button I've clicked for some reason...
If you take that line of code that's commented on, and then move it up to where it says to insert it, you'll get what happens in the bottom frame. The text won't appear any longer, but the answer actually validates. In this instance, I got it right.
Yeah, the scoring isn't right by any means, lol. But I figured I'd tackle this issue first then move on to proper scoring.
example.jpg
If you take that line of code that's commented on, and then move it up to where it says to insert it, you'll get what happens in the bottom frame. The text won't appear any longer, but the answer actually validates. In this instance, I got it right.
Yeah, the scoring isn't right by any means, lol. But I figured I'd tackle this issue first then move on to proper scoring.
example.jpg
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Brilliant! I understand now... I'll definitely be using labels in the future. Thanks for posting the solution and explaining how to upload a .rar file as a .png as well!
Archive your project as RAR file change extension to PNG and upload to your thread.