Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

stopping a MC on ROLL_OUT

Status
Not open for further replies.

zdvdla

Technical User
Apr 28, 2007
18
US

Ive been trying all day and cant get the MC to stop playing.
I have a MC that I want to play over buttons when they are rolled over.
Class sparkle.
I want the MC to stop when the user rolls out.

I dont understand why Im getting this error or what the best way to achieve my desired result.

//Btn_Home_mc the instance of a particular button

Btn_Home_mc.buttonMode = true;

Btn_Home_mc.addEventListener(MouseEvent.ROLL_OVER, HomeSpark);
Btn_Home_mc.addEventListener(MouseEvent.ROLL_OUT, HomeSparkClear);


function HomeSpark(event:MouseEvent):void

{
if (spark == null)
{
var spark:sparkle = new sparkle;
addChild(spark);
spark.x = 256.1;
spark.y = 276.7;

}
}

function HomeSparkClear(event:MouseEvent):void

{

removeChild(spark);

}

ERROR

ReferenceError: Error #1065: Variable spark is not defined.

I tried every possible variation of moving and calling but dont get it..
please help...
thanks
 
tried this too


Btn_Home_mc.buttonMode = true;

Btn_Home_mc.addEventListener(MouseEvent.ROLL_OVER, HomeSpark);
Btn_Home_mc.addEventListener(MouseEvent.ROLL_OUT, HomeSparkClear);


function HomeSpark(event:MouseEvent):void

{
if (spark == null)
{
var spark:sparkle = new sparkle;
addChild(spark);
spark.x = 256.1;
spark.y = 276.7;


}
}

function HomeSparkClear(event:MouseEvent):void

{
HomeSpark.stop();

}

ERROR

ReferenceError: Error #1069: Property stop not found on builtin.as$0.MethodClosure and there is no default value.
 
this doesnt work either


Btn_Home_mc.buttonMode = true;

Btn_Home_mc.addEventListener(MouseEvent.ROLL_OVER, HomeSpark);
Btn_Home_mc.addEventListener(MouseEvent.ROLL_OUT, HomeSparkClear);


function HomeSpark(event:MouseEvent):void

{
if (spark == null)
{
var spark:sparkle = new sparkle;
addChild(spark);
spark.x = 256.1;
spark.y = 276.7;


}
}

function HomeSparkClear(event:MouseEvent):void

{
sparkle.stop();

}

ERROR

TypeError: Error #1006: stop is not a function.

what?
 
This works - But still throws an error- is that a killer error?


Btn_Home_mc.buttonMode = true;

Btn_Home_mc.addEventListener(MouseEvent.ROLL_OVER, HomeSpark);
Btn_Home_mc.addEventListener(MouseEvent.ROLL_OUT, HomeSparkClear);


function HomeSpark(event:MouseEvent):void

{
if (spark == null)
{
var spark:sparkle = new sparkle;
addChild(spark);
spark.x = 256.1;
spark.y = 276.7;


Btn_Home_mc.addEventListener(MouseEvent.ROLL_OUT, HomeSparkClear);

function HomeSparkClear(event:MouseEvent):void
{
removeChild(spark);
}

}
}

ERROR

ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
at flash.display::DisplayObjectContainer/removeChild()
at MethodInfo-324()
 
Code:
//Main timeline
btn_Home_mc.addEventListener(MouseEvent.ROLL_OVER, homeSpark);
btn_Home_mc.addEventListener(MouseEvent.ROLL_OUT, homeSparkClear);

var spark:Sparkle;

function homeSpark(evt:MouseEvent):void {
	if (spark == null) {
		spark = new Sparkle();
		this.addChild(spark);
		spark.x = 100;
		spark.y = 100;
	}
	spark.play();
}

function homeSparkClear(evt:MouseEvent):void {
	spark.stop();
}

Kenneth Kawamoto
 

thanks Ken

I ended up using this...

Btn_Home_mc.buttonMode = true;

Btn_Home_mc.addEventListener (MouseEvent.ROLL_OVER, HomeSpark);
Btn_Home_mc.addEventListener (MouseEvent.ROLL_OUT, HomeSparkClear);


function HomeSpark (event:MouseEvent):void
{
if (spark == null)
{
var spark:sparkle = new sparkle();
spark.name = "spark";
addChild (spark);
spark.x = 256.1;
spark.y = 276.7;
}
}

function HomeSparkClear (event:MouseEvent):void
{
try
{
removeChild (getChildByName("spark"));
}
catch (e:Error)
{
trace("Error");
}
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top