[Flashcoders] trouble with adding/removing multiple preloaders on thumbs

2009-09-18 Thread thomas horner
i  have set up a thumbnail image gallery that drags images from an external
xml file, however now i have come the point of adding a preloader, i want to
add a preloader to each of the thumbnails, however it only seems to work for
one thumbnail or image, if i just target [0] it works fine, but when i add
the preloader to all my image containers and then try to remove them all it
trips up, 

 

 

 

 

TypeError: Error #1009: Cannot access a property or method of a null object
reference.

at MethodInfo-448()

at Function/http://adobe.com/AS3/2006/builtin::apply()

at gs::TweenLite/complete()

at gs::TweenLite/render()

at gs::TweenLite$/updateAll()

 

 

my code is below;

 

 

my_images=myXML.IMAGE;

my_total=my_images.length();

 

function callThumbs():void {

for (var s:Number = 0; s < my_total; s++) {

var thumb_url=my_images[...@small;

var thumb_loader = new Loader();

thumb_loader.load(new URLRequest(thumb_url));

thumb_loader.contentLoaderInfo.addEventListener(Event.COMPLETE,
thumbLoaded);

//add preloader to the container

var preloader:starPreloader = new starPreloader();

container1.addChild(preloader);

container1.preloader=preloader;

 

thumb_loader.name=s;

container1.buttonMode=true;

thumb_loader.y = (100+5)*s;

zoom.small.addChild(container1);

container1.addEventListener(MouseEvent.CLICK, callFull);

loadedImages ++;

 

}

}

 

function thumbLoaded(e:Event):void {

var my_thumb:Loader=Loader(e.target.loader);

var holder:MovieClip=container1[loadedImages];

 

TweenLite.to(container1.preloader, 1, {scaleX: 0, scaleY: 0, alpha: 0,
onComplete:thumbFinished, onCompleteParams:[container1.preloader, holder]});

 

container1.addChild(my_thumb);

}

 

function thumbFinished(preloader:MovieClip, container1:MovieClip):void {

container1.removeChild(preloader);

//Remove the preloader

}

 

 

 

___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


RE: [Flashcoders] trouble with adding/removing multiple preloaders on thumbs

2009-09-19 Thread Keith Reinfeld
Thomas, 

I think the example code below addresses your primary concerns. The biggest
changes involve using a loaderArray to prevent overwriting previous Loader()
assignments, and also using getChildByName() to grab the relevant preloader
instance for removal. See inline comments. Let me know if you have any
questions. 
So, did you work out your image panning interaction? 

Code: 

import gs.TweenLite; 

var myXML:XML =  
 
 
 
 
 
; 
 
 
var container1:MovieClip = new MovieClip(); 
var loaderArray:Array = []; 
addChild(container1); 
var my_images:XMLList = myXML.IMAGE; 
var my_total:Number = my_images.length();  
 
callThumbs(); 
 
function callThumbs():void { 
for (var s:Number = 0; s < my_total; s++) { 
var thumb_url:String = my_images[...@small; 
// Store each Loader separately as an array element 
// so it won't be overwritten by the next. - KR 
loaderArray[s] = new Loader(); 
loaderArray[s].load(new URLRequest(thumb_url)); 

loaderArray[s].contentLoaderInfo.addEventListener(Event.COMPLETE,thumbLoaded
);  
var preloader:starPreloader = new starPreloader();  
// Name the preloader instance after the current url's 
// filename so we can pick-up on it later. - KR 
preloader.name =
thumb_url.substr(thumb_url.lastIndexOf("/")+1); 
loaderArray[s].y = 105 * s; 
// I am not putting the preloader 'in' the thumbnail, 
// just overlaying it. - KR 
preloader.y = 105 * s; 
//add preloader to the container 
container1.addChild(preloader); 
container1.buttonMode = true; 
// The next two lines caused reference errors for me - KR 
//zoom.small.addChild(container1); 
//container1.addEventListener(MouseEvent.CLICK, callFull); 
} 
} 
 
function thumbLoaded(e:Event):void { 
var my_thumb:Loader=Loader(e.target.loader); 
// Display the thumbnail image behind the preloader. - KR 
container1.addChildAt(my_thumb,0); 
// Here is where we identify the preloader that 
// corresponds with the current thumbnail image. - KR 
var currentURL:String = e.currentTarget.url; 
var preloaderName:String =
currentURL.substr(currentURL.lastIndexOf("/")+1); 
trace("\npreloaderName =",preloaderName); 
var preloader:starPreloader =
container1.getChildByName(preloaderName) as starPreloader; 
TweenLite.to(preloader, 1, {scaleX: 0, scaleY: 0, alpha: 0,
onComplete:thumbFinished, onCompleteParams:[container1, preloader]}); 
} 
 
function thumbFinished(mc:MovieClip, mc2:starPreloader):void { 
trace("\nthumbFinished() called",mc.name,mc2.name); 
//Remove the preloader 
mc.removeChild(mc2); 
} 


Regards,

Keith Reinfeld
Home Page: http://keithreinfeld.home.comcast.net



___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


RE: [Flashcoders] trouble with adding/removing multiple preloaders on thumbs

2009-09-19 Thread thomas horner
Hi many thanks, will check this out in a sec, just having a full english
breakfast, yes managed to do the product zoomer with a lot of help from
'Cor' on here. it works really well, and i've made it kind of dynmaic so you
can select different angles to zoom, you are quite welcome to the fla is you
want,

thanks, Thomas

-Original Message-
From: flashcoders-boun...@chattyfig.figleaf.com
[mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Keith
Reinfeld
Sent: 19 September 2009 07:52
To: 'Flash Coders List'
Subject: RE: [Flashcoders] trouble with adding/removing multiple preloaders
on thumbs

Thomas, 

I think the example code below addresses your primary concerns. The biggest
changes involve using a loaderArray to prevent overwriting previous Loader()
assignments, and also using getChildByName() to grab the relevant preloader
instance for removal. See inline comments. Let me know if you have any
questions. 
So, did you work out your image panning interaction? 

Code: 

import gs.TweenLite; 

var myXML:XML =  
 
 
 
 
 
; 
 
 
var container1:MovieClip = new MovieClip(); 
var loaderArray:Array = []; 
addChild(container1); 
var my_images:XMLList = myXML.IMAGE; 
var my_total:Number = my_images.length();  
 
callThumbs(); 
 
function callThumbs():void { 
for (var s:Number = 0; s < my_total; s++) { 
var thumb_url:String = my_images[...@small; 
// Store each Loader separately as an array element 
// so it won't be overwritten by the next. - KR 
loaderArray[s] = new Loader(); 
loaderArray[s].load(new URLRequest(thumb_url)); 

loaderArray[s].contentLoaderInfo.addEventListener(Event.COMPLETE,thumbLoaded
);  
var preloader:starPreloader = new starPreloader();  
// Name the preloader instance after the current url's 
// filename so we can pick-up on it later. - KR 
preloader.name =
thumb_url.substr(thumb_url.lastIndexOf("/")+1); 
loaderArray[s].y = 105 * s; 
// I am not putting the preloader 'in' the thumbnail, 
// just overlaying it. - KR 
preloader.y = 105 * s; 
//add preloader to the container 
container1.addChild(preloader); 
container1.buttonMode = true; 
// The next two lines caused reference errors for me - KR 
//zoom.small.addChild(container1); 
//container1.addEventListener(MouseEvent.CLICK, callFull); 
} 
} 
 
function thumbLoaded(e:Event):void { 
var my_thumb:Loader=Loader(e.target.loader); 
// Display the thumbnail image behind the preloader. - KR 
container1.addChildAt(my_thumb,0); 
// Here is where we identify the preloader that 
// corresponds with the current thumbnail image. - KR 
var currentURL:String = e.currentTarget.url; 
var preloaderName:String =
currentURL.substr(currentURL.lastIndexOf("/")+1); 
trace("\npreloaderName =",preloaderName); 
var preloader:starPreloader =
container1.getChildByName(preloaderName) as starPreloader; 
TweenLite.to(preloader, 1, {scaleX: 0, scaleY: 0, alpha: 0,
onComplete:thumbFinished, onCompleteParams:[container1, preloader]}); 
} 
 
function thumbFinished(mc:MovieClip, mc2:starPreloader):void { 
trace("\nthumbFinished() called",mc.name,mc2.name); 
//Remove the preloader 
mc.removeChild(mc2); 
} 


Regards,

Keith Reinfeld
Home Page: http://keithreinfeld.home.comcast.net



___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


RE: [Flashcoders] trouble with adding/removing multiple preloaders on thumbs

2009-09-19 Thread thomas horner
Hi Keith. many thanks for your help with this i've tried to implement it, it
now loads up the array of preloaders but when it comes to removing them it
still trips up with the following error;

any ideas, cheers, Thomas

thumbFinished() called instance935 top.png
ArgumentError: Error #2025: The supplied DisplayObject must be a child of
the caller.
at flash.display::DisplayObjectContainer/removeChild()
at MethodInfo-448()
at Function/http://adobe.com/AS3/2006/builtin::apply()
at gs::TweenLite/complete()
at gs::TweenLite/render()
at gs::TweenLite$/updateAll()




code


my_images=myXML.IMAGE;
my_total=my_images.length();


var loaderArray:Array=[];


callThumbs();

function callThumbs():void {
for (var s:Number = 0; s < my_total; s++) {
var
thumb_url:string=my_images[...@small;
// Store each Loader separately as
an array element 
// so it won't be overwritten by the
next. - KR 
loaderArray[s] = new Loader();
loaderArray[s].load(new
URLRequest(thumb_url));


loaderArray[s].contentLoaderInfo.addEventListener(Event.COMPLETE,thumbLoaded
);
var preloader:starPreloader = new
starPreloader();
// Name the preloader instance after
the current url's 
// filename so we can pick-up on it
later. - KR 

preloader.name=thumb_url.substr(thumb_url.lastIndexOf("/")+1);
loaderArray[s].y=105*s;
// I am not putting the preloader
'in' the thumbnail, 
// just overlaying it. - KR 
preloader.y=105*s;
//add preloader to the container 
container1.addChild(preloader);

container1.addEventListener(MouseEvent.CLICK, callFull);
container1.buttonMode=true;

//this is just a nested movielcip 
zoom.small.addChild(container1);
// The next two lines caused
reference errors for me - KR 
}
}


function thumbLoaded(e:Event):void {
var my_thumb:Loader=Loader(e.target.loader);
// Display the thumbnail image behind the
preloader. - KR 
container1.addChildAt(my_thumb,0);
// Here is where we identify the preloader
that 
// corresponds with the current thumbnail
image. - KR 
var currentURL:String=e.currentTarget.url;
var
preloaderName:String=currentURL.substr(currentURL.lastIndexOf("/")+1);
trace("\npreloaderName =",preloaderName);
var
preloader:starPreloader=container1.getChildByName(preloaderName) as
starPreloader;
TweenLite.to(preloader, 1, {scaleX: 0,
scaleY: 0, alpha: 0, onComplete:thumbFinished, onCompleteParams:[container1,
preloader]});
}

function thumbFinished(mc:MovieClip,
mc2:starPreloader):void {
trace("\nthumbFinished()
called",mc.name,mc2.name);
//Remove the preloader 
mc.removeChild(mc2);
}

___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders