codacopia
codacopia

Reputation: 2501

How can I link movie clip to URL via Flash Actionscript 2.0?

I am trying to turn a movie clip into a button once the graphic catches your mouse as shown here:

http://www.kirupa.com/developer/mx/followease.htm

So, when the circle catches up to your mouse you have the option to click on that circle and go to a specified URL. Is this possible, if so how?

==============================

These notes are from the various responses thus far. I am still getting errors and cannot get the clip to function properly. Here is the exact code that I am applying to the movie clip (mc):

onClipEvent (load) {
_x = 0;
_y = 0;
speed = 5;
}
onClipEvent (enterFrame) {
endX = _root._xmouse;
endY = _root._ymouse;
_x += (endX-_x)/speed;
_y += (endY-_y)/speed;

import flash.net.navigateToURL;
import flash.net.URLRequest;
import flash.events.MouseEvent;

// assuming the movie clip is called mc
mc.onRelease = function() {
getURL("http://www.google.com");
}

Any further suggestions are much appreciated and thanks for those who have contributed thus far.

Upvotes: 1

Views: 5413

Answers (3)

Chris
Chris

Reputation: 1094

  1. onClipEvent(enterframe) has unmatched }
  2. those import statements are for AS3
  3. if you're going to put the script directly on a movieclip (that is, select it with mouse and press F9 to bring up the script panel, and paste the code on it), you don't have to use its name (mc)

try pasting this on the movie clip~

onClipEvent(load) {
    _x = 0;
    _y = 0;
    speed = 5;
}

onClipEvent(enterFrame) {
    endX = _root._xmouse;
    endY = _root._ymouse;
    _x += (endX-_x)/speed;
    _y += (endY-_y)/speed;
}

onClipEvent(mouseUp) {
    getUrl("http://www.google.com");
}

Upvotes: 2

Daniel MesSer
Daniel MesSer

Reputation: 1181

Following up on the solution provided by @Chris but in an AS2-context

in the code sample, mc is a link to the circle movie clip that is following the mouse

mc.onRelease = function() {
    getURL("http://www.google.com");
}

Upvotes: 0

Chris
Chris

Reputation: 1094

you can simply add a click handler to your movie clip and use flash.net.navigateToURL to go to a specified URL.

import flash.net.navigateToURL;
import flash.net.URLRequest;
import flash.events.MouseEvent;

// assuming the movie clip is called mc
mc.addEventListener(MouseEvent.CLICK, onClick);
var url: String = "http://www.google.com"
function onClick(event: MouseEvent): void {
    navigateToURL(new URLRequest(url))
}

Upvotes: 1

Related Questions