View Full Version : onrollover attachmovie problem in as3
rosanna
November 3rd, 2009, 10:19 AM
Hi,
I have been letting flash/As 2 and AS for quite a while now. But my new project needs a blend of Html AND Flash.
For the first time I'll use as3 and It seems that the so-useful onrollover / attachmovie does not work anymore.
What am I supposed to do now to achieve the same function ?
My purpose is simple :
13 movie clips, each one of them has to show onrollover a different thumb_mc.
I googled and found some answers.
I get the addeventlistener thing, but can not figure out a decent attachmovie function
I am confused.
Could somebody help me ?
Thank you !
snickelfritz
November 3rd, 2009, 12:13 PM
Not sure if this is precisely what you're looking for.
This example basically works like a tooltip.
Setup: there are two MovieClips in the Library:
One MovieClip for the button, with class export name of "Btn".
ie: a shape within a movieclip.
One MovieClip for the thumbnails, with class Export name of "Thumbs".
On the timeline within Thumbs, each thumbnail (bitmap/graphic/text), is placed on successive frames.
ie: thumb1 is on frame1, thumb2 is on frame2, and so forth.
The script instantiates one button for each thumbnail.
The thumbnails are instantiated and pushed into an array;
On mouse over, the thumbnail at the array index matching the button id is added to the stage.
On mouse out, the thumbnail is removed from the stage and set to null.
var temp:Thumbs = new Thumbs();// used only to establish the number of frames within Thumbs.
var n:int = temp.totalFrames;// assign the number of frames within Thumbs to a variable.
temp = null;// temp is no longer needed.
var thumbs:Array = new Array();// array to hold references to the thumbs
var thumb:MovieClip;// variable to represent the thumbnail
var thumbHolder:Sprite = new Sprite();// create a parent container for the thumbs.
addChild(thumbHolder);
// for..loop instantiates one button for each frame in Thumbs and places them in a column on the stage.
// the thumbnails are then instantiated, assigned properties relative to the buttons, and pushed into the array
for (var i:int = 0; i < n; i++)
{
var b:Btn = new Btn();
b.id = i;
b.y = b.height * i;
b.buttonMode = true;
b.addEventListener(MouseEvent.ROLL_OVER, addThumb);
b.addEventListener(MouseEvent.ROLL_OUT, removeThumb);
addChild(b);
var t:Thumbs = new Thumbs();
t.gotoAndStop(i+1);
t.x = b.width;
t.y = b.y;
thumbs.push(t);
}
function addThumb(e:MouseEvent):void
{
thumb = MovieClip(thumbs[e.target.id]);
thumbHolder.addChild(thumb);
}
function removeThumb(e:MouseEvent):void
{
thumbHolder.removeChildAt(0);
thumb = null;
}
Tweening the thumbnails works exactly the same way it did in AS2.
siteoner
November 3rd, 2009, 02:32 PM
Hi,
Yes, the in AS 3 they got rid of attachMovie(). They replaced it with addChild(). Take a look at this post I wrote about it. http://theactionscripter.com/2009/04/20/as3-attachmovie-from-library.aspx I have a working demo and code example that may help you.
Let me know.
AHernandez
November 3rd, 2009, 02:41 PM
There is no "attachMovie". What you do is define a custom class where you set the linkage id. Then to create an instance of this class you do:
var myClip:myClass = new myClass();
addChild(myClip);
rosanna
November 4th, 2009, 02:31 AM
Thank you so much everyone for all your answers !!!
I am gonna work on it.
Have a nice day ;-)
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.