Re: [Flashcoders] Weak eventListener Problem

2009-11-08 Thread Keith H
I make destroy methods, avoid using extra references to listeners and am 
compulsive about cleaning them up, still some continue to execute 
imperviously.

I hate when this happens cause its unpredictable and unexplainable.

All I know is the Real garbage collectors are sometimes late picking 
up my garbage after I put it outside for them.


-- Keith H --
www.keith-hair.net




Steven Sacks wrote:
No, it's not true.  You're misunderstanding how weak listeners work, 
how anonymous functions work (you shouldn't use those anyway), and 
you're also misunderstanding how the garbage collector works.


Whenever you addEventListener, immediately write a function that 
removes the event listener (such as a destroy method).  If you get 
into this habit, you will never forget to do it and you'll never have 
this issue ever again.

___
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] localconnection in as2

2009-09-19 Thread Keith H
-If you don't want to worry about a send/receive limit on a String sent, 
take a look at this post here.
-If you just want to measure the size being sent,  you can look at the 
part where the poster is dividing the length of the String sent by the 
limit.


http://www.ultrashock.com/forums/actionscript/40k-byte-size-limit-on-localconnection-56395.html

...hope that leads you in the way you want to go.


-- Keith H --
www.keith-hair.net





Hans Wichman wrote:

Hi list,

as I understand it, there is a send/receive limit of 40k to the
localconnection object in actionscript2.
Mostly the objects passed in my application will probably be under 40k, but
the question is: how can you tell?

Is there some way to grab the actual AMF object flash is going to try and
pass and cut it up into pieces if necessary?
Or should you serialize and cut up everything beforehand just to be sure?

regards,
Hans
___
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] Weird htmlText line break behavior

2009-08-21 Thread Keith H

Maybe the lettercase of a property is causing an error.

myTF.wordwrap = true;  //Need to be wordWrap




-- Keith H --
www.keith-hair.net

Joel Stransky wrote:

I'm encountering an odd problem in as3/fp9-10 when dealing with embedded
fonts, condensed whitespace, style sheet objects and  br / tags. I wanted
to see if you guys have heard of it or can verify it as a bug.

I have a textfield set up as such. The intent is to remove all p tag
indents and get fully left justified text with paragraphs having larger
leading than individual lines :

var myTF:TextField = new TextField();
myTF.autoSize = TextFieldAutoSize.LEFT;
myTF.embedFonts = true;
myTF.condenseWhite = true;
myTF.antiAliasType = AntiAliasType.ADVANCED;
myTF.multiline = true;
myTF.wordwrap = true;
myTF.styleSheet = myStyleSheet;

The stylesheet is an imported .css file and below is the html imported from
an .xml file and protected by a CDATA tag:

h2About Us/h2br /
p class=normalstrongLorem/strong ipsum dolor sit amet,
consectetur/pbr /
p class=normalLorem ipsum dolor sit amet, consectetur./pbr /
p class=normalLorem ipsum dolor sit amet, consectetur./pbr /
p class=normalLorem ipsum dolor sit amet, consectetur./p

The result is fully left justified text but the br / tags are ignored.
Each paragraph does start on a new line but directly below the the previous.

I decided to try a version of the css clear break trick used in xhtml which
produced the results I wanted but for no discernible reason.

I created this style in the .css file,

.lineBreak {
  leading: 20;
}

and altered ONLY the first br / tag to this p class=lineBreak /
The weird thing is that not only did the first paragraph get the correct
amount of space, they all did. For some reason, an empty styled p / tag
caused the following br / tags to be recognized.

Thoughts?

  



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


Re: [Flashcoders] How to add a DisplayObject into a container without using addChild() method.

2009-08-18 Thread Keith H
Back when I was using AS2 and Javascript || operator was useful to me. 
I was so glad when AS3 brought default parameters.

var value:String = foo || bar;

-- Keith H --
www.keith-hair.net




Steven Sacks wrote:

Dave, come on. Take a stand on the issue. Stop straddling the fence.

Pick a side. Im or Ex?

I'm not about writing cryptic PERL-like statements, but writing != 
null is a waste of time.  It's obviously a null comparison (by nature 
of it being an instance).  Calling it out as such is redundant.


It also lends itself to very readable code with inline ORs.

var value:String = foo || bar;

If foo is null, value = bar.  Great for default values such as with XML.

var value:String = x...@foo || ;

Very readable and so much better than

var value:String = ;
if (x...@foo != undefined) value = x...@foo;
___
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] maintainable code

2009-08-18 Thread Keith H

WTF comes from trying to plan for worse case scenarios.
I did not write this. My doppleganger did  :)

var WorstCaseSenario:*= 0x00 ;
trace(toBoolean(WorstCaseSenario) == false);

function toBoolean(bool:*):Boolean
{
   if (bool ==  || !bool) {
   return false;
   }
   if (bool is Boolean == false) {
   bool=String(bool);
   }
   if (bool is String) {
   bool=String(bool).toLowerCase().replace(/^\s+|\s+$/mig,);
   if (/\d+|\dx\d+/.test(bool)) {
   if (Number(bool) == 1) {
   return true;
   }
   if (Number(bool) == 0) {
   return false;
   }
   }
   if (bool == true) {
   return true;
   }
   if (bool == false) {
   return false;
   }
   return false;
   }
   return bool;
}


-- Keith H --
www.keith-hair.net


Juan Pablo Califano wrote:

This remainds me of a utility method written by a former coworker at my
previous job, that rightfully belongs in the daily WTF.

public static function mtd_validarVar (variable : Object) :Boolean
{
 if (
  variable == false  ||
  variable == undefined   ||
  variable == ||
  variable == null
  )
 {
  return false
 }else
 {
  return true
 }
}
Had he checked against 0, at least this method could have been used as a
generic replacement for the obscure and unreadable implicit boolean
coercion...

He also had the chutzpah to put this method in our core library, in a class
conveniently named VarUtils, so the whole team could benefit from it.

To add insult to injury, he had a very personal take on hungarian notation
and code formatting as well. Not to mention he was also in the tabs should
be 8 spaces here, there and everywhere, and if you and the rest of the world
use 4 spaces, rest asured I will reformat any such piece of crap as soon as
I get a chance to put my hands on it camp.
Nevertheless, he was a cool guy.

Cheers
Juan Pablo Califano

2009/8/18 Latcho spamtha...@gmail.com

  

some great optimalistations can be found here:
http://mindprod.com/jgloss/unmain.html

for ex.

class Truth
 {
 boolean isTrue ( boolean assertion )
{
if ( assertion != false )
   {
   return assertion;
   }
else
   {
   return assertion;
   }
}
 }
...

var doIt:Boolean;

var trutherizer:Truth = new Truth();
if ( trutherizer.isTrue( s.equals( t ) ) )
 {
 doIt = true;
 }
else
 {
 doIt = false;
 }



// hint: all the above accomplishes is:
doIt = (s==t);

___
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] How to add a DisplayObject into a container without using addChild() method.

2009-08-17 Thread Keith H


Steven,

Maybe its just me but...
Just doing a Boolean check on DisplayObjects always put my scripts in 
high risk of runtime errors.

Especially in the case of cleanup operations.
Sometimes I might have a function that attempts removing a DisplayObject 
that has not been added to the stage or has already been removed.


So I check if the stage property is null for almost all cases now.

var myDO:Sprite=new Sprite();
try {
   //if (myDO) { //Creates runtime error
   if (myDO  myDO.stage != null) {
   myDO.parent.removeChild(myDO);
   }   
} catch (e:Error) {

   trace(e.message);
}

-- Keith H --
www.keith-hair.net






Steven Sacks wrote:
I don't understand why you would not want to write a single line of 
code in the class where it would provide the most clarity, and instead 
write MORE code in another class obscuring the behavior that is going 
on.  In other words, you're writing more code to write the same code.  
You're going to write addChild either way, why make it more 
complicated than it needs to be?


Always follow the KISS principle.


BTW, Ekameleon, you should use

if (target)

Instead of

if (target != null)




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


Re: [Flashcoders] How to add a DisplayObject into a container without using addChild() method.

2009-08-17 Thread Keith H

Thanks.
That is a better way to write the check. (Clever! you escaped from using 
null once again LOL)

BTW I just put the try/catch there to demonstrate error.

-- Keith H --
www.keith-hair.net



Steven Sacks wrote:

Here's the best way to write that. No try catch required.

if (myDO  myDO.parent) myDO.parent.removeChild(myDO);


Keith H wrote:


Steven,

Maybe its just me but...
Just doing a Boolean check on DisplayObjects always put my scripts in 
high risk of runtime errors.

Especially in the case of cleanup operations.
Sometimes I might have a function that attempts removing a 
DisplayObject that has not been added to the stage or has already 
been removed.


So I check if the stage property is null for almost all cases now.

var myDO:Sprite=new Sprite();
try {
   //if (myDO) { //Creates runtime error
   if (myDO  myDO.stage != null) {
   myDO.parent.removeChild(myDO);
   }   } catch (e:Error) {
   trace(e.message);
}

-- Keith H --
www.keith-hair.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] array.indexOf problem

2009-06-16 Thread Keith H

trace (buttonsArray.indexOf(e.target.name));


Looking at the aboveyour buttonsArray  is  an  Array containing 
Objects.

And you are using the indexOf method looking for a String.

Take off the .name property and you should see a difference.


-- Keith H --
www.keith-hair.net





Isaac Alves wrote:

Hi fellows,
Cannot solve this problem:

function buttonClicked(e:Event):void {
 trace (buttonsArray.indexOf(e.target.name));

It always  traces -1. This code should trace the index of the Array
element right? for ex: 0, 1, 2 or 3.

If i do this, it will trace the correct name of the element.

function buttonClicked(e:Event):void {
 trace (e.target.name);

If I do this, it will trace the name of the second element:

function buttonClicked(e:Event):void {
 trace (buttonsArray[1].name);

Why indexOf doesn´t work properly?

Thanks a lot!
___
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