PDA

View Full Version : how convert this rollOver to AS3?



sank
July 30th, 2008, 11:38 PM
been trying to crack this one - it's just a simple rollover, but my AS3 attempt (below the AS2 version here) only plays the first frame when it should roll...

// AS2:

function startRoll() {
this.nextFrame();
}
function stopRoll() {
this.prevFrame();
}

// button:
bttn.onRollOver = function() {
this.onEnterFrame = startRoll;
};
bttn.onRollOut = function() {
this.onEnterFrame = stopRoll;
};
bttn.onPress = function() {
getURL("http://www.site.com","_blank");
}




// AS3:

bttn.addEventListener(MouseEvent.MOUSE_OVER, startRoll);
bttn.addEventListener(MouseEvent.MOUSE_OUT, stopRoll);

function startRoll(event:MouseEvent):void{
MovieClip(this).bttn.nextFrame();
}
function stopRoll(event:MouseEvent):void{
MovieClip(this).bttn.prevFrame();
}
bttn.addEventListener(MouseEvent.CLICK,enter_url);
function enter_url(evt:Event):void
{
var enter_site:URLRequest = new URLRequest("http://www.site.com");
navigateToURL(enter_site,"_blank");
}

saxx
July 30th, 2008, 11:48 PM
This isn't your code but i didn't want to convert it, heres how to do a rollover alpha function




bt_button.addEventListener(MouseEvent.MOUSE_OUT, mouseOut)
bt_button.addEventListener(MouseEvent.MOUSE_OVER, mouseOver)

function mouseOver(event:MouseEvent):void
{
event.target.alpha = 1;
// instead of event.target you could use the button name or whatever else

}

function mouseOut(event:MouseEvent):void
{
event.target.alpha = .8
}


bt_button.alpha = .8




import flash.events.EventDispatcher;
import flash.display.MovieClip;
this.stop();
function startMovie(event:MouseEvent):void {

this.gotoAndPlay("products");

}

myButton.addEventListener(MouseEvent.CLICK,
startMovie);



thats a frame to frame event

sank
July 31st, 2008, 12:35 PM
hey there,
thanks for the fast reply... i've tried out your code and tried to modify it, but no luck...

the original AS2 code was one of those simple yet cool animations that would play only as long as one mousedOver it, and would reverse the anim on MouseOut...

getting that effect in AS3 shouldnt be so frustrating!
;)

any other suggestions would be sweet!
thanks
s

Rundevo
August 5th, 2008, 06:15 AM
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;
}