Groups | Blog | Home
all groups > flash actionscript > october 2006 >

flash actionscript : onRollover problems


Carly G
10/21/2006 9:35:25 PM
I'm creating a XML photogallery, and have created movieClips with the loaded
jpg from the XML using createEmptyMovieClip. The problem is that onRollover
doesn't work. Does the hit area not include the loaded jpg?

Here's what I have




slides_xml = new XML();
slides_xml.onLoad = startSlideShow;
slides_xml.load("photoGallery.xml");
slides_xml.ignoreWhite = true;


function startSlideShow(success) {
if (success == true) {
rootNode = slides_xml.firstChild;
totalSlides = rootNode.childNodes.length;
firstSlideNode = rootNode.firstChild;
var i = 0;
var xPos = 35;
var yPos = 35;
thisDepth = 100;
var currentSlide = rootNode.firstChild;

while (( i < totalSlides) && ( i < 10))
{
var buttonName = "btn" + i;
_root.createEmptyMovieClip(buttonName, thisDepth);
_root[buttonName]._x = xPos;
_root[buttonName]._y = yPos;
_root[buttonName]._xscale = _root[buttonName]._yscale = 20;

_root[buttonName].jpeg = currentSlide.attributes.jpegURL;
_root[buttonName].picTitle = currentSlide.attributes.picTitle;
_root[buttonName].loadMovie(_root[buttonName].jpeg);
_root[buttonName].hitArea = mcHit;


_root[buttonName].onRollOver = function ()
{
_root.txtDescription.text = _root[buttonName].picTitle;
}

currentSlide = currentSlide.nextSibling;
yPos = yPos + 75;
thisDepth = thisDepth + 1
i++;
if (yPos > 400)
{
yPos = 40;
xPos = xPos + 90;
}
}
}
}
kglad
10/21/2006 11:26:32 PM
Moonster
10/22/2006 12:00:00 AM
Loading anything into a movieclip overwrites all properties (except _x,
_y and maybe a few others).

The result, in your case, is that .jpeg, .picTitle .hitArea and
..onRollOver is all gone when the image is finished loading.

The easiest way out is to create a child movieclip and load the image
into that.

like this:


....
var mcButton = _root.createEmptyMovieClip(buttonName, thisDepth);
mcButton._x = xPos;
mcButton._y = yPos;
mcButton._xscale = _root[buttonName]._yscale = 20;
mcButton.jpeg = currentSlide.attributes.jpegURL;
mcButton.picTitle = currentSlide.attributes.picTitle;
// create child movieclip:
mcButton.mcImage = mcButton.createEmptyMovieClip("mcImage", 1);
// and load image into that one:
mcButton.mcImage.loadMovie(_root[buttonName].jpeg);
mcButton.hitArea = mcHit;
....


This way all only properties of mcButton.mcImage is overwritten :)

- Magnus

[quoted text, click to view]
AddThis Social Bookmark Button