Or you can use the MovieClipLoader()...
//
// DATA
//
imageData =
{
dir: "models/",
ext: ".jpg",
images: [
{title:'myfirst', path:"image1"},
{title:'mysecond', path:"image2"}
],
clips: []
};
//
// CREATE
//
var xspace = 100;
var yspace = 100;
var holder = this.createEmptyMovieClip ( 'holder',
this.getNextHighestDepth();
var len = imageData.images.length;
for (i = 0; i < len; i++)
{
var mc = holder.createEmptyMovieClip ( 'mc_'+ i,
holder.getNextHighestDepth() )
mc.image = mc.createEmptyMovieClip ( 'image',
mc.getNextHighestDepth() )
mc.loader = new MovieClipLoader();
mc.loader.addListener( mc );
mc.onLoadInit = proxyBEFORE ( this, image_onLoadInit, i );
mc.onLoadError = proxyBEFORE ( this, image_onLoadError, i );
mc.loader.loadClip( imageData.dir + imageData.images[i].path +
imageData.ext, mc.image );
mc.id = i;
mc._x= xspace * -i;
mc._y = yspace * i;
imageData.clips.push ( mc );
}
//
// LOADING
//
function image_onLoadError ( id, image )
{
var mc = imageData.clips [ id ];
trace( 'image not loaded for: ' + mc );
}
function image_onLoadInit ( id, image )
{
var mc = imageData.clips [ id ];
delete mc.loader;
delete mc.onLoadInit;
mc.onRollOver = function()
{
var title = imageData.images [ id ].title;
var path = imageData.images [ id ].path;
trace( 'title: ' + title + ' path: ' + path )
}
}
//
// PROXY
//
function proxyBEFORE (s:Object, func:Function):Function
{
// from jgDelegate
var a:Array = arguments.slice(2, arguments.length);
return function ():Void { func.apply(s, a.concat(arguments));};
}
_____________________________
Jesse Graupmann
www.jessegraupmann.com
www.justgooddesign.com/blog/
_____________________________
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of David Ngo
Sent: Friday, April 06, 2007 12:30 PM
To: [email protected]
Subject: RE: [Flashcoders] attaching an event to a movie clip
Personally, I find onEnterFrames bad practice to use unless you absolutely
have to (if your logic is frame-based, etc). I would suggest the nested clip
and/or use MovieClipLoader to handle your image loading.
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of john
robinson
Sent: Friday, April 06, 2007 11:48 AM
To: [email protected]
Subject: Re: [Flashcoders] attaching an event to a movie clip
You have 2 choices so far... you can set up a poll (using onEnterFrame)
to figure out when the images have finished loading and then attach the
events or you can do as David suggested and nest your images inside
another clip. I don't really know if either solution is better than the
other, but with the code you already have and what David suggested you
can make a few changes and probably get by. Some code:
var models = new Array();
models = [ "model1", "model2", "model3", "model4"];
trace(models.length);
for (i=0; i<models.length; i++){
movieName=models[i];
var newMC= this.container1.createEmptyMovieClip(movieName, 0+i);
// create another mc inside newMC to load your images into
var img_mc = newMC.createEmptyMovieClip("image_mc", 1);
// load your image
img_mc.loadMovie("models/"+movieName+".jpg");
newMC._x=100*-i;
newMC._y=100*i;
trace (newMC);// so far works until here, creating the movieclips
and
loading the pics inside then and assigning them a respective value for
x and y
///from now on, I got the problem, it appear that can't accept any
event in the movie clips
newMC.onRollOver= function(){
trace("hello");
}
}
Hope it helps. Keep in mind that this doesn't let you adjust the size
of the image. For that you'll have to go the other route and wait until
the image has fully loaded. You could do that using the code above, but
attach an onEnterFrame to your "newMC"... like so:
newMC.onEnterFrame = function() {
var bl = img_mc.getBytesLoaded();
var bt = img_mc.getBytesTotal();
if(bl == bt && bt > 0) {
delete this.onEnterFrame;
// your image is now loaded... do whatever you want here.
}
}
John
On Apr 6, 2007, at 2:25 PM, Gustavo Duenas wrote:
> I did, but it is the same...nothing so far...I guess that one of you
> maybe have been in this problem before...so I'd like to know how can I
> finish it.
>
>
> Regards
>
>
> Gustavo
> On Apr 6, 2007, at 2:04 PM, Rost, Andrew wrote:
>
>> newMC.rollOver
>>
>> Should be:
>>
>> newMC.onRollOver
>>
>> HTH
>>
>> -----Original Message-----
>> From: Gustavo Duenas [mailto:[EMAIL PROTECTED]
>> Sent: Friday, April 06, 2007 12:43 PM
>> To: [email protected]
>> Subject: [Flashcoders] attaching an event to a movie clip
>>
>> Hi , Ok it doesn't sound as simple,
>>
>> I've created a series of empty movieclips which loads pics from an
>> array, so far it loads perfectly but I can attach to the newly
>> created movie clip any kind of
>> events.
>>
>> I'm using this.
>>
>> stop();
>>
>> var models = new Array();
>>
>> models = [ "model1", "model2", "model3", "model4"];
>>
>> trace(models.length);
>> for (i=0; i<models.length; i++){
>> movieName=models[i];
>> var newMC= this.container1.createEmptyMovieClip(movieName, 0+i);
>> newMC.loadMovie("models/"+movieName+".jpg");
>> newMC._x=100*-i;
>> newMC._y=100*i;
>> trace (newMC);// so far works until here, creating the movieclips
>> and loading the pics inside then and assigning them a respective
>> value for x and y
>>
>> ///from now on, I got the problem, it appear that can't accept any
>> event in the movie clips
>> newMC.rollOver= function(){
>> trace("hello");
>> }
>>
>> }
>>
>> I hope you got it...because I'm still dont get it.
>>
>> Regards
>>
>>
>> Gustavo Duenas
>>
_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com