|
-
replace mouse cursor with image
Hi i have this code which allows me to replace the mouse cursor with an image but i would also like to change the image when the mouse is clicked down using a different image. the code i am using for just replacing the mouse cursor is:
Mouse.hide();
stage.addEventListener(MouseEvent.MOUSE_MOVE,follo w);
function follow(evt:MouseEvent){
hover1_mc.x = mouseX;
hover1_mc.y = mouseY;
}
i tried using a different code which i found but it failed to work with my project can anyone help me please
-
Senior Member
On a mouse click you load a different image into hover1_mc.
- The right of the People to create Flash movies shall not be infringed. -
-
how would i do that sorry if im asking an obvious question
-
Senior Member
Youfirst create a Loader object and add it to the MovieClip.
var myLoader:Loader = new Loader();
hover1_mc.addChild(myLoader);
Then you create a stage eventlistener for the mouse click and load the image into the loader randomly.
stage.addEventListener (MouseEvent.CLICK,loadImage);
function loadImage (evt:MouseEvent)
{
var myURLs:Array = new Array("img1.jpg","img2.jpg");
var ranImg:int = Math.random() * 2;
myLoader.load (new URLRequest(myURLs[ranImg]));
}
- The right of the People to create Flash movies shall not be infringed. -
-
 Originally Posted by cancerinform
Youfirst create a Loader object and add it to the MovieClip.
var myLoader:Loader = new Loader();
hover1_mc.addChild(myLoader);
Then you create a stage eventlistener for the mouse click and load the image into the loader randomly.
stage.addEventListener (MouseEvent.CLICK,loadImage);
function loadImage (evt:MouseEvent)
{
var myURLs:Array = new Array("img1.jpg","img2.jpg");
var ranImg:int = Math.random() * 2;
myLoader.load (new URLRequest(myURLs[ranImg]));
}
that didnt work
-
Senior Member
Create a fla and Movieclip in the library. The id of the clip is holder and the class is Holder. Then put this script in the actions of the main timeline. Do not place the Movieclip on stage. Replace the urls with urls of your own images.
import flash.display.MovieClip;
var hover1_mc:MovieClip = new Holder();
addChild (hover1_mc);
var myLoader:Loader = new Loader();
hover1_mc.addChild (myLoader);
myLoader.load(new URLRequest("noimage.jpg"));
stage.addEventListener (MouseEvent.CLICK,loadImage);
function loadImage (evt:MouseEvent)
{
var myURLs:Array = new Array("kayokitty.png","noimage.jpg");
var ranImg:int = Math.random() * 2;
myLoader.load (new URLRequest(myURLs[ranImg]));
}
Mouse.hide ();
stage.addEventListener (MouseEvent.MOUSE_MOVE,follow);
function follow (evt:MouseEvent)
{
hover1_mc.x = mouseX;
hover1_mc.y = mouseY;
}
- The right of the People to create Flash movies shall not be infringed. -
-
this code makes both images appear at the same time side by side :S
this is how i have edited the code:
Actionscript Code:
import flash.display.MovieClip;
var hover1_mc:MovieClip = new Holder(); addChild (hover1_mc); var myLoader:Loader = new Loader(); hover1_mc.addChild (myLoader); myLoader.load(new URLRequest("hover.png")); stage.addEventListener (MouseEvent.CLICK,loadImage); function loadImage (evt:MouseEvent) { var myURLs:Array = new Array("click.png","hover.png"); var ranImg:int = Math.random() * 2; myLoader.load (new URLRequest(myURLs[ranImg])); }
Mouse.hide (); stage.addEventListener (MouseEvent.MOUSE_MOVE,follow); function follow (evt:MouseEvent) { hover1_mc.x = mouseX; hover1_mc.y = mouseY; }
Last edited by dt10jja; 02-03-2012 at 01:13 AM.
-
Senior Member
The path to your image is not correct.
- The right of the People to create Flash movies shall not be infringed. -
-
i was getting an error saying that before then i made sure both of my images were on mydesktop where the swf and fla files are.
-
Senior Member
Place fla and images into a folder and try again and make sure the location of the swf is in the same place.
- The right of the People to create Flash movies shall not be infringed. -
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|