Go Back   kirupaForum > Flash > ActionScript 3.0

Reply
 
Thread Tools Display Modes
Old 11-13-2007, 07:37 AM   #1
Rundevo
Registered User
Rewind Button AS3

Hi all

First off, I´m fairly new to Actionscript, but I understand the basics.

What I´m trying to do is to create buttons that acts like the buttons on http://www.newstoday.com/

However, they are activated from an external swf, but I would like to have them static on my timeline.

The code I have so far is something in the ways like this.

stop();

hitArea.buttonMode = true;

var hrewind:Boolean = false;
hitArea.addEventListener(Event.ENTER_FRAME, rewindButton);
hitArea.addEventListener(MouseEvent.MOUSE_OVER, playButton);
hitArea.addEventListener(MouseEvent.MOUSE_OUT, startRewind);

function rewindButton(event:Event){
if(hrewind) prevFrame();
}
function playButton(event:MouseEvent){
hrewind = false;
gotoAndPlay("overMenu")
}
function startRewind(event:MouseEvent){
hrewind = true;
}

It works out okay, but when I add another button using the same script it rewinds all the way do the starting frame, resulting in making the first button rewind itself after the second button, as it rewinds back in the timeline.

Can someone help me get around this problem, or point me in the correct way if I have written something wrong in the code or misunderstood the whole concept of rewinding buttons.

Thanks in advance.
Rundevo is offline   Reply With Quote

Sponsored Links (Guests Only) - Register | Need Help?
 

Old 11-13-2007, 11:49 AM   #2
GrndMasterFlash
itz lik a jungle sum timz
 
GrndMasterFlash's Avatar
Location the heart of Babylon

Posts 710
function rewindButton(event:Event){
if(hrewind) prevFrame();
}

is the only problem i see it should be like this

function rewindButton(event:Event){
if(hrewind){
prevFrame();
}
}
GrndMasterFlash is offline   Reply With Quote
Old 11-13-2007, 11:59 AM   #3
Felixz
Researcher
 
Felixz's Avatar
I think that ur code is in a timeline and shares variables... (I'm wrong?)
ActionScript Code:
stop();
hitArea.buttonMode = true;
hitArea.addEventListener(MouseEvent.MOUSE_OVER, playButton);
hitArea.addEventListener(MouseEvent.MOUSE_OUT, startRewind);

function rewindButton(event:Event) {
event.target.prevFrame();
if (event.target.currentFrame==1) event.target.removeEventListener(Event.ENTER_FRAME, rewindButton);
}
function playButton(event:MouseEvent) {
event.target.removeEventListener(Event.ENTER_FRAME, rewindButton);
gotoAndPlay("overMenu")
}
function startRewind(event:MouseEvent) {
event.target.addEventListener(Event.ENTER_FRAME, rewindButton);
}

__________________

Homepage
Felixz is offline   Reply With Quote
Old 11-13-2007, 12:28 PM   #4
Rundevo
Registered User
Thanks GrndMasterFlash, the code looks better now, but the problem still remains.

Felixz, thanks, my code is in the timeline, but I changed the variable name for the different meny buttons, so I dont see that as a problem, but I´m new at this so dont take my word for it How could I do that differently?

If I could change prevFrame(); to stop at a certain frame instead of going all the way back to the start of the timeline, my problems should get fixed.
However, there are some bugs if you roll over and off again too fast, then it stays in roll over fase and doesnt trigger the other menys.

I´ve seen it done with external swfs for every meny button and loading them on ROLL_OVER, and rewind the swf on ROLL_OUT, but I´m not good enough to try something like that yet.

I feel that I´m just getting deeper and deeper into problems here, maybe there is another way of getting the same effect that I havent thought of?

Thanks for all your feedback, much appreciated.
Rundevo is offline   Reply With Quote
Old 11-13-2007, 12:55 PM   #5
Felixz
Researcher
 
Felixz's Avatar
Quote:
Originally Posted by GrndMasterFlash View Post
function rewindButton(event:Event){
if(hrewind) prevFrame();
}

is the only problem i see it should be like this

function rewindButton(event:Event){
if(hrewind){
prevFrame();
}
}
Its no difference between
ActionScript Code:
if (bool) function();
And
ActionScript Code:
if (bool) {
function();
}

__________________

Homepage
Felixz is offline   Reply With Quote
Old 11-13-2007, 01:08 PM   #6
Felixz
Researcher
 
Felixz's Avatar
ActionScript Code:
target.stop();
target.buttonMode=true;
target.mouseChildren=false;
target.addEventListener(MouseEvent.ROLL_OVER,animujMENU_OVER,false,0,true);
target.addEventListener(MouseEvent.ROLL_OUT,animujMENU_OUT,false,0,true);
target.addEventListener(MouseEvent.CLICK,animujMENU_CLICK,false,0,true);
private function animujMENU_OVER(event:MouseEvent):void {
event.target.removeEventListener(Event.ENTER_FRAME,doTylu);
event.target.addEventListener(Event.ENTER_FRAME,doPrzodu,false,0,true);
}
private function animujMENU_OUT(event:MouseEvent):void {
event.target.removeEventListener(Event.ENTER_FRAME,doPrzodu);
if (!event.target.hasEventListener(Event.ENTER_FRAME)) event.target.addEventListener(Event.ENTER_FRAME,doTylu,false,0,true);
}
private function animujMENU_CLICK(event:MouseEvent):void {
event.target.removeEventListener(MouseEvent.ROLL_OVER,animujMENU_OVER);
event.target.addEventListener(Event.ENTER_FRAME,doKonca,false,0,true);
}
private function doPrzodu(event:Event):void {
event.target.nextFrame();
event.target.currentLabel=="over"?event.target.removeEventListener(event.type,doPrzodu):null;
}
private function doTylu(event:Event):void {
event.target.prevFrame();
event.target.currentFrame==1?event.target.removeEventListener(event.type,doTylu):null;
}
private function doKonca(event:Event):void {
event.target.nextFrame();
if (event.target.currentLabel=="click") {
event.target.gotoAndStop("up");
event.target.removeEventListener(Event.ENTER_FRAME,doKonca);
event.target.addEventListener(MouseEvent.ROLL_OVER,animujMENU_OVER,false,0,true);
event.target.hitTestPoint(stage.mouseX,stage.mouseY,true)?event.target.dispatchEvent(new MouseEvent(MouseEvent.ROLL_OVER,true,false,mouseX,mouseY,event.target)):null;
}
}

__________________

Homepage

Last edited by Felixz; 11-14-2007 at 02:52 PM..
Felixz is offline   Reply With Quote
Old 11-13-2007, 01:14 PM   #7
GrndMasterFlash
itz lik a jungle sum timz
 
GrndMasterFlash's Avatar
Location the heart of Babylon

Posts 710
Quote:
Originally Posted by Felixz View Post
Its no difference between ActionScript Code:
if (bool) function();


And ActionScript Code:
if (bool) {
function();
}

in

if (bool) function;

how does the if statement know to terminate? i have never heard of doing things this way.
GrndMasterFlash is offline   Reply With Quote
Old 11-13-2007, 05:37 PM   #8
453.0
ActionScript 3.0
Location Romania, Timisoara

Posts 389
Here's my version of this thingie, and it works... btw, I'm stoping my button with code, but that's because I'm lazy, you could simply add a stop(); action to the first frame withing the button ( animation ) to stop it from looping:

Good luck guys.

__________________


Last edited by 453.0; 11-13-2007 at 05:42 PM..
453.0 is offline   Reply With Quote
Old 11-13-2007, 05:39 PM   #9
453.0
ActionScript 3.0
Location Romania, Timisoara

Posts 389
PS: my_btn is the instance name of the animated movie clip on the stage...

__________________

453.0 is offline   Reply With Quote
Old 11-13-2007, 05:43 PM   #10
453.0
ActionScript 3.0
Location Romania, Timisoara

Posts 389
pff, stupid editor lost my code... whatever here it is again:


var rewind:Boolean;
my_btn.stop();

my_btn.addEventListener(Event.ENTER_FRAME, my_btn_ef);
my_btn.addEventListener(MouseEvent.MOUSE_OVER, btn_over);
my_btn.addEventListener(MouseEvent.MOUSE_OUT, btn_out);

function my_btn_ef(event:Event):void {
if(rewind) my_btn.prevFrame();
}

function btn_over(event:MouseEvent):void {
rewind = false;
my_btn.play();
}

function btn_out(event:MouseEvent):void {
rewind = true;
}


Hope it stays here this time.

__________________


Last edited by 453.0; 11-14-2007 at 08:45 AM..
453.0 is offline   Reply With Quote
Old 11-13-2007, 05:59 PM   #11
453.0
ActionScript 3.0
Location Romania, Timisoara

Posts 389
Ok, I found only one little bug, and I'm still working on it. The buttons work, no matter how many of them you have but there's a tiny but. If you roll out a button while it's animation and roll over another button, the one you rolled out of stop on the frame you rolled out instead of returning to it's original state ( but it's interesting that once you roll out the button you rolled over after the first one, the first one roll back too )... weird...

__________________

453.0 is offline   Reply With Quote
Old 11-13-2007, 06:14 PM   #12
453.0
ActionScript 3.0
Location Romania, Timisoara

Posts 389
Ok, I found the problem, it's the rewind variable that's causing that bug... Because, well, once you roll over a button, it's value is set to false, after rolling out it's value is set to true, and here's the problem, hence I was rolling out from a button on to another button, the values got changed again...

So, rolling over button 1 -> rewind = false;
rolling out button 1 -> rewind = true;
rolling over button 2 -> rewind = false; ( but if I rolled over this button while the rewind animation was still running for the first one then it will globally change the value of rewind to "false" causing the second button's stop... )

I'm not sure how to get over this as efficiently as possible ( yet ) but, you could solve this problem by using a rewind variable for each button, i.e.: rewind, rewind1, rewind2 and so on, associating each rewind for each button.

I'll be back with more info ( hopefully ).

ActionScript Code:
var rewind:Boolean;
var rewind2:Boolean;

my_btn.hitArea = my_btn.box;
my_btn2.hitArea = my_btn2.box;

my_btn.addEventListener(Event.ENTER_FRAME, my_btn_ef);
my_btn.addEventListener(MouseEvent.ROLL_OVER, btn_over);
my_btn.addEventListener(MouseEvent.ROLL_OUT, btn_out);

my_btn2.addEventListener(Event.ENTER_FRAME, my_btn_ef2);
my_btn2.addEventListener(MouseEvent.ROLL_OVER, btn_over2);
my_btn2.addEventListener(MouseEvent.ROLL_OUT, btn_out2);

// actions for my_btn
function my_btn_ef(event:Event):void {
    if(rewind) { my_btn.prevFrame(); }
}

function btn_over(event:MouseEvent):void {
    rewind = false;
    my_btn.play();
}

function btn_out(event:MouseEvent):void {
    rewind = true;
}

// actions for my_btn2
function my_btn_ef2(event:Event):void {
    if(rewind2) my_btn2.prevFrame();
}

function btn_over2(event:MouseEvent):void {
    rewind2 = false;
    my_btn2.play();
}

function btn_out2(event:MouseEvent):void {
    rewind2 = true;
}


^ there's an example code.

__________________

453.0 is offline   Reply With Quote
Old 11-13-2007, 06:55 PM   #13
453.0
ActionScript 3.0
Location Romania, Timisoara

Posts 389
Solved. So, I made a mistake when playing around with the functions and stuff... My mistake was to control the movie clip button from the main timeline instead of placing the code withing the button. If you place the code on the main timeline and try to control your buttons from there then you'll end up having that same variable interference that I had... But, if you place the code withing the button then even if you have the same variable in n number of movie clips, they won't bother each other until they are on different timelines.

Here the code I got up and running ( place it on the first frame of you mc ):

ActionScript Code:
stop();

var rewind:Boolean;

this.hitArea = this.hit;

this.addEventListener(Event.ENTER_FRAME, ef);
this.addEventListener(MouseEvent.ROLL_OVER, roll_over);
this.addEventListener(MouseEvent.ROLL_OUT, roll_out);

function ef(event:Event):void {
    if(rewind) this.prevFrame();
}

function roll_over(event:MouseEvent):void {
    rewind = false;
    this.play();
}

function roll_out(event:MouseEvent):void {
    rewind = true;
}


I attached a sample file too ( made it while I was playing with the code ), hope it helps. Good luck everyone.
Attached Files
File Type: zip as3_mcButton.zip (8.3 KB, 175 views)

__________________

453.0 is offline   Reply With Quote
Old 11-14-2007, 01:12 PM   #14
453.0
ActionScript 3.0
Location Romania, Timisoara

Posts 389
@ Felixz, I saw that you tend to use an access-control modifier for your functions. Well, in AS 3.0 functions cannot be controlled with the help of access-control modifiers such as "private" or "public", all function be default are public ( and as I mentioned, they cannot be controlled with the help of access-control modifiers ).

__________________

453.0 is offline   Reply With Quote
Old 11-14-2007, 01:17 PM   #15
Rundevo
Registered User
GREAT!

Thanks a million 453.0, works out just as I wanted now. Sweet butt.

Beer is on me if that time ever comes

All the best to you!

Cheers
Rundevo is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 04:44 PM.

SUPPORTERS:

kirupa.com's fast and reliable hosting provided by Media Temple. flash components
Creative web apps. Make your own free flash banners and photo slideshows.
Check out the great, high-quality flash extensions. Buy or sell stock flash, video, audio and fonts for as little as 50 cents at FlashDen.

Flash Transition Effects

Flash Effect Tutorials

Digicrafts Components
Flash effects. Art without coding. Upload, publish, deliver. Secure hosting for your professional or academic video, presentations & more. Screencast.com
Streamsolutions Content Delivery Networks Flipping Book - page flip flash component.
Flash-Gallery.com - Get your flash photo gallery (flash component or swf gallery Learn how to advertise on kirupa.com
 

cdn
content delivery network (cdn)

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd. Copyright 2010 - kirupa.com Copyright 2010 - kirupa.com