A Flash Developer Resource Site

Results 1 to 9 of 9

Thread: Could you help me with some coding please

  1. #1
    Junior Member
    Join Date
    Apr 2009
    Location
    plymouth UK
    Posts
    20

    Could you help me with some coding please

    hello there

    please could you help me with some action script in flash 8.

    what i would like to achieve is an if statement or something similar where a user will click on the hazard button. if the user clicks on the hazard button between the cuepoints of hazard1 and hazard2 the flash will output will say "win". if the user clicks on the hazard either before the hazard1 cuepoint or after the hazard2 cuepoint the flash output will be "lose"

    if there is anything else that you need to know please post here or contact me on adey8ball@gmail.com and i will reply ASAP

    once again many thanks to all who can help

    thank you for your time

    adey


    stop();

    //button to next frame

    NxtVid.onRelease = function(){
    gotoAndStop(2);
    }

    trace("Hazard clip 1");
    var listenerObject:Object = new Object();
    listenerObject.cuePoint = function(eventObject:Object):Void {
    // Put any code you like here
    //trace("Cue point name: " + eventObject.info.name);
    //trace("Cue point type: " + eventObject.info.type);

    if(eventObject.info.name=="Hazard1")
    {
    trace("start timer")
    }
    else
    if(eventObject.info.name=="Hazard2")
    {
    trace("stop timer")
    }

    //if the hazard button is pressed between hazard1 and hazard two output "win"

    Hazardbtn.onRelease = function(){
    trace ("hazards pressed");
    }

    // if(eventObject.info.name=="Hazard2")
    //and
    //if(eventObject.info.name=="End")

    // {
    // trace ("win")
    //}
    if(eventObject.info.name=="End")
    {
    trace("Click Here for next clip")
    }

    }
    video1.addEventListener("cuePoint", listenerObject);

  2. #2
    Flash/Flex Developer samac1068's Avatar
    Join Date
    Apr 2007
    Location
    Here, no there
    Posts
    1,813

    Use a Boolean variable

    A simple method would be to use a variable to determine if a selection at this time falls within the appropriate length..all other will be considered a fail. Pulling from your code I would have the following:

    Code:
    var listenerObject:Object = new Object();
    var inBound:Boolean = false;
    
    listenerObject.cuePoint = function(eventObject:Object):Void {
       if(eventObject.info.name=="Hazard1")
       {
           inBound = true;
       }
       else if(eventObject.info.name=="Hazard2")
       {
          inBound = false;
       }
       else if(eventObject.info.name=="End")
       {
          trace("Click Here for next clip")
       }
    }
    
    Hazardbtn.onRelease = function(){
       if(inBound)
       {
            trace("You win.");
       }
       else
       {
            trace("You lose.");
       }
    }
    
    NxtVid.onRelease = function(){
       gotoAndStop(2);
    }
    
    video1.addEventListener("cuePoint", listenerObject);
    When hazard1 is cued, then the boolean variable is set to true. When hazard2 is cued, the boolean is set to false. If the button is selected while the boolean is set to true, then they win otherwise it is false.
    Some people are like Slinkies, not really good for anything, but they bring a smile to your face when pushed down the stairs.

  3. #3
    Junior Member
    Join Date
    Apr 2009
    Location
    plymouth UK
    Posts
    20
    thank you for taking the time to code that and reply.

    i tried the solution code that you helped me with and i worked perfectly for the first video.

    however when i tried to do this again to a second video on a different frame i could only get the "you lose" message. this was even between the hazard cuepoints on the second video.

    would the very helpful users of this site be able to help me code this to a second video and explain to me how to change this again for a third fourth and fifth video.

    would i be right in thinking that the variable would still be running from the first video meaning that i could not get a win message because its still running.

    any help gratefully appreciated

    adey

  4. #4
    Flashmatics silentweed's Avatar
    Join Date
    Mar 2005
    Location
    London, UK
    Posts
    4,876
    in the beginning of the other frame just put:

    inBound = false;
    Flashmatics | Flashmatics Library (free downloads)
    -----------------------------------------------------
    Latest Projects:
    The Dead Room | Are You Smarter | Prison Break (Frame A Friend) | Beck's Fusions | The 24 Experience

    -----------------------------------------------------
    Flash Certified Developer

  5. #5
    Junior Member
    Join Date
    Apr 2009
    Location
    plymouth UK
    Posts
    20
    Quote Originally Posted by silentweed View Post
    in the beginning of the other frame just put:

    inBound = false;
    thank you for taking the time to reply

    please forgive me could you explain where to put the inBound = false syntax

    possibly could you write a line of code above it and a line of code below the syntax

    many thanks

  6. #6
    Junior Member
    Join Date
    Apr 2009
    Location
    plymouth UK
    Posts
    20
    thank you

    you say to add inbound = false to the second frame of action script

    please could you suggest before/after which line of code you suggest me to add the code that has been suggested

    thank you for your time

    adey

  7. #7
    Flashmatics silentweed's Avatar
    Join Date
    Mar 2005
    Location
    London, UK
    Posts
    4,876
    not necessarily to the second frame.. im not sure how you have coded your flash movie.. u said when flash goes to another frame it then plays the second video?

    if this is the case just you just need to reset inBound = false; before the second video plays...

    so if your second video is in the second frame... just put inBound = false; right in the beginning of the actions...

    i'll need to know the code on the second frame to help u further.. is the video object still the same object i.e video1? if its something else like video2 then you will need to do:

    video2.addEventListener("cuePoint", listenerObject);

    P.S you shouldnt need to go to the second frame to play a new video... you can just use code to make your video play the next video...

    have a look at www.gotoandlearn.com for some good video tutorials on creating a video player...

    you can also download a video player from my library and see how its coded up..
    Flashmatics | Flashmatics Library (free downloads)
    -----------------------------------------------------
    Latest Projects:
    The Dead Room | Are You Smarter | Prison Break (Frame A Friend) | Beck's Fusions | The 24 Experience

    -----------------------------------------------------
    Flash Certified Developer

  8. #8
    Junior Member
    Join Date
    Apr 2009
    Location
    plymouth UK
    Posts
    20
    thank you so much for helping

    i would like to have 5 videos showing one after the other. once you have viewed on video and pressed the hazard button i want to be able to click a button that will direct the user to the second video (second frame) and the user will have to spot the hazard again.

    thank you for the offer of looking at your library

    the code from the first frame is

    stop();

    var listenerObject:Object = new Object();
    var inBound:Boolean = false;

    listenerObject.cuePoint = function(eventObject:Object):Void {
    if(eventObject.info.name=="Hazard1")
    {
    inBound = true;
    }
    else if(eventObject.info.name=="Hazard2")
    {
    inBound = false;
    }
    else if(eventObject.info.name=="End")
    {
    trace("Click Here for next clip")
    }
    }

    Hazardbtn1.onRelease = function(){
    if(inBound)
    {
    trace("You win.");
    }
    else
    {
    trace("You lose.");
    }
    }

    NxtVid1.onRelease = function(){
    gotoAndStop(2);
    }

    video1.addEventListener("cuePoint", listenerObject);



    the code from the second frame is



    stop();


    var listenerObject:Object = new Object();
    var inBound:Boolean = false;

    listenerObject.cuePoint = function(eventObject:Object):Void {
    if(eventObject.info.name=="Hazard1")
    {
    inBound = true;
    }
    else if(eventObject.info.name=="Hazard2")
    {
    inBound = false;
    }
    else if(eventObject.info.name=="End")
    {
    trace("Click Here for next clip")
    }
    }

    Hazardbtn2.onRelease = function(){
    if(inBound)
    {
    trace("You win.");
    }
    else
    {
    trace("You lose.");
    }
    }

    NxtVid.onRelease = function(){
    gotoAndStop(3);
    }

    video2.addEventListener("cuePoint", listenerObject);stop();

    var listenerObject:Object = new Object();
    var inBound:Boolean = false;

    listenerObject.cuePoint = function(eventObject:Object):Void {
    if(eventObject.info.name=="Hazard1")
    {
    inBound = true;
    }
    else if(eventObject.info.name=="Hazard2")
    {
    inBound = false;
    }
    else if(eventObject.info.name=="End")
    {
    trace("Click Here for next clip")
    }
    }

    Hazardbtn1.onRelease = function(){
    if(inBound)
    {
    trace("You win.");
    }
    else
    {
    trace("You lose.");
    }
    }

    NxtVid1.onRelease = function(){
    gotoAndStop(2);
    }

    video2.addEventListener("cuePoint", listenerObject);



    thank you again for any help

    adey
    Last edited by adey177; 04-24-2009 at 11:57 AM. Reason: not all information present

  9. #9
    Flash/Flex Developer samac1068's Avatar
    Join Date
    Apr 2007
    Location
    Here, no there
    Posts
    1,813
    What silentweed was asking is for the code that is used to load your video or are you NOT importing the video. I believe the code I provided will work, but you need to reset the inBound variable at the start of each frame actionscript line for it to work the remaining videos.

    Like silentweed mentioned, it would be beneficial to import the video using code all on the same frame, this way the same code is used over and over again.
    Some people are like Slinkies, not really good for anything, but they bring a smile to your face when pushed down the stairs.

Tags for this Thread

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