PDA

View Full Version : Mouse over on dynamically added MovieClip


vikasumit
08-13-2007, 10:47 AM
Hello,

I have a flash movie in which on main scene I add a scrollPane, and at runtime, I add a MovieClip on scrollpane. This movieclip has no instance on stage, but I pick it from Library.

On this library movie clip (say movie x) I have another movieclips and Dynamic text boxes placed that i set when I add the movie clip on scrollpane.

Now, I want to capture mouseover on these movieclip, such that when a user mouseover on these dynamically added movie on Scroll Pane, will be replaced with another movie clip (in library) or give new look to existing.

Can you please suggest how to d that.

Thanks & Regards

xxneon
08-13-2007, 12:31 PM
whats your current code for adding the movieclip to the scrollpane?

vikasumit
08-13-2007, 12:57 PM
import mx.xpath.XPathAPI;

var rss:XML = new XML();
rss.ignoreWhite = true;

var mergerbg_as:MovieClip= new MovieClip();
mergerbg_sp.contentPath = "merger_bg";
mergerbg_as = mergerbg_sp.content ;

rss.onLoad = function(success:Boolean) {
if (success) {
// Retrieve all titles in the path /rss/channel/item/title.
var titleArray:Array = XPathAPI.selectNodeList(this.firstChild, "/root/product");
var j:Number;
j=0;

for (var i:Number = 0; i < titleArray.length; i++) {
var abc2:MovieClip=mergerbg_as.attachMovie("merger_box","title"+ i, mergerbg_as.getNextHighestDepth());
abc2.txtprice.text=XPathAPI.selectSingleNode(title Array[i],"/product/deal_value/price").firstChild.nodeValue;
... //more similar settings from xml
}

}
} else {
trace("XML loading failed !!!");
}
var abc2:MovieClip=mergerbg_as.attachMovie("black_height30","blank", mergerbg_as.getNextHighestDepth());
mergerbg_sp.invalidate();
};

rss.load("myxml.xml");


Hope that help, its the only code on my main movie.... I have no code what so ever in my complete project except this :)

xxneon
08-13-2007, 01:04 PM
inside the for loop you could try this..

abc2.onRollOver = function {
trace("you rolled over: " + this._name);
}

vikasumit
08-13-2007, 01:08 PM
tell you what you are genius and I am so stupid.. I try abc2.onMouseOver, I try onRollOver within the abc2 library movieclip code, but I doesn't try what you suggest..

which is ofcourse a perfect solution.. however, you make a mistake too


abc.onRollOver = function() {

is the correct line :)

Thanks a lot for your answer

xxneon
08-13-2007, 01:22 PM
yea little typos i always miss when just typing code from my head .. glad it worked for you.

vikasumit
08-13-2007, 01:26 PM
One issue found..

When I place a onRollOut event for abc2, I observe that it is called even when I am rolling over to abc2, but I am on a movieclip that is added on the abc2 movie itemself.

How can I stop that ??so I doesn't lose my rollover for abc2.

Thanks

xxneon
08-13-2007, 01:43 PM
the mc you are rolling over ?? does it just have text in it ??

vikasumit
08-13-2007, 01:52 PM
yes it has three dynamic text field with two white movie that I load images on it.

xxneon
08-13-2007, 02:46 PM
i know that if there is any transperancy in a movieclip .. that can cause weird results when using the onRollOver.. because when the mouse is over the movieclip .. but over 'transparent area' it acts like you roll out of it ..

ie.. you rollover text.. but your mouse is inbetween characters.. it will fire the rollout too..

vikasumit
08-14-2007, 01:37 AM
well I was suspecting this, but what will be work around to this ?

How can I achieve what I want to :)

matbury
08-14-2007, 01:46 AM
Yeah, put a rectangle behind the text fields, inside the MovieClip and make the alpha 0. The mouse will register it even though it's invisible.

vikasumit
08-14-2007, 07:42 AM
Hello,

Thanks your solution works perfect. I add a White Rectangle shape in a new layer, and making that layer the bottom most.

This make it working perfect. However, I doesn't found a way to set its alpha to zero (its shape object). But since I have white background I make it working with white rectangle.. but just curious how can I set its alpha.

Thanks again

xxneon
08-14-2007, 12:13 PM
you would have to make the background a nested movieclip .. so that you can modify the alpha of the background indepentantly.

vikasumit
08-14-2007, 12:57 PM
Not sure how, but I did manage to get it working :D, Thanks a lot

matbury
08-14-2007, 11:20 PM
Hello,

Thanks your solution works perfect. I add a White Rectangle shape in a new layer, and making that layer the bottom most.

This make it working perfect. However, I doesn't found a way to set its alpha to zero (its shape object). But since I have white background I make it working with white rectangle.. but just curious how can I set its alpha.

Thanks again

It's easy to do. You can either:

Select the rectangle.

Click on the color fill icon in the Properties inspector, at the bottom of the screen.

A swatches dialogue box will pop up.

At the top-right of the box you'll see the Alpha property at 100%.

Click in the 100% and type in 0.

Press Enter/Return.

Done!

...or...

Select the rectangle.

Open the Color Mixer window (Shift + F9).

Change the Alpha property there.

Done!


The second option is a bit buggy on my computer.

The rectangle doesn't have to be a MovieClip or Graphic object for this to work.

vikasumit
08-17-2007, 02:32 AM
:) thats easy, I was wondering why I doesn't see that ..

sorry for later reply I was out in mean time :(