Re: [Flashcoders] Event.COMPLETE Question

2010-02-23 Thread Steven Sacks
If you call close() on a Loader and it fails for any reason, it will throw a 
runtime error that you can do nothing about. To avoid this, you should wrap it 
in a try catch.


The code block comes straight from Flex and it works. If you test it a bunch and 
close() never fires an error, then you can remove it.  It's really not that much 
overhead to keep it in unless you're doing hundreds of iterations per second.

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


RE: [Flashcoders] Event.COMPLETE Question

2010-02-23 Thread Keith Reinfeld
> 
> var bitmap:Bitmap = new
> Bitmap(Bitmap(loader.content).bitmapData.clone(),"auto", true);
> Bitmap(loader.content).bitmapData.dispose();
> loader.unloadAndStop(true);
> try {
>  loader.close();
> } catch (e:Error) {}
> // remove all event listeners from loader
>

Steven, 
I'm curious about the try-catch block. It seems unnecessary since,
presumably, this code would be called within an onLoadComplete function and
the URLStream would no longer be open. Is there a scenario where this would
not be the case? 

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] Event.COMPLETE Question

2010-02-23 Thread Keith Reinfeld
Steven, 

Thanks for the backup.

Regards,

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


> -Original Message-
> From: flashcoders-boun...@chattyfig.figleaf.com [mailto:flashcoders-
> boun...@chattyfig.figleaf.com] On Behalf Of Steven Sacks
> Sent: Tuesday, February 23, 2010 2:52 PM
> To: Flash Coders List
> Subject: Re: [Flashcoders] Event.COMPLETE Question
> 
> You should only create the bevel filter ONCE.  Filters are _expensive_
> and
> can/should be shared.  Make your bevel an instance variable
> 
> private var myBevel:BevelFilter = new BevelFilter();
> 
> public function foo()
> {
>  myClip.filters = [myBevel];
> }
> ___
> Flashcoders mailing list
> Flashcoders@chattyfig.figleaf.com
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
> No virus found in this incoming message.
> Checked by AVG - www.avg.com
> Version: 9.0.733 / Virus Database: 271.1.1/2705 - Release Date:
> 02/23/10 01:34:00

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


Re: [Flashcoders] Event.COMPLETE Question

2010-02-23 Thread Steven Sacks
You should only create the bevel filter ONCE.  Filters are _expensive_ and 
can/should be shared.  Make your bevel an instance variable


private var myBevel:BevelFilter = new BevelFilter();

public function foo()
{
myClip.filters = [myBevel];
}
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] Event.COMPLETE Question

2010-02-23 Thread Steven Sacks
When loading bitmaps, your loader will NEVER be eligible for cleanup by the 
Garbage Collector unless you do ALL of the following in this order:


var bitmap:Bitmap = new Bitmap(Bitmap(loader.content).bitmapData.clone(), 
"auto", true);

Bitmap(loader.content).bitmapData.dispose();
loader.unloadAndStop(true);
try {
loader.close();
} catch (e:Error) {}
// remove all event listeners from loader

This means that if you want the Bitmap from the loader, you should extract it 
using bitmapData.clone(), or your Bitmap will be gone when the loader goes away 
or the loader will not go away because there's still a reference to its BitmapData.


If you're pulling a Bitmap out of an anonymous loader by saying 
addChild(loader.content) you will never have another opportunity to get rid of 
the loader. That may be ok for your purposes, but this is a very good reason to 
addChild(loader) so you maintain a reference to the loader itself.


Unless you have a specific reason for not using addChild(loader) you should use 
the code block above.


It's important to note that you won't see your memory go down unless you force 
the GC to run after you null out all references to the loader. In AIR you can 
say System.gc().  In Flash, you have to use the unsupported LocalConnection hack.

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


Re: [Flashcoders] Event.COMPLETE Question

2010-02-23 Thread Susan Day
On Tue, Feb 23, 2010 at 1:27 PM, Keith Reinfeld
wrote:

> > How is that? I'm not iterating over that function, I call it as needed,
> > so
> > myX, myY would be reset every time.
>
> Uses the addition assignment (+=) operator.
>

My bad. It is not iteration. It is called onMouseOver, hence the value of
myX, myY cannot be predetermined nor iterated.

>
> > No:
> > displayObject.filters = [createBevel()];
>
> You are missing the point. Why run this function repeatedly when you can
> set
> 'myBevel' once and just use that?
> displayObject.filters = [myBevel];
>

function createBevel():BevelFilter
{
var bf:BevelFilter = new BevelFilter();
bf.type = BitmapFilterType.OUTER;
bf.distance = 10;
bf.highlightColor = 0xFF;
bf.shadowColor = 0x00;
bf.blurX = 20;
bf.blurY = 20;
return bf;
}

myBevel no longer exists!
TIA,
Susan
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


RE: [Flashcoders] Event.COMPLETE Question

2010-02-23 Thread Keith Reinfeld
> How is that? I'm not iterating over that function, I call it as needed,
> so
> myX, myY would be reset every time.

Uses the addition assignment (+=) operator. 

> No:
> displayObject.filters = [createBevel()]; 

You are missing the point. Why run this function repeatedly when you can set
'myBevel' once and just use that? 
displayObject.filters = [myBevel];

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] Event.COMPLETE Question

2010-02-23 Thread Susan Day
On Tue, Feb 23, 2010 at 11:04 AM, Keith Reinfeld
wrote:

> > I presume my removeEventListener works.
> You should be sure. So check it:
>
> trace(e.currentTarget.hasEventListener(Event.COMPLETE)); //true
> e.currentTarget.removeEventListener(Event.COMPLETE, loaded);
> trace(e.currentTarget.hasEventListener(Event.COMPLETE)); //false
>

Thanks. Traced true.

>
> > So, how do I pass new values to fn loaded?
> Just increment the vars.
> // Cascade layout
> displayObject.x = myX + 31;
> displayObject.y = myY + 31;
> myX += 20;
> myY += 20;
>

How is that? I'm not iterating over that function, I call it as needed, so
myX, myY would be reset every time.

>
> Have you considered putting your url strings into an array instead of using
> that awkward switch statement?
>

This worked. Thanks:

public function thePic(x:int,
   y:int)
{
var paths:Array = new Array("images/bracelet.jpg",
"images/brooch.jpg",
"images/chain.jpg",
"images/earring.jpg",
"images/necklace.jpg",
"images/ring.jpg");
var path:String = new String();
path = paths[counter];
var req:URLRequest = new URLRequest(path);
var loaderArray:Array = new Array();
loaderArray[counter] = new Loader();
loaderArray[counter].load(req);
loaderArray[counter].contentLoaderInfo.addEventListener(Event.COMPLETE,loaded);
}

I would also recommend writing a function that creates and returns
> BevelFilter. Set 'myBevel' once (rather than running through the code
> repeatedly) then apply it where appropriate.
> var myBevel:BevelFilter = createBevel();
> function createBevel():BevelFilter{
>var bf:BevelFilter = new BevelFilter();
>bf.type = BitmapFilterType.OUTER;
>bf.distance = 10;
>bf.highlightColor = 0xFF;
>bf.shadowColor = 0x00;
>bf.blurX = 20;
>bf.blurY = 20;
>return bf;
> }
>
> Thanks.


> // apply Bevel filter
> displayObject.filters = [myBevel];
>

No:
displayObject.filters = [createBevel()];

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


RE: [Flashcoders] Event.COMPLETE Question

2010-02-23 Thread Keith Reinfeld
> I presume my removeEventListener works. 
You should be sure. So check it: 
 
trace(e.currentTarget.hasEventListener(Event.COMPLETE)); //true
e.currentTarget.removeEventListener(Event.COMPLETE, loaded); 
trace(e.currentTarget.hasEventListener(Event.COMPLETE)); //false

> So, how do I pass new values to fn loaded?
Just increment the vars. 
// Cascade layout 
displayObject.x = myX + 31; 
displayObject.y = myY + 31; 
myX += 20; 
myY += 20; 
 
Have you considered putting your url strings into an array instead of using
that awkward switch statement? 

I would also recommend writing a function that creates and returns
BevelFilter. Set 'myBevel' once (rather than running through the code
repeatedly) then apply it where appropriate. 
var myBevel:BevelFilter = createBevel(); 
function createBevel():BevelFilter{ 
var bf:BevelFilter = new BevelFilter(); 
bf.type = BitmapFilterType.OUTER; 
bf.distance = 10; 
bf.highlightColor = 0xFF; 
bf.shadowColor = 0x00; 
bf.blurX = 20; 
bf.blurY = 20; 
return bf; 
} 
 
// apply Bevel filter 
displayObject.filters = [myBevel]; 
 
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] Event.COMPLETE Question

2010-02-23 Thread Susan Day
On Mon, Feb 22, 2010 at 2:27 PM, Keith Reinfeld
wrote:

> > Thanks for the clarification, but that ain't doing it either.
>
> // LoaderInfo
> e.currentTarget
>
> // Bitmap
> e.currentTarget.loader.content
>

Perhaps, but if I trace(displayObject) it traces as the bitmap, so I can use
that. Such being the case, I apply the bevel filter to the bitmap, which is
correct. Then I add the child to the default (stage) and it appears.
Everything good here. I presume my removeEventListener works.

But,,,that's not the problem!

> Your images are likely to display one top of the other, making it seem
like
you are only getting one.

THAT'S the problem. "myX" and "myY" are all the same value every iteration
(traced 'em). So, how do I pass new values to fn loaded?

public function thePic(x:int,
   y:int)
{
var path:String = new String();
switch (counter)
{
case 0:
path = "images/bracelet.jpg";
break;
case 1:
path = "images/brooch.jpg";
break;
case 2:
path = "images/chain.jpg";
break;
case 3:
path = "images/earring.jpg";
break;
case 4:
path = "images/necklace.jpg";
break;
case 5:
path = "images/ring.jpg";
break;
}
var req:URLRequest = new URLRequest(path);
var loaderArray:Array = new Array();
loaderArray[counter] = new Loader();
loaderArray[counter].load(req);
loaderArray[counter].contentLoaderInfo.addEventListener(Event.COMPLETE,loaded);
}

function loaded(e:Event):void
{
var loaderInfo:LoaderInfo = e.target as LoaderInfo;
var displayObject:DisplayObject = loaderInfo.loader.content;
displayObject.width = 257;
displayObject.height = 257;
displayObject.x = myX + 31;
displayObject.y = myY + 31;
var myBevel:BevelFilter = new BevelFilter();
myBevel.type = BitmapFilterType.FULL;
myBevel.distance = 10;
myBevel.highlightColor = 0xFF;
myBevel.shadowColor = 0x00;
myBevel.blurX = 20;
myBevel.blurY = 20;
displayObject.filters = [myBevel];
addChild(displayObject);
e.currentTarget.content.removeEventListener(Event.COMPLETE, loaded);
}

TIA,
Susan

>
>
>
> ___
> 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] Event.COMPLETE Question

2010-02-22 Thread Steven Sacks

> e.target isn't your loader info, its most likely the Loader itself.

loader.contentLoaderInfo.addEventListener()

The LoaderInfo is the target of the event - that's what you added the event 
listener to.


trace(event.target);
[LoaderInfo]

Proof that the LoaderInfo is the target is easily derived by tracing the 
event.target.




Why don't you just do this?

loader.filters = [myBevel];
addChild(loader);






On 2/22/2010 5:33 AM, Gregory Boland wrote:



the target is where the event bubbles from, and the currentTarget is what
was applied the listener

so what you are looking for is e.target.content and that is whatever you
loaded in

On Mon, Feb 22, 2010 at 4:57 AM, Susan Daywrote:


On Mon, Feb 22, 2010 at 8:31 AM, Steven Sacks
wrote:



Update this line:

var displayObject:DisplayObject = loaderInfo.loader.content;



Updated:

function loaded(e:Event):void
{
var loaderInfo:LoaderInfo = e.target as LoaderInfo;
var displayObject:DisplayObject = loaderInfo.loader.content;
displayObject.width = 257;
displayObject.height = 257;
displayObject.x = myX + 31;
displayObject.y = myY + 31;
var myBevel:BevelFilter = new BevelFilter();
myBevel.type = BitmapFilterType.FULL;
myBevel.distance = 10;
myBevel.highlightColor = 0xFF;
myBevel.shadowColor = 0x00;
myBevel.blurX = 20;
myBevel.blurY = 20;
displayObject.filters = [myBevel];
addChild(displayObject);
e.target.removeEventListener(Event.COMPLETE, loaded);
}

Did the same thing (no correction). Please advise.
TIA,
Susan
___
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


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


RE: [Flashcoders] Event.COMPLETE Question

2010-02-22 Thread Keith Reinfeld
> Thanks for the clarification, but that ain't doing it either. 
 
// LoaderInfo 
e.currentTarget 
 
// Bitmap 
e.currentTarget.loader.content 
 
// Remove listener 
e.currentTarget.removeEventListener(Event.COMPLETE, loaded); 
// Get current jpg 
var displayObject:DisplayObject = e.currentTarget.loader.content; 
 
Your images are unlikely to load in the same order indicated by the switch
statement. 
Your images are likely to display one top of the other, making it seem like
you are only getting one. 
 
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] Event.COMPLETE Question

2010-02-22 Thread Susan Day
On Mon, Feb 22, 2010 at 9:33 AM, Gregory Boland
wrote:

> e.target isn't your loader info, its most likely the Loader itself.
>
> the target is where the event bubbles from, and the currentTarget is what
> was applied the listener
>
> so what you are looking for is e.target.content and that is whatever you
> loaded in
>

e.target.content.removeEventListener(Event.COMPLETE, loaded);

Thanks for the clarification, but that ain't doing it either.
TIA,
Susan
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] Event.COMPLETE Question

2010-02-22 Thread Gregory Boland
e.target isn't your loader info, its most likely the Loader itself.

the target is where the event bubbles from, and the currentTarget is what
was applied the listener

so what you are looking for is e.target.content and that is whatever you
loaded in

On Mon, Feb 22, 2010 at 4:57 AM, Susan Day wrote:

> On Mon, Feb 22, 2010 at 8:31 AM, Steven Sacks  >wrote:
>
> > Update this line:
> >
> > var displayObject:DisplayObject = loaderInfo.loader.content;
>
>
> Updated:
>
> function loaded(e:Event):void
> {
> var loaderInfo:LoaderInfo = e.target as LoaderInfo;
> var displayObject:DisplayObject = loaderInfo.loader.content;
> displayObject.width = 257;
> displayObject.height = 257;
> displayObject.x = myX + 31;
> displayObject.y = myY + 31;
> var myBevel:BevelFilter = new BevelFilter();
> myBevel.type = BitmapFilterType.FULL;
> myBevel.distance = 10;
> myBevel.highlightColor = 0xFF;
> myBevel.shadowColor = 0x00;
> myBevel.blurX = 20;
> myBevel.blurY = 20;
> displayObject.filters = [myBevel];
> addChild(displayObject);
> e.target.removeEventListener(Event.COMPLETE, loaded);
> }
>
> Did the same thing (no correction). Please advise.
> TIA,
> Susan
> ___
> 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] Event.COMPLETE Question

2010-02-22 Thread Susan Day
On Mon, Feb 22, 2010 at 8:31 AM, Steven Sacks wrote:

> Update this line:
>
> var displayObject:DisplayObject = loaderInfo.loader.content;


Updated:

function loaded(e:Event):void
{
var loaderInfo:LoaderInfo = e.target as LoaderInfo;
var displayObject:DisplayObject = loaderInfo.loader.content;
displayObject.width = 257;
displayObject.height = 257;
displayObject.x = myX + 31;
displayObject.y = myY + 31;
var myBevel:BevelFilter = new BevelFilter();
myBevel.type = BitmapFilterType.FULL;
myBevel.distance = 10;
myBevel.highlightColor = 0xFF;
myBevel.shadowColor = 0x00;
myBevel.blurX = 20;
myBevel.blurY = 20;
displayObject.filters = [myBevel];
addChild(displayObject);
e.target.removeEventListener(Event.COMPLETE, loaded);
}

Did the same thing (no correction). Please advise.
TIA,
Susan
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] Event.COMPLETE Question

2010-02-22 Thread Steven Sacks

Update this line:

var displayObject:DisplayObject = loaderInfo.loader.content;
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] Event.COMPLETE Question

2010-02-22 Thread Susan Day
On Sat, Feb 20, 2010 at 2:58 PM, Keith Reinfeld
wrote:

> All but the last Loader is being over written.
> Put each Loader into an array.
>
> var req:URLRequest = new URLRequest(path);
> loaderArray[counter] = new Loader();
> loaderArray[counter].load(req);
>
> loaderArray[counter].contentLoaderInfo.addEventListener(Event.COMPLETE,loade
> d);
>
> This way each Loader object is preserved in a separate element of the
> array.
>
>
> Don't forget to remove your listeners.
>

I'm missing something. I added the variable loaderArray as an Array which I
believe took care of one problem; however, I apparently am not correctly
identifying the e.target in the loader function:

var req:URLRequest = new URLRequest(path);
var loaderArray:Array = new Array();
loaderArray[counter] = new Loader();
loaderArray[counter].load(req);
loaderArray[counter].contentLoaderInfo.addEventListener(Event.COMPLETE,loaded);
}

function loaded(e:Event):void
{
var loaderInfo:LoaderInfo = e.target as LoaderInfo;
var displayObject:DisplayObject = loaderInfo.content;
displayObject.width = 257;
displayObject.height = 257;
displayObject.x = myX + 31;
displayObject.y = myY + 31;
var myBevel:BevelFilter = new BevelFilter();
myBevel.type = BitmapFilterType.FULL;
myBevel.distance = 10;
myBevel.highlightColor = 0xFF;
myBevel.shadowColor = 0x00;
myBevel.blurX = 20;
myBevel.blurY = 20;
displayObject.filters = [myBevel];
addChild(displayObject);
e.target.removeEventListener(Event.COMPLETE, loaded);
}

Please help me see what I'm missing.
TIA,
Susan
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


RE: [Flashcoders] Event.COMPLETE Question

2010-02-20 Thread Keith Reinfeld
All but the last Loader is being over written. 
Put each Loader into an array. 
 
var req:URLRequest = new URLRequest(path); 
loaderArray[counter] = new Loader(); 
loaderArray[counter].load(req); 
loaderArray[counter].contentLoaderInfo.addEventListener(Event.COMPLETE,loade
d); 

This way each Loader object is preserved in a separate element of the array.


Don't forget to remove your listeners. 

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] Event.COMPLETE Question

2010-02-20 Thread Susan Day
Hi;
I have this code:

public function thePic(x:int,
   y:int)
{
var path:String = new String();
switch (counter)
{
case 0:
path = "images/bracelet.jpg";
break;
case 1:
path = "images/brooch.jpg";
break;
case 2:
path = "images/chain.jpg";
break;
case 3:
path = "images/earring.jpg";
break;
case 4:
path = "images/necklace.jpg";
break;
case 5:
path = "images/ring.jpg";
break;
}
var req:URLRequest = new URLRequest(path);
var loader:Loader = new Loader();
loader.load(req);
loader.contentLoaderInfo.addEventListener(Event.COMPLETE,loaded);
}

function loaded(e:Event):void
{
var loaderInfo:LoaderInfo = e.target as LoaderInfo;
var displayObject:DisplayObject = loaderInfo.content;
displayObject.width = 257;
displayObject.height = 257;
displayObject.x = myX + 31;
displayObject.y = myY + 31;
var myBevel:BevelFilter = new BevelFilter();
myBevel.type = BitmapFilterType.FULL;
myBevel.distance = 10;
myBevel.highlightColor = 0xFF;
myBevel.shadowColor = 0x00;
myBevel.blurX = 20;
myBevel.blurY = 20;
displayObject.filters = [myBevel];
addChild(displayObject);
}

If I trace "path" all paths print out in the iteration of "counter". The
problem is that "Event.COMPLETE.loaded" is apparently called only once after
the while loop terminates that increments counter (inside of which all of
the above code is contained). Please advise how to make function loaded fire
for each iteration.
TIA,
Susan
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders