A Flash Developer Resource Site

Results 1 to 20 of 20

Thread: Creating random pop up quiz / message and pausing a video

  1. #1
    Junior Member
    Join Date
    May 2010
    Posts
    11

    Creating random pop up quiz / message and pausing a video

    Hi all,

    I need some assistance on creating some feature in my video.

    Here's what I would like to achieve:
    While a video is playing, I want to create a randomly pop up message / quiz that needs user to make a selection or hit OK. When the message / quiz pop up, the video would be stopped at that point in time and after user make the selection or hit OK, the video would resume playing.

    Is this a very very difficult action script?

    Could someone please kindly provide some assistance here?

    Thanks!

  2. #2
    Senior Member
    Join Date
    Mar 2010
    Posts
    157
    Quote Originally Posted by funnysora View Post
    While a video is playing, I want to create a randomly pop up message / quiz that needs user to make a selection or hit OK.
    When the message / quiz pop up, the video would be stopped at that point in time and after user make the selection or hit OK, the video would resume playing.
    Alright. do you want pop-ups to appear at a random intervals?
    i would recommend something like this:

    ___
    Actionscript Code:
    var myInt:Number = random(*any number 1*) + *any number 2* /*this creates a variable called 'myInt' with a value of *any number 2* + something between 0 and *any number 1* */

    var current:Number = 0;

    _root.onEnterFrame = function(){
    if(current < myInt){
    current += 1/12;
    }else{
    popup();
    }
    }

    function popup():Void{
    _root.stop();
    duplicateMovieClip(myMc_mc, *any level*, 'popup_mc');
    popup_mc.onEnterFrame = function(){
    this.onMouseUp = function(){
    if(this.okay_btn.rollover == true){
    confirm();
    }
    }
    }
    }


    function confirm():Void{
    current = 0 // if you want to repeat the popup only!!
    _root.play();
    }
    ____

    does this satisfy you? Of course, it might need just a little debugging (i do not have flash at hand right now, so i couldn't check it for mistakes...)

    Cheers!

    KoenAhn

  3. #3
    Junior Member
    Join Date
    May 2010
    Posts
    11
    Hi!! Thanks so much, I am so excited to see if it works!!
    But I am novice so there are some parts I dont quite understand:

    1) var myInt:Number = random(*any number 1*) + *any number 2*
    What does it really means? My whole movie clip span to frame 2510. Why is there a "+" and not just simply random(*a number*)?

    2) duplicateMovieClip(myMc_mc, *any level*, 'popup_mc');
    What does this do? My movie clip name is judy1.

    Hmm... yes, I may need a pop up to appear again as the movie progresses after the first pop up.

    Thanks so much again. I am going to try to see if I know how to change to fit my movie clip.



    Quote Originally Posted by koenahn View Post
    Alright. do you want pop-ups to appear at a random intervals?
    i would recommend something like this:

    ___
    Actionscript Code:
    var myInt:Number = random(*any number 1*) + *any number 2* /*this creates a variable called 'myInt' with a value of *any number 2* + something between 0 and *any number 1* */

    var current:Number = 0;

    _root.onEnterFrame = function(){
    if(current < myInt){
    current += 1/12;
    }else{
    popup();
    }
    }

    function popup():Void{
    _root.stop();
    duplicateMovieClip(myMc_mc, *any level*, 'popup_mc');
    popup_mc.onEnterFrame = function(){
    this.onMouseUp = function(){
    if(this.okay_btn.rollover == true){
    confirm();
    }
    }
    }
    }


    function confirm():Void{
    current = 0 // if you want to repeat the popup only!!
    _root.play();
    }
    ____

    does this satisfy you? Of course, it might need just a little debugging (i do not have flash at hand right now, so i couldn't check it for mistakes...)

    Cheers!

    KoenAhn

  4. #4
    Junior Member
    Join Date
    May 2010
    Posts
    11
    Hi KoenAhn,

    I just tried, I think it's because I did not change the code correctly and that was why it didnt work for me, did not see pop up. Do I have to create any sort of HTML script or this is all within Flash?

    Sorry... a very novice in flash.

    ------------------------------------

    var myInt:Number = random(200) + 400 /*this creates a variable called 'myInt' with a value of *any number 2* + something between 0 and *any number 1* */

    var current:Number = 0;

    _root.onEnterFrame = function(){
    if(current < myInt){
    current += 1/12;
    }else{
    popup();
    }
    }

    function popup():Void{
    _root.stop();
    duplicateMovieClip(judy1, judy2, 'popup_mc');
    popup_mc.onEnterFrame = function(){
    this.onMouseUp = function(){
    if(this.okay_btn.rollover == true){
    confirm();
    }
    }
    }
    }


    function confirm():Void{
    current = 0 // if you want to repeat the popup only!!
    _root.play();
    }

  5. #5
    Senior Member
    Join Date
    Mar 2010
    Posts
    157
    hi!

    i'm sorry it didn't work properly, i couldn't check it because i was at school.

    here's the code as it works ;D

    Actionscript Code:
    var myInt:Number = random(3) + 2 /*this creates a variable called 'myInt' with a value of *any number 2* + something between 0 and *any number 1* */

    var popped:Boolean = false;
    var current:Number = 0;

    _root.onEnterFrame = function(){

        if(current < myInt){
            current += 1/12;
        }else{
            if(popped == false){
                popup();
                popped =  true;
            }
        }
       
        if(popped){
            popup_mc.onMouseUp = function(){
                popup_mc.okay_btn.onRollOver = function(){
                    confirm();
                    _root.popup_mc.removeMovieClip();
                    popped = false;
                }
            }
        }
    }

    function popup():Void{
        _root.stop();
        duplicateMovieClip(_root.judy1_mc, "popup_mc", 12);
        //trace("just popped up");
        popup_mc._x = 200;
        popup_mc._y = 150;
    }

    function confirm():Void{
    current = 0 // if you want to repeat the popup only!!
    _root.play();
    }

    and no, you will never need html or any other language withing flash. html is used to create a website layout and not to make the user interact with objects.
    Last edited by koenahn; 06-03-2010 at 01:06 PM.

  6. #6
    Junior Member
    Join Date
    May 2010
    Posts
    11
    Hi Koenahn,

    Thanks so much for the code! But... somehow it is not working for me... Sorry about that.

    Do I have to change the # in the random function?

    By the code, what is popping up? I did not see any message box popping up.

    Thanks again!

  7. #7
    Senior Member
    Join Date
    Mar 2010
    Posts
    157
    okay so what you do is make your movie
    and place a movieclip on the stage (outside of the visible bit) go to the property inspector ("properties" pannel) and name it "judy1_mc". inside it, make a button and call it "okay_btn" the same way you did your movieclip.
    then paste the code i made on the 1st frame of a layer called "AS" (for actionscript, but it can be anything, this is just handy) and really it should work. ik works for me.

    if you have any other questions don't hesitate to ask.

  8. #8
    Junior Member
    Join Date
    May 2010
    Posts
    11
    Hi koenahn,

    Thanks for patience.

    Ok, just to make sure I understand what to do:

    I have currently 3 layers now, 1 is the layer for the movie clip (judy1_mc), 1 is the layer for my 2 play / pause button and the last one is for action scripts.

    Where should I create an "okay" button? in the same layer as the movie clip?

    I have a question too, does the movie clip pause when the pop up shows? I would need the movie clip to pause until the user hit "Ok", then the movie will resume.

    Thanks!!
    Attached Images Attached Images
    Last edited by funnysora; 06-03-2010 at 02:51 PM. Reason: added a print screen

  9. #9
    Senior Member
    Join Date
    Mar 2010
    Posts
    157
    ah! i understand why you don't get what i mean. see, this is a bit complicated, but like the main timeline with the flash video, objects like movieclips also have a timeline, that's why you can put movieclips inside of other movieclips. so what you do is right-click on your judy1_mc and choose "edit" (or you can double-click judy1_mc, that's the same). this will bring you into judy's own timeline. inside judy, you add a layer with the a btn called "okay_btn"

    what my function does is as follows:


    ___


    every frame, i check if a random time (myInt) has passed. if the time has passed, i tell flash to execute the function called "popup()" and i tell flash that there's a pop-up in the window (boolean "popped" being true). also, i make the movie stop.
    i tell flash that when the user presses the "okay_btn" that's inside the popup (judy1_mc), the popup should disappear, there is no longer a pop-up (boolean "popped" = false) and i tell flash to execute the function "confirm()".
    what popup() does is basicly that it duplicates judy, names the copy of judy "popup_mc" and says that it should be placed at (200, 150) on the stage (these are _x and _y values). what confirm() does is that it makes sure the random time will pass agian, and also it will make the movie play again.
    I just realised that it would be better if you added this line to confirm(): "myInt = random(3) + 2;". this makes sure that the pop-ups won't appear at the same random interval all the time.

    of course, the 3 and 2 (also seen at the very beginning of the as-code) can be anything. the 2 is the minimum number of seconds before the popup appears, the 3 stands for the idea that a number between 0 and 3 will be added to the 2 (which is the minimum).

  10. #10
    Junior Member
    Join Date
    May 2010
    Posts
    11
    OK! Does the button layer inside Judy's timeline has to be on top of the movie or below?
    If I put the button layer on top, after I click out of Judy's timeline, the button show up on the stage.

  11. #11
    Junior Member
    Join Date
    May 2010
    Posts
    11
    Thanks Koenahn for his help!

    I just have 1 more question to make my project works.

    In my movie clip timeline (the timeline for the movieclip itself, not the root timeline), I added a button. I want to make this button not visible when the movie starts.

    No matter how and where I put the button._visible=false, it never works. The button always shows up when I preview.

    Any idea how to go about making this embedded button not visible when the movie clip starts??

    Thanks!!!

  12. #12
    Senior Member
    Join Date
    Mar 2010
    Posts
    157
    even if you put it outside of the stage, you will still see the movieclip of the popup in the preview. that's because in the preview, you see more than you are supposed to see. if you'd go to the location of your flash movie and watch the swf-file, you won't see it.

  13. #13
    Junior Member
    Join Date
    May 2010
    Posts
    11
    Hey Koenahn!

    I changed the code you provided me! because of the sound in the video etc, I don't know how to make the duplicatemovieclip works correctly to turn off the sound when the popup is showing.

    using your code, I changed to the following idea:

    var myInt:Number = random(15)+2;
    /*this creates a variable called 'myInt' with a value of *any number 2* + something between 0 and *any number 1* */
    var popped:Boolean = false;
    var current:Number = 0;

    _root.onEnterFrame = function() {
    if (current<myInt) {
    current += 1/12;
    } else {
    if (popped == false) {
    popup();
    popped = true;
    }
    }

    The above is same as before! but the popup function:

    function popup():Void {
    _root.judy1_mc.stop();
    okay_btn._visible = true;
    judy1_mc._visible = false;
    }

    Until here, it works fine. At the random time, the popup function tells the movie to stop, hide the movie, show the button.

    But the next step just cannot work... When user click the Okay_Btn, I just need the movie to show again and the button to hide again, but that never happen.........

    if (popped) {
    _root.okay_btn.onRelease = function () {
    _root.judy1_mc.play();
    _root.judy1_mc._visible = true;
    popped = false;
    }
    }
    }

    I guess I pretty much know why, is it because of the onRelease event most likely... but I just cant find a better way to do it...

    Have been pulling my hair over this thing for the past 2 days........

    Any suggestion whats happening here?

    Thanks!!!

  14. #14
    Senior Member
    Join Date
    Mar 2010
    Posts
    157
    you should put that bit of code inside of an onEnterFrame. Make sure however that you only have one onEnterFrame per object. For instance:

    onEnterFrame=function(){eat-an-apple();}
    onEnterFrame=function(){jump();}

    wont work. flash will only eat-an-apple(), not jump().
    but this works:

    onEnterFrame = function(){eat-an-apple();}
    john_mc.onEnterFrame = function(){jump();}

    this means that every time _root (the main timeline) enters a frame, flash will eat-an-apple() and every time john_mc enters a frame, flash will execute jump().


    if putting the bit of code inside of the onEnterFrame still won't work, try using _alpha = 0 inistead of _visible = false. Sometimes _visible = false gets messy somehow.

  15. #15
    Junior Member
    Join Date
    May 2010
    Posts
    11
    Oh well... Kinda upset, I think I am heading the wrong direction somehow.

    The code actually works (or appears to work correctly). But I just realized that when I stop the video, it doesnt actually stopped the video at all, the video or timeline actually still continues to play until it reaches the last frame.

    Why I said that is because:

    I previewed the flash movie, when the random pop up showed up, I did not hit the okay_btn, I just leave it there, so that the video does not resume. When I came back after a while, I realized that the timeline has reached the last frame and the video has ended. (This is because I added at the last frame a word on stage that said "End")

    So... somehow I managed to "stopped" the video, but the timeline is still running...

    I am totally lost. I thought by controlling the video I am controlling the time line...

  16. #16
    Senior Member
    Join Date
    Mar 2010
    Posts
    157
    hang on, did you put the actionscript in the frame, not the object?
    strage.
    try changing _root.judy_mc.stop(); into _root.stop(); ...?
    maybe you simply never declared your judy's name in the property panel?

  17. #17
    Junior Member
    Join Date
    May 2010
    Posts
    11

    Unhappy

    Hi Koenahn,

    Thanks.
    I have a layer called "AS" for actionscript, so yea, I put most actions in frame, except for the okay_btn of cos, I had that on the button itself.

    Those actionscripts in the frame, I had "_root" added. But my play and pause buttons, did not have. Still, it should work, but anyhow, I just included that to make sure.

    Somehow I dont understand, if it can start and stop the video, that means the code works at targetting the video, but why would the timeline still continue to run when the video is paused?

    Was it the way I imported the video? I had imported it as movie clip. There is another way to import it as "current timeline". I tried that, but somehow, the play and pause buttons did not work on this imported video...

    Dont know what's happening...

    Quote Originally Posted by koenahn View Post
    hang on, did you put the actionscript in the frame, not the object?
    strage.
    try changing _root.judy_mc.stop(); into _root.stop(); ...?
    maybe you simply never declared your judy's name in the property panel?

  18. #18
    Senior Member
    Join Date
    Mar 2010
    Posts
    157
    well, if you want to pause your movie clip, say "_root.judy_mc.stop();" and if you want to stop the main time line, say "_root.stop();"

  19. #19
    Junior Member
    Join Date
    May 2010
    Posts
    11
    Ok. What is the difference between the 2?
    Does it mean that pausing will not pause the timeline??
    Sorry just curious.
    Thanks!

  20. #20
    Senior Member
    Join Date
    Mar 2010
    Posts
    157
    Quote Originally Posted by funnysora View Post
    Does it mean that pausing will not pause the timeline??
    There is not ONE timeline. there is ONE _root timeline, the main timeline. but if your movie is inside of an MC, you obviously have at least 3 timelines (counting the button in).
    _root.stop(); pauses the main timeline (_root).
    _root.ANYMOVIECLIP_mc.stop(); pauses the timeline of ANYMOVIECLIP_mc.

    and don't apologise ;D

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