dcsimg
A Flash Developer Resource Site

Page 1 of 2 12 LastLast
Results 1 to 20 of 23

Thread: Button Events by Date

  1. #1
    Member
    Join Date
    Sep 2004
    Posts
    40

    Button Events by Date

    Hi There

    I have designed an advent calendar with buttons that open the windows.

    Is it possible to control the action of the button dependant on day e.g on Dec 1st door 1 opens, Dec 2nd door 2 opens etc?

    How would i go about getting this functionality to work?

    The script i have used for my buttons is:

    <code>
    on(rollOver){
    button1.gotoAndPlay(2);
    }
    on(rollOut){
    button1.gotoAndPlay(16);
    }
    on (press) {
    getURL("javascript:show('images/img1.jpg','IMAGE CAPTION');");
    }
    </code>


    Any help would be most appreciated.

    Thanks

  2. #2
    anyone else hear that? flashpipe1's Avatar
    Join Date
    Jan 2003
    Location
    Upstate NY
    Posts
    1,930
    This should work as long as your images are named according to the day...

    Code:
    on(rollOver){
         button1.gotoAndPlay(2);
    }
    on(rollOut){
         button1.gotoAndPlay(16);
    }
    on (release) {
    	var today_date:Date = new Date();
    	var date_str:Number = today_date.getDate();	
    	getURL("javascript:show('images/img"+date_str+".jpg','IMAGE CAPTION');");
    }
    Hope that helps!
    Last edited by flashpipe1; 10-29-2009 at 11:10 AM. Reason: Adding code tags
    Love like you've never been hurt, live like there's no tomorrow and dance like nobody's watching.

  3. #3
    Member
    Join Date
    Sep 2004
    Posts
    40
    Hi flashpipe

    thanks for getting back to me. When you say images named according to the day what do you mean?

    Is it the button, movie clip or image itself because i have named my buttons in numerical sequence each representing a day in december.

  4. #4
    anyone else hear that? flashpipe1's Avatar
    Join Date
    Jan 2003
    Location
    Upstate NY
    Posts
    1,930
    I just meant that I set the code up to load the representative image based on the date...

    So,

    Code:
    'images/img"+date_str+".jpg'
    will load "images/img1.jpg", "images/img2.jpg", "images/img3.jpg", etc.

    If you have a bunch of buttons (actual Button symbols), there is a much easier way to code ALL of them in one chunk of code, but you would have to convert them to movieclips. If they're already movieclips, let me know and I'll send you the code to use...
    Love like you've never been hurt, live like there's no tomorrow and dance like nobody's watching.

  5. #5
    Member
    Join Date
    Sep 2004
    Posts
    40
    Yes they are all button symbols (each day that is). Each window is a movie clip and has an invisible button layer on top. I hope it makes sense

  6. #6
    anyone else hear that? flashpipe1's Avatar
    Join Date
    Jan 2003
    Location
    Upstate NY
    Posts
    1,930
    Cool...I try to avoid using buttons whenever possible (and just use movieclips for everything), but you can still do it this way...

    I'm not sure why each day has a button and you still needed a way to tell each button to display the image based on the day, but this should help make the code centralized and easier to update.

    First, make a copy of your file (in case you decide to go back to how you currently have it)

    Remove all the scripts from your buttons, then, give each of your buttons an instance name, use sequential numbers, for instance, day1_btn, day2_btn, day3_btn, etc.

    Put the following script in a frame (not on a button):
    Code:
    var today_date:Date = new Date();
    var date_str:Number = today_date.getDate();
    //replace the number below with however many buttons you have
    var numBtns:Number = 30;
    for (i=1; i<=numBtns; i++) {
    	daySelected = this["day"+i+"_btn"];
    	daySelected.i = i;
    	daySelected.onRelease = function() {
    		//put the code here to display an image based on the date
    		getURL("javascript:show('images/img"+date_str+".jpg','IMAGE CAPTION');");
    		//put the code here to do something based on the "number" of this button
    		trace("hit "+this.i);
    	};
    }
    Hope that helps!
    Love like you've never been hurt, live like there's no tomorrow and dance like nobody's watching.

  7. #7
    Member
    Join Date
    Sep 2004
    Posts
    40
    Hi flashpipe1

    I have tried your approach but dont seem to be getting anywhere I have followed your instruction but the weird thing is the action script doesnt have any effect on my fla.

    I am not sure what i am doing wrong. Would it help if i posted an example of what I have done so far. Its completed except for the actionscript controlling which window on what day. At the moment all the doors open at the moment.

    Thanks.

  8. #8
    anyone else hear that? flashpipe1's Avatar
    Join Date
    Jan 2003
    Location
    Upstate NY
    Posts
    1,930
    Absolutely, being able to see what you're talking about will make it much easier to tell you what to change.
    Love like you've never been hurt, live like there's no tomorrow and dance like nobody's watching.

  9. #9
    Member
    Join Date
    Sep 2004
    Posts
    40

    cs3 button events by date

    Hi again

    I have attached a basic example, couldnt attach the whole project as it exceeds atttachment file size.

    I have just four caledar windows on the stage, hopefully you can make sense of what i have done.

    Really appreciate your help?

    Regards
    Attached Files Attached Files

  10. #10
    anyone else hear that? flashpipe1's Avatar
    Join Date
    Jan 2003
    Location
    Upstate NY
    Posts
    1,930
    Hmm...well, a few things. If you're going to set this up to us one piece of code, you can't use sequential numbers and do "1st.jpg", "2nd.jpg", etc. since the final few characters are different. You can use whatever names you want if you set up an array with the names in there (like I did with the descriptions), or you can just use 1.jpg, 2.jpg, etc.

    Not sure why the code I sent didn't work for you...works fine here...I attached your file with the code in there...

    Also, still don't know where getting the current date comes into play??

    Hope that helps!
    Last edited by flashpipe1; 05-05-2011 at 10:24 AM.
    Love like you've never been hurt, live like there's no tomorrow and dance like nobody's watching.

  11. #11
    Member
    Join Date
    Sep 2004
    Posts
    40
    Thanks for that.

    I have looked at what you did and can make sense of it. I think i have not explained myself properly and do apologise for that - in a nutshell the end user should be able to click on whatever day it is in december at that moment in time, the window curls up and on press the product is displayed.

    On the example you have sent across all the windows are still clickable but the window that should be the only one to open is window 3 as today is the 3rd November. Thats where getting the current date comes in.

    Is this feasible?

  12. #12
    anyone else hear that? flashpipe1's Avatar
    Join Date
    Jan 2003
    Location
    Upstate NY
    Posts
    1,930
    Ah, so, the only button that should be active is the one for the current day?

    In that case, just put the following if statement right after the onRelease function and wrap the whole block of code for that function inside it:

    Code:
    if(this.i == date_str){
    Love like you've never been hurt, live like there's no tomorrow and dance like nobody's watching.

  13. #13
    Member
    Join Date
    Sep 2004
    Posts
    40
    flashpipe1 thank you so much we have lift off it works! Cant beleive it!

    Last question I had an animation on there so that when you hover over the window peels open. How come you took it out? Can i put it back in or will it disrupt what we have come to now?

  14. #14
    anyone else hear that? flashpipe1's Avatar
    Join Date
    Jan 2003
    Location
    Upstate NY
    Posts
    1,930
    I just didn't add it in there...you can put it back by adding the onRollOver and onRollOut to the function.


    Code:
    daySelected.onRollOver = function() {
    	this._parent["sticker"+this.i].gotoAndPlay(2);
    };
    daySelected.onRollOut = function() {
    	this._parent["sticker"+this.i].gotoAndPlay(16);
    };
    Love like you've never been hurt, live like there's no tomorrow and dance like nobody's watching.

  15. #15
    Member
    Join Date
    Sep 2004
    Posts
    40
    Hi flashpipe1 Thanks for your help.

    It all works now. There is only one glitch. When my image loads up the image description says undefined - this after uploading the swf/html file on the server, however when i test it in flash and put a trace statement in it displays the image description fine.

    Is there any reason as to why that is please?

  16. #16
    anyone else hear that? flashpipe1's Avatar
    Join Date
    Jan 2003
    Location
    Upstate NY
    Posts
    1,930
    Try changing the code from:
    Code:
    getURL("javascript:show('img/img"+this.i+".jpg',"+descriptionArray[date_str-1]+");");
    to:
    Code:
    getURL("javascript:show('img/img"+this.i+".jpg','+descriptionArray[date_str-1]+');");
    Change the double quote to single quote.

    That might do it...
    Love like you've never been hurt, live like there's no tomorrow and dance like nobody's watching.

  17. #17
    Member
    Join Date
    Sep 2004
    Posts
    40
    I changed it to single quote and the image description text says -
    +descriptionArray[date_str-1]+

    What could it be?

  18. #18
    anyone else hear that? flashpipe1's Avatar
    Join Date
    Jan 2003
    Location
    Upstate NY
    Posts
    1,930
    Hmm...try this:

    Code:
    getURL("javascript:show('img/img"+this.i+".jpg','"+descriptionArray[date_str-1]+"');");
    Just have to get the formatting right to pass the variable through the flash string into the javascript call correctly...I think this will do it.
    Love like you've never been hurt, live like there's no tomorrow and dance like nobody's watching.

  19. #19
    Member
    Join Date
    Sep 2004
    Posts
    40
    Thanks for your help flashpipe1 really appreciate it!

    I am just getting started in flash and action script just findind the actionscript side of things a little tricky to grasp. In terms of learning shall i begin with as2 or start with as3?

  20. #20
    Member
    Join Date
    Sep 2004
    Posts
    40
    Hi Flashpipe

    The image description we have got it to work but it always displays the same image description no matter what window you select. I went back to the original file you uploaded to try and see where i have gone wrong but it seems to do the same thing as well. Any ideas?

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