A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: Trouble with delaying of showing a textbox.

  1. #1
    Junior Member
    Join Date
    Mar 2013
    Posts
    5

    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!

  2. #2
    Dignitary rynoe's Avatar
    Join Date
    Jan 2003
    Location
    Earth
    Posts
    760
    PHP Code:
    myTimer = new Timer(1000,20);
    stop();
    cover.visible=true;
     
    import flash.events.MouseEvent;

     function 
    onClick(event:MouseEvent):void
     

     var 
    nRandom Math.floor(Math.random() * 7);
     
    gotoAndStop(nRandom);
     
    myTimer.start();
     }
     
    proceed.addEventListener(MouseEvent.CLICKonClick);

     function 
    frameNumberText(event:Event):void
     

     var 
    frames:Number;
     
    frames=currentFrame;
     
    textBox.text = (String(frames)); 
     } 
     
    textBox.addEventListener(Event.ENTER_FRAMEframeNumberText);
    myTimer.addEventListener(TimerEvent.COMPLETEtimeOut)

    function 
    timeOut(t:TimerEvent):void{
      
    cover.visible=false;

    [SIGPIC][/SIGPIC]

  3. #3
    Junior Member
    Join Date
    Mar 2013
    Posts
    5

    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...

  4. #4
    Dignitary rynoe's Avatar
    Join Date
    Jan 2003
    Location
    Earth
    Posts
    760
    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 Math.floor(Math.random() * 7); 
     
    gotoAndStop(nRandom); 
     
    myTimer.start(); 
     } 
     
    proceed.addEventListener(MouseEvent.CLICKonClick); 

     function 
    frameNumberText(event:Event):void 
     
    {  
     var 
    frames:Number
     
    frames=currentFrame
     
    textBox.text = (String(frames));  
     }  
     
    textBox.addEventListener(Event.ENTER_FRAMEframeNumberText); 
    myTimer.addEventListener(TimerEvent.TIMER_COMPLETEtimeOut

    function 
    timeOut(t:TimerEvent):void
      
    cover.visible=false

    Last edited by rynoe; 03-29-2013 at 01:11 PM. Reason: WRONG
    [SIGPIC][/SIGPIC]

  5. #5
    Junior Member
    Join Date
    Mar 2013
    Posts
    5

    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!

  6. #6
    Registered User
    Join Date
    Apr 2013
    Posts
    2
    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
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center