|
-
unloading swf's in UI Loader
I am having some problem removing a null object and I realise that I have not been unloading my swf's properly. Could someone take a look at what I have been doing and tell me what I can do to make it better. I am putting my website in an exhibiton of my design work and if it lagged up due to all the clicking it would suck! so its important I get this right I just need a little help if someone wouldn't mind.
Code:
aboutBtn.addEventListener(MouseEvent.CLICK, aboutLoad);
function aboutLoad(e:MouseEvent):void {
ldr.unload();
proLdr.unload();
ldr.source = "about.swf";
}
contactBtn.addEventListener(MouseEvent.CLICK, contactLoad);
function contactLoad(e:MouseEvent):void {
ldr.unload();
proLdr.unload();
ldr.source = "contact.swf";
}
storeBtn.addEventListener(MouseEvent.CLICK, storeLoad);
function storeLoad(e:MouseEvent):void {
ldr.unload();
proLdr.unload();
ldr.source = "store.swf";
}
productsBtn.addEventListener(MouseEvent.CLICK, productsLoad);
function productsLoad(e:MouseEvent):void {
ldr.unload();
proLdr.unload();
this.product.gotoAndPlay(2);
}
-
can anybody help me please. I urgently need help!
-
If this is for an installation, you should really just load all your content in once and add/removeChild the content or turn it in/visible rather than using loaders...you want to get the memory consumption to be as steady as possible (basically run as little code as you can after startup) - the more work you're doing, the more possibility of a memory leak to gum up the works.
Please use [php] or [code] tags, and mark your threads resolved 8)
-
lol wish I hada known that a few days ago haha I can see exactly what you mean. Man I don't have the time to go back and recode it unless its really simple. Im a design student so this AS stuff is all over my head and I gota get it done would you mind explaining how I can do it cos I don't know.
-
Load up the content all at once:
PHP Code:
var about:MovieClip;
var contact:MovieClip;
var store:MovieClip;
var products:MovieClip;
var aboutLoader:Loader = new Loader();
aboutLoader.addEventListener(Event.COMPLETE, function(e:Event):void{
e.target.removeEventListener(e.type, arguments.callee);
about = MovieClip(e.target.content);
addChild(about);
about.visible = false;
about.stop();
});
aboutLoader.load('about.swf');
// repeat for every section
And update your buttons to show/hide the appropriate content:
PHP Code:
function aboutLoad(e:MouseEvent):void{
contact.visible = store.visible = products.visible = false;
contact.stop();
store.stop();
products.stop();
about.visible = true;
about.gotoAndPlay(1);
}
Please use [php] or [code] tags, and mark your threads resolved 8)
-
oh wow thanx so much I'll try it now and let you know how I get on with it. I just had a queastion in a mean time.
I am using UI Loader atm which is handy because I know it is 1024x768 in size andI need to position all my movie in the center of the screen, which I know how to do... as long as I know what is is I should target to position.
I guess what I am asing is can I load them into a movie 1024x768 with this or how should I do it....all my movies are 1024x768 btw
-
Since all your movies are the same size, they all need to sit at (0,0) to line up so it doesn't really matter how you load them in. Also - if you're on deadline, you might want to backup the copy that's working before you jump into a new technique - just in case
Please use [php] or [code] tags, and mark your threads resolved 8)
-
yeh thanx I made a copy would hate to loose it now.
The way I am positioning the Ui Loder atm is like this:
Code:
function onResizeStage(evt:Event):void {
//trace("Stage Height = " + stage.stageHeight,"Stage Width =" + stage.stageWidth);
setElementsXY();
}
function setElementsXY():void {
//------------------------------------------------------------
/*Initialize the start x and y values of your fluid elements*/
//------------------------------------------------------------
/*Align Center*/
ldr.x = ((stage.stageWidth / 2) - 512);
ldr.y = ((stage.stageHeight / 2) - 384);
So thats why I am wondering how I can still you this type of placement.
also while I am here. I'm still adding the new code but if you look abck up at the script I put up I am telling the product button to play frame 2 of product MC and once that has played at the end there is a ldr.Unload(); and ldr.source = "products.swf" how can I change the ldr.source to the new way?
-
Ahh - I see...you should be able to apply the same positioning to the movieclips to center them after theyre loaded in.
I think I'm missing something...it seems like there are two things called "product"? I'm not sure specifically what goes where but to do a delayed redirect like you're talking about, you'd want to use a custom event...so at the end of your productMC dispatch an event like so:
PHP Code:
dispatchEvent(new Event('goToProducts'));
And you'll want to listen for that event in your code:
PHP Code:
productMCLoader.addEventListener(Event.COMPLETE, function(e:Event):void{
e.target.removeEventListener(e.type, arguments.callee);
productMC = MovieClip(e.target.content);
addChild(productMC);
productMC.visible = false;
productMC.stop();
productMC.addEventListener('goToProducts', onGoToProducts);
});
And finally, handle the event:
PHP Code:
function goToProducts(e:Event):void{
// kill the other contents
products.visible = true;
products.gotoAndPlay(1);
}
...that's going to require tweaking...I'm pretty sure I'm goofed up on the specifics but the base concept is in there.
Please use [php] or [code] tags, and mark your threads resolved 8)
-
ok sorry I was a bit unclear. I have a movie clip called product (productsMC for easy) and the I have a movie products.swf which I wish to load at the end of the productsMC.
also I tested the script and It threw back sum errors:
1067: Implicit coercion of a value of type String to an unrelated type flash.net:URLRequest. productLoader.load('products.swf');
(did it for all of them)
here's how I set it up cos I may have done it wrong.
Code:
var about:MovieClip;
var contact:MovieClip;
var store:MovieClip;
var products:MovieClip;
var aboutLoader:Loader = new Loader();
aboutLoader.addEventListener(Event.COMPLETE, function(e:Event):void{
e.target.removeEventListener(e.type, arguments.callee);
about = MovieClip(e.target.content);
addChild(about);
about.visible = false;
about.stop();
});
aboutLoader.load('about.swf');
var contactLoader:Loader = new Loader();
contactLoader.addEventListener(Event.COMPLETE, function(e:Event):void{
e.target.removeEventListener(e.type, arguments.callee);
contact = MovieClip(e.target.content);
addChild(contact);
contact.visible = false;
contact.stop();
});
contactLoader.load('contact.swf');
var storeLoader:Loader = new Loader();
storeLoader.addEventListener(Event.COMPLETE, function(e:Event):void{
e.target.removeEventListener(e.type, arguments.callee);
store = MovieClip(e.target.content);
addChild(store);
store.visible = false;
store.stop();
});
storeLoader.load('store.swf');
var productLoader:Loader = new Loader();
productLoader.addEventListener(Event.COMPLETE, function(e:Event):void{
e.target.removeEventListener(e.type, arguments.callee);
product = MovieClip(e.target.content);
addChild(product);
product.visible = false;
product.stop();
});
productLoader.load('products.swf');
// repeat for every section
aboutBtn.addEventListener(MouseEvent.CLICK, aboutLoad);
function aboutLoad(e:MouseEvent):void{
contact.visible = store.visible = products.visible = false;
contact.stop();
store.stop();
products.stop();
about.visible = true;
about.gotoAndPlay(1);
}
contactBtn.addEventListener(MouseEvent.CLICK, contactLoad);
function contactLoad(e:MouseEvent):void{
about.visible = store.visible = products.visible = false;
about.stop();
store.stop();
products.stop();
contact.visible = true;
contact.gotoAndPlay(1);
}
storeBtn.addEventListener(MouseEvent.CLICK, storeLoad);
function storeLoad(e:MouseEvent):void{
contact.visible = about.visible = products.visible = false;
contact.stop();
about.stop();
products.stop();
store.visible = true;
store.gotoAndPlay(1);
}
productsBtn.addEventListener(MouseEvent.CLICK, productsLoad);
function productsLoad(e:MouseEvent):void {
contact.visible = about.visible = store.visible = false;
contact.stop();
about.stop();
store.stop();
this.product.gotoAndPlay(2);
}
-
whoops - that should be :
PHP Code:
contactLoader.load(new URLRequest('contact.swf'));
Please use [php] or [code] tags, and mark your threads resolved 8)
-
ok I think I get it...you can load in products.swf the same way as the other content and when you click the button, play productsMC and use the event technique - then in goToProducts() put in code similar to the other buttons:
PHP Code:
var productSWFLoader:Loader = new Loader();
productSWFLoader.addEventListener(Event.COMPLETE, function(e:Event):void{
e.target.removeEventListener(e.type, arguments.callee);
productSWF = MovieClip(e.target.content);
addChild(productSWF);
productSWF.visible = false;
productSWF.stop();
});
productSWF.load(new URLRequest('products.swf'));
function goToProducts(e:Event):void{
contact.visible = about.visible = store.visible = false;
contact.stop();
about.stop();
store.stop();
this.productsSWF.gotoAndPlay(2);
}
Please use [php] or [code] tags, and mark your threads resolved 8)
-
I think I am doing something wrong. The error is gone (Thanx) but now nothing happens when I click on the links.
Code:
var about:MovieClip;
var contact:MovieClip;
var store:MovieClip;
var products:MovieClip;
var aboutLoader:Loader = new Loader();
aboutLoader.addEventListener(Event.COMPLETE, function(e:Event):void{
e.target.removeEventListener(e.type, arguments.callee);
about = MovieClip(e.target.content);
addChild(about);
about.visible = false;
about.stop();
});
aboutLoader.load(new URLRequest('about.swf'));
var contactLoader:Loader = new Loader();
contactLoader.addEventListener(Event.COMPLETE, function(e:Event):void{
e.target.removeEventListener(e.type, arguments.callee);
contact = MovieClip(e.target.content);
addChild(contact);
contact.visible = false;
contact.stop();
});
contactLoader.load(new URLRequest('contact.swf'));
var storeLoader:Loader = new Loader();
storeLoader.addEventListener(Event.COMPLETE, function(e:Event):void{
e.target.removeEventListener(e.type, arguments.callee);
store = MovieClip(e.target.content);
addChild(store);
store.visible = false;
store.stop();
});
storeLoader.load(new URLRequest('store.swf'));
var productLoader:Loader = new Loader();
productLoader.addEventListener(Event.COMPLETE, function(e:Event):void{
e.target.removeEventListener(e.type, arguments.callee);
product = MovieClip(e.target.content);
addChild(product);
product.visible = false;
product.stop();
});
productLoader.load(new URLRequest('products.swf'));
// repeat for every section
function aboutLoad(e:MouseEvent):void{
contact.visible = store.visible = products.visible = false;
contact.stop();
store.stop();
products.stop();
about.visible = true;
about.gotoAndPlay(1);
}
function contactLoad(e:MouseEvent):void{
about.visible = store.visible = products.visible = false;
about.stop();
store.stop();
products.stop();
contact.visible = true;
contact.gotoAndPlay(1);
}
function storeLoad(e:MouseEvent):void{
contact.visible = about.visible = products.visible = false;
contact.stop();
about.stop();
products.stop();
store.visible = true;
store.gotoAndPlay(1);
}
function productLoad(e:MouseEvent):void{
contact.visible = store.visible = about.visible = false;
contact.stop();
store.stop();
about.stop();
product.visible = true;
product.gotoAndPlay(1);
}
-
haha I think I know what I am doing wrong. lol I just got functions but haven't added them to the buttons. OPPs
-
well I put them in the buttons but now I just get this error:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at main2_fla::MainTimeline/contactLoad()
and nothing loads.
-
Ugh - youre trying to change those movieclips before theyre loaded and its breaking...put in some logic checks to catch the errors:
PHP Code:
if(about){
about.visible = false;
about.stop();
}
if(store){
store.visible = false;
store.stop();
}
if(products){
products.visible = false;
products.stop();
}
if(contact){
contact.visible = true;
contact.gotoAndPlay(1);
}
and add a listener to see if your loaders are hitting any snags:
PHP Code:
aboutLoader.addEventListener('ioError', function(e:Event):void{
trace('load error: ' + e);
});
Please use [php] or [code] tags, and mark your threads resolved 8)
-
Nothing is happening now when I click no errors(yay) but no movies either.
have I structured it wrong?
Code:
var about:MovieClip;
var contact:MovieClip;
var store:MovieClip;
var products:MovieClip;
var aboutLoader:Loader = new Loader();
aboutLoader.addEventListener(Event.COMPLETE, function(e:Event):void{
e.target.removeEventListener(e.type, arguments.callee);
about = MovieClip(e.target.content);
addChild(about);
about.visible = false;
about.stop();
});
aboutLoader.load(new URLRequest('about.swf'));
var contactLoader:Loader = new Loader();
contactLoader.addEventListener(Event.COMPLETE, function(e:Event):void{
e.target.removeEventListener(e.type, arguments.callee);
contact = MovieClip(e.target.content);
addChild(contact);
contact.visible = false;
contact.stop();
});
contactLoader.load(new URLRequest('contact.swf'));
var storeLoader:Loader = new Loader();
storeLoader.addEventListener(Event.COMPLETE, function(e:Event):void{
e.target.removeEventListener(e.type, arguments.callee);
store = MovieClip(e.target.content);
addChild(store);
store.visible = false;
store.stop();
});
storeLoader.load(new URLRequest('store.swf'));
var productLoader:Loader = new Loader();
productLoader.addEventListener(Event.COMPLETE, function(e:Event):void{
e.target.removeEventListener(e.type, arguments.callee);
product = MovieClip(e.target.content);
addChild(product);
product.visible = false;
product.stop();
});
productLoader.load(new URLRequest('products.swf'));
// repeat for every section
aboutBtn.addEventListener(MouseEvent.CLICK, aboutLoad);
function aboutLoad(e:MouseEvent):void{
if(contact){
contact.visible = false;
contact.stop();
}
if(store){
store.visible = false;
store.stop();
}
if(products){
products.visible = false;
products.stop();
}
if(about){
about.visible = true;
about.gotoAndPlay(1);
}
}
contactBtn.addEventListener(MouseEvent.CLICK, contactLoad);
function contactLoad(e:MouseEvent):void{
if(about){
about.visible = false;
about.stop();
}
if(store){
store.visible = false;
store.stop();
}
if(products){
products.visible = false;
products.stop();
}
if(contact){
contact.visible = true;
contact.gotoAndPlay(1);
}
}
storeBtn.addEventListener(MouseEvent.CLICK, storeLoad);
function storeLoad(e:MouseEvent):void{
if(about){
about.visible = false;
about.stop();
}
if(contact){
contact.visible = false;
contact.stop();
}
if(products){
products.visible = false;
products.stop();
}
if(store){
store.visible = true;
store.gotoAndPlay(1);
}
}
productsBtn.addEventListener(MouseEvent.CLICK, productLoad);
function productLoad(e:MouseEvent):void{
if(about){
about.visible = false;
about.stop();
}
if(store){
store.visible = false;
store.stop();
}
if(contact){
contact.visible = false;
contact.stop();
}
if(products){
products.visible = true;
products.gotoAndPlay(1);
}
}
aboutLoader.addEventListener('ioError', function(e:Event):void{
trace('load error: ' + e);
});
-
I suspect it's working but you're turning all of the sections invisible - comment out the
PHP Code:
product.visible = false;
product.stop();
part of whichever you want as the first section.
Please use [php] or [code] tags, and mark your threads resolved 8)
-
could you please explain a bit more I dont really understand. I tried commenting it out but it didn't work.
-
When you load in each section, you're setting it to invisible - otherwise all the content would stack up and look like crap. However, you still want one of those to be turned on at the beginning so you should disable the .visible=false for one section.
Otherwise does the whole thing work when you click around on the buttons?
Please use [php] or [code] tags, and mark your threads resolved 8)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|