View Full Version : [Q] MouseOver on Loader
manfree
June 10th, 2007, 11:08 PM
Hii all
mouseOver.fla has been attached with this thread
Purpose:
When mouse over, the card will be enlarge
Problem:
When MouseOver on MovieClip "card", it works fine ...
However, when Mouse over on the picture. I get lost @_@
Seems the "picHolder" is on the top layer and blocked the MouseEvent ... ????
I really have no idea on how to solve it ??
var ldr:Loader = new Loader();
var url:URLRequest (http://www.kirupa.com/forum/URLRequest) = new URLRequest("http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif");
ldr.load(url);
card.picHolder.addChild(ldr);
card.addEventListener(MouseEvent.MOUSE_OVER, mouseOverHandler);
card.addEventListener(MouseEvent.MOUSE_OUT, mouseOutHandler);
function mouseOverHandler(e:Event):void {
e.target.scaleX = 2;
e.target.scaleY = 2;
}
function mouseOutHandler(e:Event):void {
e.target.scaleX = 1;
e.target.scaleY = 1;
}
Any body could help ?
Thasnk
stephen2earth
June 11th, 2007, 01:16 AM
This any better? if it's what you want, it works, attached is the file
var ldr:Loader = new Loader();
var vUrl:URLRequest = new URLRequest("http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif");
ldr.load(vUrl);
card.picHolder.addChild(ldr);
card.addEventListener(MouseEvent.MOUSE_OVER, mouseOverHandler);
card.addEventListener(MouseEvent.MOUSE_OUT, mouseOutHandler);
function mouseOverHandler(e:Event):void {
card.scaleX = 2;
card.scaleY = 2;
}
function mouseOutHandler(e:Event):void {
card.scaleX = 1;
card.scaleY = 1;
}
This any better?
manfree
June 11th, 2007, 02:20 AM
what about ... if i have more then one card...
Is there a way to simplify the following code ???
var ldr:Loader = new Loader();
var vUrl:URLRequest = new URLRequest("http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif");
ldr.load(vUrl);
card.picHolder.addChild(ldr);
card.addEventListener(MouseEvent.MOUSE_OVER, mouseOverHandler);
card.addEventListener(MouseEvent.MOUSE_OUT, mouseOutHandler);
card2.addEventListener(MouseEvent.MOUSE_OVER, mouseOverHandler);
card2.addEventListener(MouseEvent.MOUSE_OUT, mouseOutHandler);
card3.addEventListener(MouseEvent.MOUSE_OVER, mouseOverHandler);
card3.addEventListener(MouseEvent.MOUSE_OUT, mouseOutHandler);
function mouseOverHandler(e:Event):void {
switch (e.target.name) {
case "card":
card.scaleX = 2;
card.scaleY = 2;
break;
case "card2":
card2.scaleX = 2;
card2.scaleY = 2;
break;
case "card3":
card3.scaleX = 2;
card3.scaleY = 2;
break;
}
}
function mouseOutHandler(e:Event):void {
switch (e.target.name) {
case "card":
card.scaleX = 1;
card.scaleY = 1;
break;
case "card2":
card2.scaleX = 1;
card2.scaleY = 1;
break;
case "card3":
card3.scaleX = 1;
card3.scaleY = 1;
break;
}
}
This any better? if it's what you want, it works, attached is the file
var ldr:Loader = new Loader();
var vUrl:URLRequest = new URLRequest("http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif");
ldr.load(vUrl);
card.picHolder.addChild(ldr);
card.addEventListener(MouseEvent.MOUSE_OVER, mouseOverHandler);
card.addEventListener(MouseEvent.MOUSE_OUT, mouseOutHandler);
function mouseOverHandler(e:Event):void {
card.scaleX = 2;
card.scaleY = 2;
}
function mouseOutHandler(e:Event):void {
card.scaleX = 1;
card.scaleY = 1;
}
This any better?
sasxa
June 11th, 2007, 03:23 AM
make a card class...
package {
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
public class Card extends Sprite {
private var picHolder:Sprite = new Sprite();
public function Card(imgURL:String):void {
var loader:Loader = new Loader();
var request:URLRequest = new URLRequest(imgURL);
loader.load(request);
loader.contentLoaderInfo.addEventListener(Event.CO MPLETE, imgLoad);
addChild(picHolder);
addEventListener(MouseEvent.MOUSE_OVER, mouseOverHandler);
addEventListener(MouseEvent.MOUSE_OUT, mouseOutHandler);
}
private function imgLoad(event:Event):void {
picHolder.addChild(event.currentTarget.loader);
}
private function mouseOverHandler(event:MouseEvent) {
event.currentTarget.scaleX = 2;
event.currentTarget.scaleY = 2;
}
private function mouseOutHandler(event:MouseEvent) {
event.currentTarget.scaleX = 1;
event.currentTarget.scaleY = 1;
}
}
}
and make as many as you like...
import card;
//....
var c1:Card = new Card("img1.jpg");
var c2:Card = new Card("img2.jpg");
btw, didn't check if it actually works, so if there's any errors don't blame me (:
manfree
June 11th, 2007, 04:44 AM
Arr .. i got the following error ??? STill don't know what happen ?
FLA has been attached with this reply
1151: A conflict exists with definition c1 in namespace internal.
var c1:Card = new Card("img1.jpg");
make a card class...
ActionScript Code:
</p>
<p>package {</p>
<p> import flash.display.Sprite;</p>
<p> import flash.events.Event;</p>
<p> import flash.events.MouseEvent;</p>
<p> </p>
<p> public class Card extends Sprite {</p>
<p> </p>
<p> private var picHolder:Sprite = new Sprite();</p>
<p> public function Card(imgURL:String):void {</p>
<p> var loader:Loader = new Loader();</p>
<p> var request:URLRequest = new URLRequest(imgURL);</p>
<p> loader.load(request);</p>
<p> loader.contentLoaderInfo.addEventListe ner(Event.COMPLETE, imgLoad);</p>
<p> </p>
<p> addChild(picHolder);</p>
<p> </p>
<p> addEventListener(MouseEvent.MOUSE_OVER , mouseOverHandler);</p>
<p> addEventListener(MouseEvent.MOUSE_ OUT, mouseOutHandler);</p>
<p> }</p>
<p> private function imgLoad(event:Event):void {</p>
<p> picHolder.addChild(event.currentTarget .loader);</p>
<p> }</p>
<p> private function mouseOverHandler(event:MouseEvent) {</p>
<p> event.currentTarget.scaleX = 2;</p>
<p> event.currentTarget.scaleY = 2;</p>
<p> }</p>
<p> private function mouseOutHandler(event:MouseEvent) {</p>
<p> event.currentTarget.scaleX = 1;</p>
<p> event.currentTarget.scaleY = 1;</p>
<p> }</p>
<p> }</p>
<p>}</p>
<p>
and make as many as you like...
ActionScript Code:
</p>
<p>import card;</p>
<p>//....</p>
<p>var c1:Card = new Card("img1.jpg");</p>
<p>var c2:Card = new Card("img2.jpg");</p>
<p>
btw, didn't check if it actually works, so if there's any errors don't blame me (:
sasxa
June 11th, 2007, 05:14 AM
you're getting that error msg 'cos you made one symbol and named it c1, and than you're trying to make another one using actionScript on timeline...
I must say I didn't work in flash for some time (I use Flex Builder) so can't help you more with this- don't really know how flash treats packages and stuff... I've noticed that I missed some imports in class (flash.display.Loader & flash.net.URLRequest) but there seems to be some more errors.
I hope some other folks will have time to look into it...
manfree
June 11th, 2007, 05:38 AM
Thanks sasxa ~
Now what i can do ...
1) try it in Flex
2) wait for others replies
ha ha ~
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.