Live Chat & Podcast at 1:00PM Eastern on Sunday!
There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
Search
Software Development
Tag Cloud
access acer asus bios bsod computer crash desktop driver drivers error ethernet excel freeze games gaming hard drive hardware hdmi internet laptop malware memory monitor motherboard netgear network printer problem ram random registry router slow software sound trojan ubuntu 11.10 uninstall usb video virus vista wifi windows windows 7 windows 7 32 bit windows 7 64 bit windows xp wireless
Search
Search for:
Tech Support Guy Forums > Software & Hardware > Software Development >
Actionscript 3 help :)

Reply  
Thread Tools
jbm1991's Avatar
Computer Specs
Senior Member with 1,231 posts.
 
Join Date: Sep 2007
Location: UK
Experience: intermediate ~ advanced
30-Nov-2008, 07:51 PM #1
Unhappy Actionscript 3 help :) ASAP please
hi again everyone,

yet another question about AS3

i have several buttons on a frame and have their alpha values set to 50% using the properties bit at the bottom after id converted them into Button's. anyhoo, my coding works fine and dandy, navigation works fine and all that, BUT i want to set it so that when i hover my mouse over a button the alpha value "fades" up to 100%, and then when i take my mouse button back off again it fades back down to 50%. i have tried so hard to get this to work, but i just cant
anyway, here's a copy of my script:

Code:
//freezes page
stop();
// event listeners
mainAdult.addEventListener(MouseEvent.MOUSE_OVER, increaseAlpha);
mainAdult.addEventListener(MouseEvent.MOUSE_OUT, decreaseAlpha);
mainChild.addEventListener(MouseEvent.ROLL_OVER, increaseAlpha);
mainChild.addEventListener(MouseEvent.ROLL_OUT, decreaseAlpha);
mainAdult.addEventListener(MouseEvent.MOUSE_DOWN, onClickMainAdult);
mainChild.addEventListener(MouseEvent.MOUSE_DOWN, onClickMainChild);
//functions
function onClickMainAdult(evt:MouseEvent):void {
	gotoAndStop("adultIntro");
}

function onClickMainChild(evt:MouseEvent):void {
	gotoAndStop("childIntro");
}

function increaseAlpha(evt:MouseEvent):void{
	evt.currentTarget.alpha += 5;
	if (evt.currentTarget.alpha >= 100)
		{
			evt.currentTarget.alpha = 100;
		}
}

function decreaseAlpha(evt:MouseEvent):void{
	evt.currentTarget.alpha -= 5;
	if (evt.currentTarget.alpha <= 50)
	{
		evt.currentTarget.alpha = 50;
	}
}

if you could tell me where ive gone wrong or point me in the correct direction that would be great, thanks

EDIT: oh and the reason im using evt.currentTarget is because i would like this function to be usable by as many buttons as i would like, rather than having to make a whole new function for every button, cause that just gets really messy and inefficient.
__________________
Regards John

My photos and photoshoped things are viewable on My Flickr

Last edited by jbm1991; 30-Nov-2008 at 08:13 PM..
-Fabez-'s Avatar
Senior Member with 1,943 posts.
 
Join Date: Jul 2008
Location: Earth
Experience: General
01-Dec-2008, 04:02 PM #2
So to clarify, when you mouse over, the alpha does not go back up to 100 % ?
jbm1991's Avatar
Computer Specs
Senior Member with 1,231 posts.
 
Join Date: Sep 2007
Location: UK
Experience: intermediate ~ advanced
01-Dec-2008, 04:15 PM #3
no it does go back up to 100%, but it just jumps straight to 100%, it doesn't fade in from 50% to 100%. And when i take my mouse back off again it disappears, it doesn't even jump back down to 50. the button just vanishes. it is still click able, but you cant see it.
__________________
Regards John

My photos and photoshoped things are viewable on My Flickr
-Fabez-'s Avatar
Senior Member with 1,943 posts.
 
Join Date: Jul 2008
Location: Earth
Experience: General
01-Dec-2008, 04:43 PM #4
Try looking into the Tween class. You're code appears to work fine, however in order for the MovieClips to fade back to 50% alpha, change this line.

Code:
if (evt.currentTarget.alpha <= 50)
To

Code:
if (evt.currentTarget.alpha >= 50)
jbm1991's Avatar
Computer Specs
Senior Member with 1,231 posts.
 
Join Date: Sep 2007
Location: UK
Experience: intermediate ~ advanced
01-Dec-2008, 04:51 PM #5
thanks for the suggestion, but im trying to do all this in one frame, without making tween's over several frames.
any ideas?
-Fabez-'s Avatar
Senior Member with 1,943 posts.
 
Join Date: Jul 2008
Location: Earth
Experience: General
01-Dec-2008, 05:18 PM #6
The Tween class is part of ActionScript and can be done using one frame, differing from tweens that use frames. http://livedocs.adobe.com/flash/9.0/...ons/Tween.html Is a link to the Adobe documentation on the ActionScript Tween class.
jbm1991's Avatar
Computer Specs
Senior Member with 1,231 posts.
 
Join Date: Sep 2007
Location: UK
Experience: intermediate ~ advanced
01-Dec-2008, 05:28 PM #7
oooh, now that is something i'd forgotten about. you dont have any simple examples of it relevant to what i need do you? i hate using the adobe help things, i can never understand them

also, how do i make it generalised? do i still use evt.currentTarget within the tween?

and how do i reference to them in event listeners?
__________________
Regards John

My photos and photoshoped things are viewable on My Flickr

Last edited by jbm1991; 01-Dec-2008 at 05:49 PM..
jbm1991's Avatar
Computer Specs
Senior Member with 1,231 posts.
 
Join Date: Sep 2007
Location: UK
Experience: intermediate ~ advanced
01-Dec-2008, 06:19 PM #8
aahhh would i make the tween, then reference it in a function, and then reference the said function in an event listener?
jbm1991's Avatar
Computer Specs
Senior Member with 1,231 posts.
 
Join Date: Sep 2007
Location: UK
Experience: intermediate ~ advanced
01-Dec-2008, 08:39 PM #9
**** me sideways it works its not quite how i'd like it however, as it is not generalised and i have resorted doing it by button, rather than generalness like what i was aiming for above with evt.currentTarget.
anyway heres my new and working code, ignore all the excessive comments and what not, i havent made that part of the project yet so ive commented them out for now.

Code:
import fl.transitions.Tween;
import fl.transitions.easing.*;
//freezes page
stop();
// event listeners
mainAdult.addEventListener(MouseEvent.MOUSE_OVER, increaseAlphaAdult);
mainAdult.addEventListener(MouseEvent.MOUSE_OUT, decreaseAlphaAdult);
//mainChild.addEventListener(MouseEvent.ROLL_OVER, increaseAlpha);
//mainChild.addEventListener(MouseEvent.ROLL_OUT, decreaseAlpha);
mainAdult.addEventListener(MouseEvent.MOUSE_DOWN, onClickMainAdult);
//mainChild.addEventListener(MouseEvent.MOUSE_DOWN, onClickMainChild);

//functions
function onClickMainAdult(evt:MouseEvent):void {
	gotoAndStop("adultIntro");
}
function increaseAlphaAdult(evt:MouseEvent):void{
	btnAlphaInAdult.start();
}
function decreaseAlphaAdult(evt:MouseEvent):void{
	btnAlphaOutAdult.start();
}

//variables 
var btnAlphaInAdult:Tween = new Tween(mainAdult, "alpha", None.easeIn, 0.5, 1, 1, true);
btnAlphaInAdult.stop();
var btnAlphaOutAdult:Tween = new Tween(mainAdult, "alpha", None.easeIn, 1, 0.5, 1, true);
btnAlphaOutAdult.stop();
if you could tell me how to make it more generalised for the variables and event listeners for the fading that would be great
__________________
Regards John

My photos and photoshoped things are viewable on My Flickr
-Fabez-'s Avatar
Senior Member with 1,943 posts.
 
Join Date: Jul 2008
Location: Earth
Experience: General
02-Dec-2008, 03:11 PM #10
Glad its working for you In your Tweens, try replacing the target with the following code to make it more generic.

Code:
this
Code:
evt.currentTarget
jbm1991's Avatar
Computer Specs
Senior Member with 1,231 posts.
 
Join Date: Sep 2007
Location: UK
Experience: intermediate ~ advanced
02-Dec-2008, 03:53 PM #11
hi again fabez right, the suggestion of "this" worked (evt.currentTarget doesnt i tried it before and claims it cant find it or something).
HOWEVER now instead of the button fading in and out, the WHOLE frame fades in and out i.e. everything on the frame sets to 0.5 alpha then when i hover over the button it fades in to 1, then fades back out again when i go off the button. /cry

is there any way it can just be set to fade in the button's yet keeping the generality?
you appear to be on the right track with "this", any more suggestions or modifications?

here's my new code:

Code:
import fl.transitions.Tween;
import fl.transitions.easing.*;
//freezes page
stop();
// event listeners
mainAdult.addEventListener(MouseEvent.MOUSE_OVER, increaseAlpha);
mainAdult.addEventListener(MouseEvent.MOUSE_OUT, decreaseAlpha);
//mainChild.addEventListener(MouseEvent.ROLL_OVER, increaseAlpha);
//mainChild.addEventListener(MouseEvent.ROLL_OUT, decreaseAlpha);
mainAdult.addEventListener(MouseEvent.MOUSE_DOWN, onClickMainAdult);
//mainChild.addEventListener(MouseEvent.MOUSE_DOWN, onClickMainChild);

//functions
function onClickMainAdult(evt:MouseEvent):void {
	gotoAndStop("adultIntro");
}
function increaseAlpha(evt:MouseEvent):void{
	btnAlphaIn.start();
}
function decreaseAlpha(evt:MouseEvent):void{
	btnAlphaOut.start();
}

//variables 
var btnAlphaIn:Tween = new Tween(this, "alpha", None.easeIn, 0.5, 1, 1, true);
btnAlphaIn.stop();
var btnAlphaOut:Tween = new Tween(this, "alpha", None.easeIn, 1, 0.5, 1, true);
btnAlphaOut.stop();
__________________
Regards John

My photos and photoshoped things are viewable on My Flickr
jbm1991's Avatar
Computer Specs
Senior Member with 1,231 posts.
 
Join Date: Sep 2007
Location: UK
Experience: intermediate ~ advanced
04-Dec-2008, 04:12 PM #12
you got anymore suggestions Fabez?

unfortunately the deadline for this project is looming
-Fabez-'s Avatar
Senior Member with 1,943 posts.
 
Join Date: Jul 2008
Location: Earth
Experience: General
04-Dec-2008, 04:57 PM #13
The following code applies the same functions to all MovieClips passed as parameters to ApplyActions, however you can alter it to apply different code to different MovieClips. If you dont understand any of my code I will be happy to add code and explain it to you

Code:
import fl.transitions.Tween;
import fl.transitions.easing.*;
function ApplyActions(FunctionTarget:MovieClip) {
	FunctionTarget.addEventListener(MouseEvent.ROLL_OUT,function PassParams(evt:MouseEvent){RollOutFunction(FunctionTarget)});
	FunctionTarget.addEventListener(MouseEvent.ROLL_OVER,function PassParams(evt:MouseEvent){RollOverFunction(FunctionTarget)});
	FunctionTarget.addEventListener(MouseEvent.MOUSE_DOWN,function PassParams(evt:MouseEvent){MouseDownFunction(FunctionTarget)});
}
function RollOutFunction(FunctionTarget:MovieClip) {
	new Tween(FunctionTarget, "alpha", None.easeIn, 0.5, 1, 0.5, true);
}
function RollOverFunction(FunctionTarget:MovieClip) {
	new Tween(FunctionTarget, "alpha", None.easeIn, 1, 0.5, 1, true);
}
function MouseDownFunction(FunctionTarget:MovieClip) {
}
ApplyActions(mainAdult);
ApplyActions(mainChild);
jbm1991's Avatar
Computer Specs
Senior Member with 1,231 posts.
 
Join Date: Sep 2007
Location: UK
Experience: intermediate ~ advanced
04-Dec-2008, 05:21 PM #14
you lost me at : "function ApplyActions(FunctionTarget:MovieClip) { "

im new to actionscript and programming in general so forgive me for being slow

if you could give me a run down on what all that is going on about that would be great

thanks in advance
-Fabez-'s Avatar
Senior Member with 1,943 posts.
 
Join Date: Jul 2008
Location: Earth
Experience: General
04-Dec-2008, 05:31 PM #15
I will add comments to my code and post it again for you, it may be tommorow though. If you still have any questions I will be happy to answer them so you can understand and adapt the code
Reply

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.
Thread Tools



Facebook Facebook Twitter Twitter TechGuy.tv TechGuy.tv Mobile TSG Mobile
You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 07:36 PM.
Copyright © 1996 - 2011 TechGuy, Inc. All rights reserved.

Powered by Cermak Technologies, Inc.