-
Trouble with delaying of showing a textbox.
I have a scene with a question in every frame and a button that takes me to a random next frame and a textbox showing the current frame i'm in. This is my actions for it:
stop();
import flash.events.MouseEvent;
function onClick(event:MouseEvent):void
{
// generate a random number from 1 to 3
var nRandom = 1 + Math.floor(Math.random() * 7);
// tell timeline to goto and play the random number 'nRandom'
gotoAndStop(nRandom);
}
proceed.addEventListener(MouseEvent.CLICK, onClick);
//shows current frame
function frameNumberText(event:Event):void
{
var frames:Number;
frames=currentFrame;
textBox.text = (String(frames));
}
textBox.addEventListener(Event.ENTER_FRAME, frameNumberText);
what I want is, in every frame there should be an answer showing after 20 sec. Or by clicking "show answer" the answer appears. But i want it in the main action and one code referring to all answers to show.
Just came to think of having the answer behind the background and having the background brought back in the scene. one code and one object being used. But the background settings should restart at every click of the random button.
Please help! I'm quite a novice at flash and need clear instructions.
/Thanks!
-
Dignitary
PHP Code:
myTimer = new Timer(1000,20);
stop();
cover.visible=true;
import flash.events.MouseEvent;
function onClick(event:MouseEvent):void
{
var nRandom = 1 + Math.floor(Math.random() * 7);
gotoAndStop(nRandom);
myTimer.start();
}
proceed.addEventListener(MouseEvent.CLICK, onClick);
function frameNumberText(event:Event):void
{
var frames:Number;
frames=currentFrame;
textBox.text = (String(frames));
}
textBox.addEventListener(Event.ENTER_FRAME, frameNumberText);
myTimer.addEventListener(TimerEvent.COMPLETE, timeOut)
function timeOut(t:TimerEvent):void{
cover.visible=false;
}
-
Couldn't get it to work...
Thanks Rynoe, but I could not get it to work.
I got an error message saying:
Scene 1, Layer 'Actions', Frame 1, Line 21 1120: Access of undefined property myTimer.
Scene 1, Layer 'Actions', Frame 1, Line 21 1119: Access of possibly undefined property COMPLETE through a reference with static type Class.
Tried to use another movie-clip as myTimer. What to use?
and by this:
cover.visible=true;
do you mean that "cover" is the object covering the answer textbox? tried to make a symbol and give it instancename cover but it did not work. Neither a bitmap.
Told you I was a noobie on this...
-
Dignitary
That's because my code was WRONG!
WRONG WRONG WRONG!
SHAME!
I fixed it.
PHP Code:
var myTimer:Timer = new Timer(1000,20); stop(); cover.visible=true; import flash.events.MouseEvent;
function onClick(event:MouseEvent):void { var nRandom = 1 + Math.floor(Math.random() * 7); gotoAndStop(nRandom); myTimer.start(); } proceed.addEventListener(MouseEvent.CLICK, onClick);
function frameNumberText(event:Event):void { var frames:Number; frames=currentFrame; textBox.text = (String(frames)); } textBox.addEventListener(Event.ENTER_FRAME, frameNumberText); myTimer.addEventListener(TimerEvent.TIMER_COMPLETE, timeOut)
function timeOut(t:TimerEvent):void{ cover.visible=false; }
Last edited by rynoe; 03-29-2013 at 01:11 PM.
Reason: WRONG
[SIGPIC][/SIGPIC]
-
It works!! Thank you very much!
It works! Thank you. I could not have done it without you!
Although, I wanted the timer and the cover to reset at every time I clicked the button. Solved it by inserting both the cover.visible=true; and a timer-reset into the onClick function, like below.
function onClick(event:MouseEvent):void
{
var nRandom = 1 + Math.floor(Math.random() * 7);
gotoAndStop(nRandom);
myTimer.reset();
myTimer.start();
cover.visible=true;
}
proceed.addEventListener(MouseEvent.CLICK, onClick);
Thank you, again!
-
Thanks for sharing info guys!!!...really helpful!!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|