开发者

display variable value, flash actionscript

I'm building a very simple questionnaire in flash cs5. My timeline consists of an intro frame, three question frames and a results frame. Each of the question frames allows the users to select 1 of 5 answers choices (buttons) and then proceeds to the next question. I want to capture their button selection, store it in a variable and display it on the results page.

I placed the following actionscript below on each question frame (variable names ch开发者_开发技巧ange accordingly ie secondq, thirdq, a_second, a_third..) to capture the user's anwser. Then in the results frame, I created a text box for each anwser, made it dynamic, and set the variable name (firstq, secondq, thridq) as the value. The variables only appear in the results frame if I select the first button for each question, all other answers are not appearing in the results frame. Any help would be appreciated.

question frames:

var firstq:int = 0;

        a_first.onRelease = function () 

        { 

        firstq = 1;
        gotoAndPlay(30);

        };

        b_first.onRelease = function () 

        { 

        firstq = 2;
        gotoAndPlay(30);

        };



        c_first.onRelease = function () 
        { 
        firstq = 3;
        gotoAndPlay(30);

        } ;


        d_first.onRelease = function () 
        { 
        firstq = 4;
        gotoAndPlay(30);

        } ; 


        e_first.onRelease = function () 
        { 
        firstq = 5;
        gotoAndPlay(30);


        } ; 

results frame

stop();
trace(firstq);
trace(secondq);
trace(thirdq);


firstq = resA.text;
secondq = resB.text;
thirdq = resC.text;


I've never really added ActionScript to the frame but rather linked AS pages to the whole FLA but I thought I'd chime in and see if I could help. It looks like your initialization of firstq, secondq...lastq is on it's corresponding page. Because of this I think you may be losing its value when you leave the page. Something you can try doing is creating another layer and adding a slide that persists over all of the frames. Add your text fields to this so that they're on all of the frames. On the frames that you don't want them displayed you can just change their visibility. Now, when you need to change their value you can just say myTextField.text = "some text".


Following your description, I don't see any reason why it doesn't work. You could start by tracing the results of the different questions in your results frame:

     trace( firstq, secondq , etc... );

then you could also test your TextField instances, in the results frame:

    trace( tfInstance1 , tfInstance1.text , etc... );

if all of the above is working , check if you've correctly embed the fonts in your TextFields. Now if it's all working... maybe a stop(); statement on the last frame...


Looks like your results frame is assigning the values backwards!

instead of firstq = resA.text;

you want

resA.text = firstq;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜