# Actionscript 3 help :)



## jbm1991 (Sep 1, 2007)

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:


```
//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.


----------



## -Fabez- (Jul 28, 2008)

So to clarify, when you mouse over, the alpha does not go back up to 100 % ?


----------



## jbm1991 (Sep 1, 2007)

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.


----------



## -Fabez- (Jul 28, 2008)

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.


```
if (evt.currentTarget.alpha <= 50)
```
To


```
if (evt.currentTarget.alpha >= 50)
```


----------



## jbm1991 (Sep 1, 2007)

thanks for the suggestion, but im trying to do all this in one frame, without making tween's over several frames.
any ideas?


----------



## -Fabez- (Jul 28, 2008)

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/ActionScriptLangRefV3/fl/transitions/Tween.html Is a link to the Adobe documentation on the ActionScript Tween class.


----------



## jbm1991 (Sep 1, 2007)

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?


----------



## jbm1991 (Sep 1, 2007)

aahhh would i make the tween, then reference it in a function, and then reference the said function in an event listener?


----------



## jbm1991 (Sep 1, 2007)

**** 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.


```
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


----------



## -Fabez- (Jul 28, 2008)

Glad its working for you  In your Tweens, try replacing the target with the following code to make it more generic.


```
this
```


```
evt.currentTarget
```


----------



## jbm1991 (Sep 1, 2007)

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:


```
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();
```


----------



## jbm1991 (Sep 1, 2007)

you got anymore suggestions Fabez? 

unfortunately the deadline for this project is looming


----------



## -Fabez- (Jul 28, 2008)

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 


```
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 (Sep 1, 2007)

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- (Jul 28, 2008)

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


----------



## jbm1991 (Sep 1, 2007)

righto  

thanks


----------



## jbm1991 (Sep 1, 2007)

actually, wait a second. i think i may have cracked it 

at the bottom, where it has "applyactions(..." etc, do i just add in all appropriate instance names there like that? 

if so then wooo  

i would still like to know what it all means though at some point if its not too much trouble


----------



## jbm1991 (Sep 1, 2007)

when i run it, this error appears after i have faded one button once 

VerifyError: Error #1107: The ABC data is corrupt, attempt to read out of bounds.

EDIT: is this the return of the "garbage collection" that so many people seem to hate?


----------



## -Fabez- (Jul 28, 2008)

I have added comments for you to read and you are correct, you do add the appropriate MovieClip name in the brackets of.the ApplyActions function.


```
ApplyActions(MovieClip Name)
```
Below is the commented code, feel free to ask any questions 


```
//Import the class's needed for the ActionScript to work
import fl.transitions.Tween;
import fl.transitions.easing.*;
//ApplyActions is a function that takes one MovieClip as a parameter
function ApplyActions(FunctionTarget:MovieClip) {
	//It adds event listeners to the MovieClip you pass to it as a parameter. When adding the event listenrs there is a nested function called PassParams that
	//is used to pass the name of the target MovieClip to the event handler functions.
	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)});
}
//The following functions take a MovieClip name a parameter from the PassParams function nested in the addEventListener functions. They then apply the relevent actions
//to the MovieClip they recieve as a paremeter.
function RollOutFunction(FunctionTarget:MovieClip) {
	new Tween(FunctionTarget, "alpha", None.easeIn, FunctionTarget.alpha, 1, 0.5, true);
}
function RollOverFunction(FunctionTarget:MovieClip) {
	new Tween(FunctionTarget, "alpha", None.easeIn, FunctionTarget.alpha, 0.5, 1, true);
}
function MouseDownFunction(FunctionTarget:MovieClip) {
}
//The following lines call the function ApplyActions, passing the MovieClip in the brackets as a parameter.
ApplyActions(mainAdult);
ApplyActions(mainChild);
```


----------



## jbm1991 (Sep 1, 2007)

thanks fabez 

but i still get the following error message after 1 button has been faded once  

VerifyError: Error #1107: The ABC data is corrupt, attempt to read out of bounds.


----------



## -Fabez- (Jul 28, 2008)

From what I can gather the .Fla appears to be corrupt, try making a completly new .Fla to see if the same errors occurs, however do not copy anything from the original .Fla as it may corrupt the new .Fla you are making.


----------



## jbm1991 (Sep 1, 2007)

can i copy the objects, as unfortunately i don't have the time to create a whole new thing


----------



## -Fabez- (Jul 28, 2008)

Yes you can if you want to, its just a small test to check if the file is corrupted or whether something else is wrong with the original as I cannot seem to reproduce your error. You do not have to duplicate everything, just enough to make test if it works.


----------



## jbm1991 (Sep 1, 2007)

ive just tried it there by reproducing the 2 buttons on my main page, and 2 pages for them to go to and i still get the verify error 

do any of that lot mean anything to you: http://www.google.co.uk/search?hl=en&q=VerifyError%3A+Error+%231107%3A+The+ABC+data+is+corrupt%2C+attempt+to+read+out+of+bounds+fix&btnG=Search&meta=

i'll PM you my project now and you can see for yourself


----------



## jbm1991 (Sep 1, 2007)

damn i cant PM you it, so i'll have to upload it to here. tell me when youve d/l it so i can pull it back off. 

EDIT: pulled file as the issue was sort of solved.


----------



## jbm1991 (Sep 1, 2007)

you have to be ****ting me adobe  its bloody flash player's fault 

apparently theres something wrong with r115 and that was the default on the PC  so now ive switched it over to r124 it works like a charm 

woo hoo 

now to get it to compile into an .exe  do you know how to change the compiler when i export to an exe it from using r115 to r124???


----------



## jbm1991 (Sep 1, 2007)

OH FOR THE LOVE OF ... ITS BROKEN AGAIN 

whyy mee god? why me /cry 

its stopped working even when i use r124 now 

but it was working perfectly like 5 minutes ago, and i havent done or changed anything 

and now r124 has buggered off leaving me with r115 and no others


----------



## -Fabez- (Jul 28, 2008)

Maybe the file is corrupted. As for making a .Exe from a .Swf, when viewing it in the player, click File > Create Projector.


----------



## jbm1991 (Sep 1, 2007)

hmm, maybe you are right 

so to hell with it, i dont have the time to mess about with some stupid little compiler problem  as good as your solution would have been had the flash compiler not broken it i am going to have to go back to just do a tween for every button. it takes longer and looks messy but at least it works for now 

one final question however, how do i set the alpha property of something to zero using AS3? ive tried "SPcontent.alpha = 0;" but it doesn't have any effect


----------



## -Fabez- (Jul 28, 2008)

That should work, are you sure you have given the target an instance name ? Also add my code as a comment block to show you managed to do it dynamically.


----------



## jbm1991 (Sep 1, 2007)

thanks for all the help Fabez  i'll add your code as a comment as you say 

but no "SPcontent.alpha = 0;" doesn't work. its because my buttons are set to start at alpha 50% then hover over and go to 100% then back to 50% when the mouse is removed. one button sets itself to 50% and thus works fine, the other sets itself to 100% on start up 

any ideas?

heres my new and working code: 

```
import fl.transitions.Tween;
import fl.transitions.easing.*;
//attempt to fix buttons alpha property to 50 but it doesn't work
mainAdult.alpha = 0.5;
//freezes page
stop();
// event listeners
mainAdult.addEventListener(MouseEvent.MOUSE_OVER, increaseAlphaAdult);
mainAdult.addEventListener(MouseEvent.MOUSE_OUT, decreaseAlphaAdult);
mainChild.addEventListener(MouseEvent.ROLL_OVER, increaseAlphaChild);
mainChild.addEventListener(MouseEvent.ROLL_OUT, decreaseAlphaChild);
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 increaseAlphaAdult(evt:MouseEvent):void{
	btnAlphaInAdult.start();
}
function decreaseAlphaAdult(evt:MouseEvent):void{
	btnAlphaOutAdult.start();
}
function increaseAlphaChild(evt:MouseEvent):void{
	btnAlphaInChild.start();
}
function decreaseAlphaChild(evt:MouseEvent):void{
	btnAlphaOutChild.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();
var btnAlphaInChild:Tween = new Tween(mainChild, "alpha", None.easeIn, 0.5, 1, 1, true);
btnAlphaInAdult.stop();
var btnAlphaOutChild:Tween = new Tween(mainChild, "alpha", None.easeIn, 1, 0.5, 1, true);
btnAlphaOutAdult.stop();
```
coincidentally im having a similar problem on another frame, could it be the tweens over riding and alpha changes i make?

EDIT: actually scratch that last sentence as i manage to use the .visible function to work around the problem  but i cant use that work around on my other problem described at the start of this post  as the alpha needs to be 0.5.
any suggestions? 

Thanks again Fabez


----------



## jbm1991 (Sep 1, 2007)

woo hooo i fixed it  i just added the following and now it works perfectly 


```
//attempt to fix adult button
mainAdult.addEventListener("enterFrame",enterFrame_handler);
function enterFrame_handler(evt:Event):void{
	mainAdult.alpha = 0.5;
}
```
im learning Fabez, IM LEARNING


----------



## jbm1991 (Sep 1, 2007)

oh and im just going to leave this thread open as i will undoubtedly have more AS3 problems in the near future 

thanks for all the great help so far


----------



## -Fabez- (Jul 28, 2008)

You are learning very fast  I will try my best to help you in future and you are quite welcome to private mail me if you want to as well


----------



## jbm1991 (Sep 1, 2007)

Guess who has a new problem Fabez 

and this one actually has me stumped  for 2 reasons 
1) i dont know what the hell the error message means
2) ive isolated the problem, and they work fine on their own, its just when i put them all in together they generate the error message.

anyway, the error message is:

*TypeError: Error #1009: Cannot access a property or method of a null object reference.
at Projectthing_fla::MainTimeline/enterFrame_handler()*

and here is my code, with the bold lines being the problem ones:

```
stop();
//add event listeners
childIntro.addEventListener(MouseEvent.MOUSE_DOWN, onClickChildIntro);
childCC.addEventListener(MouseEvent.MOUSE_DOWN, onClickChildCC);
childChurch.addEventListener(MouseEvent.MOUSE_DOWN, onClickChildChurch);
childPhoto.addEventListener(MouseEvent.MOUSE_DOWN, onClickChildPhoto);
childNEInfo.addEventListener(MouseEvent.MOUSE_DOWN, onClickChildNEInfo);
[B]childER.addEventListener(MouseEvent.MOUSE_DOWN, onClickChildER);
childV.addEventListener(MouseEvent.MOUSE_DOWN, onClickChildV);
childG.addEventListener(MouseEvent.MOUSE_DOWN, onClickChildG);[/B]
childClose.addEventListener(MouseEvent.MOUSE_DOWN, onClickChildClose);
//functions
function onClickChildIntro(evt:MouseEvent):void{
	gotoAndStop("childIntro");
}
function onClickChildCC(evt:MouseEvent):void{
	gotoAndStop("childCC");
}
function onClickChildChurch(evt:MouseEvent):void {
	gotoAndStop("childChurch");
}
function onClickChildPhoto(evt:MouseEvent):void {
	gotoAndStop("childPhoto");
}
function onClickChildNEInfo(evt:MouseEvent):void {
	gotoAndStop("childNEInfo");
}
[B]function onClickChildER(evt:MouseEvent):void {
	gotoAndStop("External Resources");
}
function onClickChildV(evt:MouseEvent):void {
	gotoAndStop("Videos");
}
function onClickChildG(evt:MouseEvent):void {
	gotoAndStop("Game Menu");
}[/B]
function onClickChildClose(evt:MouseEvent):void {
	gotoAndStop("MainPage");
}
```
any ideas?


----------



## jbm1991 (Sep 1, 2007)

okay nevermind, i added a blank keyframe in at the start of my whole project and the error message has gone. i have no idea how that fixed the problem but hey, at least it works again


----------



## jbm1991 (Sep 1, 2007)

Hello again  new problem 

basically on one of my pages i have 3 things, and on another page i have 4 things, both of which i want when the trigger buttons are clicked on they fade themselves in, and fade out whatever is there. Much like what i was trying to do before in this thread, except that was with 2 things so it was a lot easier. This is with 3 and 4, and the only way i could think of doing it is with quite a few IF loops do you have any other suggestions?


----------



## -Fabez- (Jul 28, 2008)

So to clarify, you would like to apply event listeners to several MovieClips, but without using endless repetition and lines of code ?


----------



## jbm1991 (Sep 1, 2007)

hi fabez 
i got round my above problem using several "if" loops. BUT i keep receiving this syntax error 
*1083: Syntax error: else is unexpected.*  bits in bold are what its complaining about

here is my code  causing the error message.


```
import fl.transitions.Tween;
import fl.transitions.easing.*;

//freezes page
stop(); 

// event listeners
term1.addEventListener(MouseEvent.MOUSE_DOWN, gotoadultTerm1);
term2.addEventListener(MouseEvent.MOUSE_DOWN, gotoadultTerm2);
term3.addEventListener(MouseEvent.MOUSE_DOWN, gotoadultTerm3);

//functions

function gotoadultTerm1(evt:MouseEvent):void{
	if(adultTerm1.alpha == 100)
		{
			stop();
		} 
	else if(adultTerm2.alpha == 100);{
			adultTerm2Out.start();
			adultTerm1In.start();
		 } 
	[B]else (adultTerm3.alpha == 100) {
			adultTerm3Out.start();
			adultTerm1In.start();
		 }[/B]
}

function gotoadultTerm2(evt:MouseEvent):void{
	if(adultTerm2.alpha == 100)
		{
			stop();
		}
	else if(adultTerm1.alpha == 100);{
			adultTerm1Out.start();
			adultTerm2In.start();
		 }
	[B]else (adultTerm3.alpha == 100) {
			adultTerm3Out.start();
			adultTerm2In.start();
		 }[/B]
}

function gotoadultTerm3(evt:MouseEvent):void{
	if(adultTerm3.alpha == 100)
		{
			stop();
		}
	else if(adultTerm1.alpha == 100);{
			adultTerm1Out.start();
			adultTerm3In.start();
		 }
	[B]else (adultTerm2.alpha == 100) {
			adultTerm2Out.start();
			adultTerm3In.start();
		 }[/B]
}
```
there are tween variables there, but they all work fine 

any ideas as to why im getting the syntax error?


----------



## -Fabez- (Jul 28, 2008)

You are getting the error because your else statements do not require a set of ( ) brackets after them. The code below shows an example of this.


```
if (1==1){
	trace ("Yes")
} else {
	trace ("No")
}
```
If you want, I can code you a more generic version of your code, as it would be easier to manage.


----------



## jbm1991 (Sep 1, 2007)

that would be great if you could do that fabez 

but i still get the same error message 


```
import fl.transitions.Tween;
import fl.transitions.easing.*;

//freezes page
stop(); 

// event listeners
term1.addEventListener(MouseEvent.MOUSE_DOWN, gotoadultTerm1);
term2.addEventListener(MouseEvent.MOUSE_DOWN, gotoadultTerm2);
term3.addEventListener(MouseEvent.MOUSE_DOWN, gotoadultTerm3);

//functions
function gotoadultTerm1(evt:MouseEvent):void{
	if(adultTerm1.alpha == 100)
		{
			stop();
		} 
	else if(adultTerm2.alpha == 100);{
			adultTerm2Out.start();
			adultTerm1In.start();
		 } 
	else {
			adultTerm3Out.start();
			adultTerm1In.start();
		 }
}

function gotoadultTerm2(evt:MouseEvent):void{
	if(adultTerm2.alpha == 100)
		{
			stop();
		}
	else if(adultTerm1.alpha == 100);{
			adultTerm1Out.start();
			adultTerm2In.start();
		 }
	else {
			adultTerm3Out.start();
			adultTerm2In.start();
		 }
}

function gotoadultTerm3(evt:MouseEvent):void{
	if(adultTerm3.alpha == 100)
		{
			stop();
		}
	else if(adultTerm1.alpha == 100);{
			adultTerm1Out.start();
			adultTerm3In.start();
		 }
	else {
			adultTerm2Out.start();
			adultTerm3In.start();
		 }
}

//variables
var adultTerm1In:Tween = new Tween(adultTerm1, "alpha", None.easeIn, 0, 1, 1, true);
adultTerm1In.stop();
var adultTerm1Out:Tween = new Tween(adultTerm1, "alpha", None.easeIn, 1, 0, 1, true);
adultTerm1Out.stop();
var adultTerm2In:Tween = new Tween(adultTerm2, "alpha", None.easeIn, 0, 1, 1, true);
adultTerm2In.stop();
var adultTerm2Out:Tween = new Tween(adultTerm2, "alpha", None.easeIn, 1, 0, 1, true);
adultTerm2Out.stop(); 
var adultTerm3In:Tween = new Tween(adultTerm3, "alpha", None.easeIn, 0, 1, 1, true);
adultTerm3In.stop();
var adultTerm3Out:Tween = new Tween(adultTerm3, "alpha", None.easeIn, 1, 0, 1, true);
adultTerm3Out.stop();
```


----------



## jbm1991 (Sep 1, 2007)

EDIT 2: okay maybe dont scratch that 

its decided not to import my actionscript  or anything


----------



## -Fabez- (Jul 28, 2008)

I made the generic code for you, in order to use it call the function AddGenericListener, with three parameters, the target MovieClip, the type of event listener you want and the function you would like to be called when the event happens.


```
import fl.transitions.Tween;
import fl.transitions.easing.*;
function AddGenericListener(Target:MovieClip, Type:String, TargetFunction:Function) {
	Target.addEventListener(Type,TargetFunction);
}
function DecreaseAlpha(EventInfo:MouseEvent) {
	new Tween(this, "alpha", None.easeIn, this.alpha, 0, 1, true);
}
function IncreaseAlpha(EventInfo:MouseEvent) {
	new Tween(this, "alpha", None.easeIn, this.alpha, 1, 1, true);
}
AddGenericListener(TestOne_mc,MouseEvent.MOUSE_OVER,DecreaseAlpha);
AddGenericListener(TestOne_mc,MouseEvent.MOUSE_OUT,IncreaseAlpha);
```
I also found the problem with your code, after the brackets in your else if statements there is a semi-colon that needs to be removed in order to ensure the correct working of your code. See the example below on how to correct your code.


```
else if(LogicTest);{
```
The semi-colon in the above code needs to be removed to create the line of code below.


```
else if(adultTerm1.alpha == 100){
```


----------



## jbm1991 (Sep 1, 2007)

thanks fabez 

any ideas why my swf isnt loading properly after its been imported?


----------



## -Fabez- (Jul 28, 2008)

No problems  Where is the .Swf being imported to ?


----------



## jbm1991 (Sep 1, 2007)

thanks  

basically i have a blank frame in main flash file (FYI which is called project.fla) called "introMain". in this blank frame, i would like to import/embed a .swf file i have called "intro.swf". 

i currently have the "intro.swf" file in the same folder as my "project.fla".

whenever i import "intro.swf" it imports incorrectly, and then breaks everything else 

could it be because my "intro.swf" corresponding .fla file calls upon an actionscript file from another folder? but if this is the case, then why does "intro.swf" work fine when it is run from my documents? it is ONLY when imported that it decides to skip some of the code, and thus breaks.


----------



## -Fabez- (Jul 28, 2008)

Are there any other frames in Project.fla ?


----------



## jbm1991 (Sep 1, 2007)

there are indeed  
24 frames in total. the frame i am importing to is frame 2.

any ideas?


----------



## -Fabez- (Jul 28, 2008)

Yes, you can use the loadMovie(MovieName) function.


----------



## jbm1991 (Sep 1, 2007)

oooh, sounds promising 

will it load my actionscript though?


----------



## -Fabez- (Jul 28, 2008)

It loads the whole .Swf file. On frame two of research.fla, create an empty MovieClip called Target_mc and place it in the top left corner of the stage. Then place the following code on your main timeline.


```
stop();
Target_mc.loadMovie("intro.swf");
```


----------



## jbm1991 (Sep 1, 2007)

i receive this compiler error  but i shall look into it myself  and probably fail miserably 


```
Warning: 1060: Migration issue: The method loadMovie is no longer supported.  Use var l = new Loader(); addChild(l); l.load(new URLRequest("your url"));. For more information, see the Loader and DisplayObjectContainer classes.."
```


----------



## -Fabez- (Jul 28, 2008)

Sorry, thats my fault, I was thinking ActionScript 2  I am sure you will not fail, but if you encounter any problems, feel free to ask


----------



## jbm1991 (Sep 1, 2007)

FIXED IT 

i could actually kiss you fabez  

except that would be wrong


----------



## -Fabez- (Jul 28, 2008)

Nice one  I'll pass on the kiss though thanks


----------



## jbm1991 (Sep 1, 2007)

one final thing however with regards to the swf problem. how do i set it to only play once? then stop on the last frame of the swf? so it doesnt keep on looping over and over again. EDIT: Nevermind fixed that.



 i'm not good enough for you am i /huff


----------



## jbm1991 (Sep 1, 2007)

oh and how do i choose where the loaded swf is positioned?


----------



## jbm1991 (Sep 1, 2007)

EEEK help 

now that the thing is working. it has disabled all the other actionscript after frame 2 in my main "project.fla".

do i need to unload it or something?

if so how


----------



## -Fabez- (Jul 28, 2008)

After it has finished, you will need to go to the next frame in project.fla. Are you doing this and your code is no longer working after this point ?


----------



## jbm1991 (Sep 1, 2007)

yes, that is what i am doing 
i have it set so that when i click anywhere on the frame on that the "intro.swf" is imported to. it move to the next frame. and none of my actionscript after that works


----------



## JohnWill (Oct 19, 2002)

Opened as per request.


----------



## jbm1991 (Sep 1, 2007)

thanks JohnWill


----------



## jbm1991 (Sep 1, 2007)

Right then, seeing as i've reopened Pandora's box we may aswell get started again   This time the final deadline is Feb 23rd 2009.

This is the same problem as i was having before with regards to the imported .swf file causes all actionscript after that frame to stop working. 

any ideas anyone?


----------



## -Fabez- (Jul 28, 2008)

Do you have a sample file you could send me or any examples of the inner workings of your files please ?


----------



## jbm1991 (Sep 1, 2007)

I'll send you a pm in a second fabez


----------



## jbm1991 (Sep 1, 2007)

Right thats everything sent. 
Also, apart from the stupid intro thing that breaks everything  on all the sub slides, they are supposed to fade in like they do on one of the pages, but they don't  you'll see what i mean.


----------



## jbm1991 (Sep 1, 2007)

Basically i have a main .fla file which i shall call projectthing.fla for example purposes, and on one of the frames in projectthing.fla i an nesting a movie clip called "childgalleryholder" which currently resides in my library. within this "mychildgalleryholder" i am... importing?... an external .swf which is located in the same folder as my main projectthing.fla . The .swf that i speak of is called stack_gallery.swf and essentially the same file that im using can be found *here*. Now then, to pull said .swf into the holder movieclip i mention above i am using this code(I'll explain the point of the pink bit in a second) :


```
import flash.net.URLRequest;
import flash.display.Loader;
import flash.events.Event;
import flash.events.ProgressEvent;

var mLoader:Loader; 

function startLoad()
{
mLoader = new Loader();
var mRequest:URLRequest = new URLRequest("stack_gallery.swf");
mLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onCompleteHandler);
mLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgressHandler);
mLoader.load(mRequest);
}

function onCompleteHandler(loadEvent:Event)
{
        addChild(mLoader);
}

function onProgressHandler(mProgress:ProgressEvent)
{
var percent:Number = mProgress.bytesLoaded/mProgress.bytesTotal;
trace(percent);
}
startLoad();

[COLOR="Magenta"]remove.addEventListener(MouseEvent.MOUSE_DOWN, onclickremove);
function onclickremove(evt:MouseEvent):void{
    mLoader.unload();
    removeChild(mLoader);[/COLOR]
}
```
to place the holder mc on the stage for that frame i am using this code: 

```
stop();

var mychildgalleryholder:childgalleryholder = new childgalleryholder();
mychildgalleryholder.x = 5;
mychildgalleryholder.y = 96;
addChild(mychildgalleryholder);
```
Now then, this all works fine (well good enough anyway), BUT when it comes to changing frames, no matter what frame i switch to, the holder mc DOES NOT go away, or at least i assume its the holder mc the point is that the imported .swf stays on the screen and renders my project unusable until i close it then reload it and avoid that frame.

So i decided to set up a button which uses this code to remove the holder from the stage:


```
removePhotoSlideShow.addEventListener(MouseEvent.MOUSE_DOWN, onClickremovePhotoSlideShow);
function onClickremovePhotoSlideShow(evt:MouseEvent):void{
    removeChild(mychildgalleryholder);
    mychildgalleryholder = null;
}
```
It works fine and the thing goes away, BUT it leaves the photos in place for no apparent reason. and they obviously also need to go away with the rest of the .swf and i can't work out why its not working. Does anyone have any ideas or suggestions?

Thanks in advance

P.S. the pink bit is just a variation of the remove button, which removes the thing but also leaves the photos in place


----------



## jbm1991 (Sep 1, 2007)

In the external .swf i'm using, the photos are loaded by a "pic_loader" Loader, so im wondering if its not unloading that loader and thus leaving it stranded in the middle of my project. and so how would i be best going about unloading this loader?

Please note, the source code for the .swf im having problems with is free to download, and i mentioned the link in my last post 

Thanks again


----------



## -Fabez- (Jul 28, 2008)

Okay then, I think I got that  With the removeChild function, you need to target the Holder_mc movie clip, not the loader instance, so the code becomes.


```
removeChild(NameOfHolder)
```


----------

