[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 370
  • Last Modified:

Play on Rollover in Flash

I am trying to find a SIMPLE play on rollover script for actionscript 3 and I cant find anything that even comes close to doing what I need. I have an image that I want to move to the left for 120 frame and then stop. I can do the motion part but the actionscript part that tells the image to move on rollover I can not figure out. I would also like for when someone rolls off of the image during play I would like for it to reverse play. How can I achive this? The world of actionscript is new any 101 instructional would be nice as well.

Thanks
0
thebradnetwork
Asked:
thebradnetwork
  • 4
  • 2
1 Solution
 
AreDubyaCommented:
thebradnetwork,

Below is some simple code to move the image. It assumes you have a picture on stage with an instance name of pictureName, and that that picture's starting x position is 100. You can change any of that. To test, start a new movie, put all this code in frame one (there should be only one frame), and put the picture onstage at x = 100. I think you will get the idea after that.

AreDubya

var origX:Number = 100; //Example of original coordinate

pictureName.addEventListener(MouseEvent.MOUSE_OVER, forward);
//Makes picture listen for mouse to enter
pictureName.addEventListener(MouseEvent.MOUSE_OUT, reverse);
//Makes picture listen for mouse to leave

function forward(event:MouseEvent):void
{
	stage.addEventListener(Event.ENTER_FRAME, goForward);
}

function reverse(event:MouseEvent):void
{
	///Movement code here
	stage.removeEventListener(Event.ENTER_FRAME, goForward);
	stage.addEventListener(Event.ENTER_FRAME, goBack);
}

function goForward(event:Event):void
{
	pictureName.x = pictureName.x + 1;
}

function goBack(event:Event):void
{
	pictureName.x = pictureName.x - 1;
	if(pictureName.x <= origX)
	{
		stage.removeEventListener(Event.ENTER_FRAME, goBack);
	}
}

Open in new window

movePic.fla
0
 
AreDubyaCommented:
thebradnetwork,

Another version, this one using the tween class. While these aren't technically go to and Play (you could navigate that way, code below) they get your image moved independent of the timeline. That would be more in keeping with the AS3 thing...

AreDubya
pictureName.addEventListener(MouseEvent.MOUSE_OVER, go);
pictureName.addEventListener(MouseEvent.MOUSE_OUT, goBack);

function go(e:MouseEvent):void
{
	this.gotoAndPlay(frameLabelOrNumber);
}

function goBack(e:MouseEvent):void
{
	this.gotoAndPlay(frameLabelOrNumber);
}

Open in new window

movePicTween.fla
0
 
thebradnetworkAuthor Commented:
I have played with this but I haven't been successful in getting it to work. I have attached the FLA file that I am trying to implement this with. All I am trying to do is have to logo scroll away and show the text behind the logo.
slide.fla
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
AreDubyaCommented:
See how this works for you. One tip - instead of placing the text by itself on it's layer, I added a black background to it. Before, once the logo slid by if your mouse wasn't on top of the text the MOUSE_OUT event was fired. So, by giving it a background we fill the whole space after the logo goes by, so we don't trigger the event too early.

AreDubya
slide.fla
0
 
thebradnetworkAuthor Commented:
Awesome! One more question. I cant get it to do a link. If i put the following string of code in it goes crazy.
on (release) {
    getURL ("http://www.domainname.com/html_file_name", "_blank");
}

Open in new window

0
 
sheepfactoryCommented:
try this instead of getURL:

navigateToURL(new URLRequest("http://www.domainname.com/html_file_name"), "_blank");
0
 
AreDubyaCommented:
thebradnetwork,

Hey. Not sure where you were putting the code, so I plugged it into fla.

Let me know how this works for you.

AreDubya
slide.fla
0

Featured Post

Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now