<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>ADM Blog &#187; How To&#8217;s</title>
	<atom:link href="http://blog.another-d-mention.ro/category/how-tos/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.another-d-mention.ro</link>
	<description>No matter how you see things, reality changes when you reach understanding</description>
	<lastBuildDate>Tue, 29 Jun 2010 06:12:27 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Ho-To: Install Alchemy</title>
		<link>http://blog.another-d-mention.ro/programming/ho-to-install-alchemy/</link>
		<comments>http://blog.another-d-mention.ro/programming/ho-to-install-alchemy/#comments</comments>
		<pubDate>Wed, 24 Jun 2009 06:51:53 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Flex / ActionScript]]></category>
		<category><![CDATA[How To's]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[actionscript3]]></category>
		<category><![CDATA[alchemy]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[library]]></category>

		<guid isPermaLink="false">http://blog.another-d-mention.ro/?p=493</guid>
		<description><![CDATA[For those of you who tried but didn't succed, I found some straigthforward instructions for this. Setup Hell: Install cygwin to "c:\cygwin" - make sure to check boxes to install Perl, "Archive" (ZIP), and Devel/gcc:g++ (3.4.4.3 presumably) (is Perl necessary?) Copy the alchemy directory to: c:\cygwin\home\Lee Copy the flex sdk bin dir from c:\program files\etc [...]


Related posts:<ol><li><a href='http://blog.another-d-mention.ro/programming/flex-components-pack/' rel='bookmark' title='Permanent Link: Flex Components Pack'>Flex Components Pack</a></li>
<li><a href='http://blog.another-d-mention.ro/programming/create-professional-flex-components/' rel='bookmark' title='Permanent Link: Create professional Flex components'>Create professional Flex components</a></li>
<li><a href='http://blog.another-d-mention.ro/programming/how-to-clone-duplicate-an-object-in-actionscript-3/' rel='bookmark' title='Permanent Link: How to clone (duplicate) an object in ActionScript 3'>How to clone (duplicate) an object in ActionScript 3</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>For those of you who tried but didn't succed, I found some straigthforward instructions for this.</p>
<h4 class="vspace">Setup Hell:</h4>
<p>Install cygwin to "c:\cygwin" - make sure to check boxes to install Perl, "Archive" (ZIP), and Devel/gcc:g++ (3.4.4.3 presumably) (is Perl necessary?)<br />
Copy the alchemy directory to: c:\cygwin\home\Lee<br />
Copy the flex sdk bin dir from c:\program files\etc to "c:\flex" (to avoid paths with spaces in it!)<br />
Run the alchemy config script once:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">   run cygwin
   <span style="color: #7a0874; font-weight: bold;">cd</span> alchemy
   .<span style="color: #000000; font-weight: bold;">/</span>config</pre></div></div>

<p>Edit the textfile "C:\cygwin\home\Lee\alchemy\alchemy-setup" and uncomment and edit line 22 to: add "export ADL=c:\flex\adl.exe"</p>
<p>Edit .bashrc (in C:\cygwin\home\Lee)</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">   <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;LEE PROFILE&quot;</span>
   <span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">FLEX_HOME</span>=~<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">flex</span>
   <span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">ALCHEMY_HOME</span>=~<span style="color: #000000; font-weight: bold;">/</span>alchemy
&nbsp;
   <span style="color: #666666; font-style: italic;"># &quot;This should be added before your PATH is modified&quot; !!</span>
   <span style="color: #7a0874; font-weight: bold;">source</span> <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>Lee<span style="color: #000000; font-weight: bold;">/</span>alchemy<span style="color: #000000; font-weight: bold;">/</span>alchemy-setup 
&nbsp;
   <span style="color: #007800;">PATH</span>=<span style="color: #007800;">$ALCHEMY_HOME</span><span style="color: #000000; font-weight: bold;">/</span>achacks:<span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>Lee<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">flex</span>:<span style="color: #007800;">$PATH</span>
   <span style="color: #7a0874; font-weight: bold;">export</span> PATH
&nbsp;
   alc-on</pre></div></div>

<p>Do this (just once, I think):</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">   <span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #007800;">$ALCHEMY_HOME</span><span style="color: #000000; font-weight: bold;">/</span>bin
   <span style="color: #c20cb9; font-weight: bold;">ln</span> <span style="color: #660033;">-s</span> llvm-stub llvm-stub.exe</pre></div></div>

<h4 class="vspace">Compiling a SW:</h4>
<p>CD to the directory with the source<br />
Always do "alc-on" before compiling, cuz it doesn't work without it even though i added it to the startup (dunno)</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">    <span style="color: #c20cb9; font-weight: bold;">gcc</span> stringecho.c <span style="color: #660033;">-O3</span> <span style="color: #660033;">-Wall</span> <span style="color: #660033;">-swc</span> <span style="color: #660033;">-o</span> stringecho.swc 
    <span style="color: #660033;">--</span> should give you a swc.</pre></div></div>

<p>Import the swc into your flex builder 4 project and make sure compiler targets SDK v4</p>
<h4 class="vspace">Shortcuts</h4>
<p><strong>alc-home</strong> - takes you to the Alchemy install folder.<br />
<strong>alc-on</strong> - puts Alchemy gcc toolchain replacements at the front of your path.<br />
<strong>alc-off</strong> - restores original path.<br />
<strong>alc-util</strong> - shows you various Alchemy-related environment vars</p>
<p class="vspace">USEFUL TO KNOW</p>
<p><strong>which gcc</strong> - tells you which gcc it will use (should be the one in the achacks dir)<br />
<strong>ln</strong> - links shit<br />
<strong>rm</strong> - deletes links as well as files</p>
<p class="vspace">Ugh: Make sure to do "alc-on" and "alchemy-setup" even though you put it in the startup script <img src='http://blog.another-d-mention.ro/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' title="Ho To: Install Alchemy" />  (?)</p>
<p class="vspace">...</p>
<p>Objects:<br />
	<span class="wikiword">AS3</span>_Val<br />
	<span class="wikiword">AS3</span>_ArrayValue</p>
<p>Methods:<br />
	<span class="wikiword">AS3</span>_Release<br />
	<span class="wikiword">AS3</span>_LibInit</p>


<p>Related posts:<ol><li><a href='http://blog.another-d-mention.ro/programming/flex-components-pack/' rel='bookmark' title='Permanent Link: Flex Components Pack'>Flex Components Pack</a></li>
<li><a href='http://blog.another-d-mention.ro/programming/create-professional-flex-components/' rel='bookmark' title='Permanent Link: Create professional Flex components'>Create professional Flex components</a></li>
<li><a href='http://blog.another-d-mention.ro/programming/how-to-clone-duplicate-an-object-in-actionscript-3/' rel='bookmark' title='Permanent Link: How to clone (duplicate) an object in ActionScript 3'>How to clone (duplicate) an object in ActionScript 3</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.another-d-mention.ro/programming/ho-to-install-alchemy/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>How to clone (duplicate) an object in ActionScript 3</title>
		<link>http://blog.another-d-mention.ro/programming/how-to-clone-duplicate-an-object-in-actionscript-3/</link>
		<comments>http://blog.another-d-mention.ro/programming/how-to-clone-duplicate-an-object-in-actionscript-3/#comments</comments>
		<pubDate>Fri, 05 Jun 2009 20:33:44 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Flex / ActionScript]]></category>
		<category><![CDATA[How To's]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[clone]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[flex]]></category>

		<guid isPermaLink="false">http://blog.another-d-mention.ro/?p=440</guid>
		<description><![CDATA[For a project I needed to clone an object of unknown type. And by clone I mean to create a new instance of that same type and then fill out all its properties (including getters and setters) to mirror the original object. Thanks to a friend, I discovered the describeType function in AS3. But this alone [...]


Related posts:<ol><li><a href='http://blog.another-d-mention.ro/programming/flex-actionscript/serialize-javascript-object-to-json/' rel='bookmark' title='Permanent Link: Serialize JavaScript object to JSON'>Serialize JavaScript object to JSON</a></li>
<li><a href='http://blog.another-d-mention.ro/programming/neural-networks-in-actionscript-3/' rel='bookmark' title='Permanent Link: Neural networks in ActionScript 3'>Neural networks in ActionScript 3</a></li>
<li><a href='http://blog.another-d-mention.ro/programming/how-to-identify-at-runtime-if-swf-is-in-debug-or-release-mode-build/' rel='bookmark' title='Permanent Link: How to identify at runtime if the swf is in debug or release mode/build'>How to identify at runtime if the swf is in debug or release mode/build</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>For a project I needed to clone an object of unknown type. And by clone I mean to create a new instance of that same type and then fill out all its properties (including getters and setters) to mirror the original object.</p>
<p>Thanks to a friend, I discovered the <a href="http://livedocs.adobe.com/flex/2/langref/flash/utils/package.html#describeType%28%29">describeType </a>function in AS3. But this alone will only take care of the copying part. To create an object of the same type as another one we use <a href="http://livedocs.adobe.com/flex/2/langref/flash/utils/package.html#getDefinitionByName%28%29">getDefinitionByName</a>.</p>
<p>Although Flash reflection is pretty basic, with a little work it will do the trick.</p>
<p>Get the <a href="http://blog.another-d-mention.ro/stuff/cloneTest.zip">application files</a>.</p>
<p>Here's the code:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;</span> <span style="color: #000000; font-weight: bold;">?</span>xml <span style="color: #004993;">version</span>=<span style="color: #990000;">&quot;1.0&quot;</span> encoding=<span style="color: #990000;">&quot;utf-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;</span>mx <span style="color: #000000; font-weight: bold;">:</span>Application xmlns<span style="color: #000000; font-weight: bold;">:</span>mx=<span style="color: #990000;">&quot;http://www.adobe.com/2006/mxml&quot;</span> layout=<span style="color: #990000;">&quot;absolute&quot;</span> xmlns<span style="color: #000000; font-weight: bold;">:</span>local=<span style="color: #990000;">&quot;*&quot;</span> creationComplete=<span style="color: #990000;">&quot;init()&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;/</span>mx<span style="color: #000000; font-weight: bold;">&gt;&lt;</span>mx <span style="color: #000000; font-weight: bold;">:</span>Script<span style="color: #000000; font-weight: bold;">&gt;</span>
 <span style="color: #000000; font-weight: bold;">&lt;</span> <span style="color: #000000; font-weight: bold;">!</span><span style="color: #000000;">&#91;</span>CDATA<span style="color: #000000;">&#91;</span>
&nbsp;
     <span style="color: #0033ff; font-weight: bold;">import</span> mx.controls.Alert;
&nbsp;
     <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">source</span><span style="color: #000000; font-weight: bold;">:</span>DataObject = <span style="color: #0033ff; font-weight: bold;">new</span> DataObject<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
     <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> cloneObject<span style="color: #000000; font-weight: bold;">:</span>DataObject;
&nbsp;
&nbsp;
     <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #004993;">init</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
&nbsp;
         <span style="color: #004993;">source</span>.<span style="color: #004993;">name</span> = <span style="color: #990000;">'John Doe'</span>;
         <span style="color: #004993;">source</span>.howMany = <span style="color: #000000; font-weight:bold;">4.5</span>;
         <span style="color: #004993;">source</span>.when = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Date</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span>;
         <span style="color: #004993;">source</span>.complexProp = <span style="color: #0033ff; font-weight: bold;">new</span> DataObject<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
         <span style="color: #004993;">source</span>.complexProp.<span style="color: #004993;">name</span> = <span style="color: #990000;">'Name in sub-object'</span>;
&nbsp;
         cloneObject = UtilFunctions.<span style="color: #004993;">clone</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">source</span><span style="color: #000000;">&#41;</span> <span style="color: #0033ff; font-weight: bold;">as</span> DataObject;
&nbsp;
         Alert.<span style="color: #004993;">show</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;Clone:<span style="">\n</span>name = &quot;</span> <span style="color: #000000; font-weight: bold;">+</span> cloneObject.<span style="color: #004993;">name</span> <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #990000;">&quot;<span style="">\n</span>howMany = &quot;</span> <span style="color: #000000; font-weight: bold;">+</span> cloneObject.howMany <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #990000;">&quot;<span style="">\n</span>when = &quot;</span> <span style="color: #000000; font-weight: bold;">+</span> cloneObject.when <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #990000;">&quot;<span style="">\n</span>complexProp.name = &quot;</span> <span style="color: #000000; font-weight: bold;">+</span> cloneObject.complexProp.<span style="color: #004993;">name</span><span style="color: #000000;">&#41;</span>;
     <span style="color: #000000;">&#125;</span>
&nbsp;
     <span style="color: #3f5fbf;">/**
&nbsp;
      * describeType will produce this (for a DataObject instance):
      *
      * &lt;type name=&quot;DataObject&quot; base=&quot;Object&quot; isDynamic=&quot;false&quot; isFinal=&quot;false&quot; isStatic=&quot;false&quot;&gt;
&nbsp;
           &lt;extendsclass type=&quot;Object&quot;/&gt;
           &lt;accessor name=&quot;isHandicap&quot; access=&quot;writeonly&quot; type=&quot;Boolean&quot; declaredBy=&quot;DataObject&quot;/&gt;
&nbsp;
           &lt;variable name=&quot;howMany&quot; type=&quot;Number&quot;/&gt;
           &lt;accessor name=&quot;complexProp&quot; access=&quot;readwrite&quot; type=&quot;DataObject&quot; declaredBy=&quot;DataObject&quot;/&gt;
&nbsp;
           &lt;variable name=&quot;name&quot; type=&quot;String&quot;/&gt;
           &lt;variable name=&quot;when&quot; type=&quot;Date&quot;/&gt;
&nbsp;
&nbsp;
      *
      * */</span>
&nbsp;
 <span style="color: #000000;">&#93;</span><span style="color: #000000;">&#93;</span><span style="color: #000000; font-weight: bold;">&gt;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;/</span>mx<span style="color: #000000; font-weight: bold;">&gt;</span></pre></td></tr></table></div>

<p>And the UtilFunctions.as file:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span>
<span style="color: #000000;">&#123;</span>
 <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.utils</span>.<span style="color: #004993;">describeType</span>;
 <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.utils</span>.<span style="color: #004993;">getDefinitionByName</span>;
 <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.utils</span>.<span style="color: #004993;">getQualifiedClassName</span>;
&nbsp;
 <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> UtilFunctions
 <span style="color: #000000;">&#123;</span>
&nbsp;
&nbsp;
     <span style="color: #0033ff; font-weight: bold;">public</span> static <span style="color: #339966; font-weight: bold;">function</span> newSibling<span style="color: #000000;">&#40;</span>sourceObj<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Object</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:*</span> <span style="color: #000000;">&#123;</span>
         <span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span>sourceObj<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
&nbsp;
             <span style="color: #6699cc; font-weight: bold;">var</span> objSibling<span style="color: #000000; font-weight: bold;">:*</span>;
             <span style="color: #0033ff; font-weight: bold;">try</span> <span style="color: #000000;">&#123;</span>
                 <span style="color: #6699cc; font-weight: bold;">var</span> classOfSourceObj<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Class</span> = <span style="color: #004993;">getDefinitionByName</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">getQualifiedClassName</span><span style="color: #000000;">&#40;</span>sourceObj<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #0033ff; font-weight: bold;">as</span> <span style="color: #004993;">Class</span>;
                 objSibling = <span style="color: #0033ff; font-weight: bold;">new</span> classOfSourceObj<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
             <span style="color: #000000;">&#125;</span>
&nbsp;
             <span style="color: #0033ff; font-weight: bold;">catch</span><span style="color: #000000;">&#40;</span>e<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Object</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><span style="color: #000000;">&#125;</span>
&nbsp;
             <span style="color: #0033ff; font-weight: bold;">return</span> objSibling;
         <span style="color: #000000;">&#125;</span>
         <span style="color: #0033ff; font-weight: bold;">return</span> <span style="color: #0033ff; font-weight: bold;">null</span>;
     <span style="color: #000000;">&#125;</span>
&nbsp;
     <span style="color: #0033ff; font-weight: bold;">public</span> static <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #004993;">clone</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">source</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Object</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Object</span> <span style="color: #000000;">&#123;</span>
&nbsp;
         <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">clone</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Object</span>;
         <span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">source</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
             <span style="color: #004993;">clone</span> = newSibling<span style="color: #000000;">&#40;</span><span style="color: #004993;">source</span><span style="color: #000000;">&#41;</span>;
&nbsp;
             <span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">clone</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
                 copyData<span style="color: #000000;">&#40;</span><span style="color: #004993;">source</span>, <span style="color: #004993;">clone</span><span style="color: #000000;">&#41;</span>;
             <span style="color: #000000;">&#125;</span>
         <span style="color: #000000;">&#125;</span>
&nbsp;
         <span style="color: #0033ff; font-weight: bold;">return</span> <span style="color: #004993;">clone</span>;
     <span style="color: #000000;">&#125;</span>
&nbsp;
     <span style="color: #0033ff; font-weight: bold;">public</span> static <span style="color: #339966; font-weight: bold;">function</span> copyData<span style="color: #000000;">&#40;</span><span style="color: #004993;">source</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Object</span>, destination<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Object</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
&nbsp;
         <span style="color: #009900;">//copies data from commonly named properties and getter/setter pairs</span>
         <span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">source</span><span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #000000;">&#40;</span>destination<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
&nbsp;
             <span style="color: #0033ff; font-weight: bold;">try</span> <span style="color: #000000;">&#123;</span>
                 <span style="color: #6699cc; font-weight: bold;">var</span> sourceInfo<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">XML</span> = <span style="color: #004993;">describeType</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">source</span><span style="color: #000000;">&#41;</span>;
                 <span style="color: #6699cc; font-weight: bold;">var</span> prop<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">XML</span>;
&nbsp;
                 <span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #0033ff; font-weight: bold;">each</span><span style="color: #000000;">&#40;</span>prop <span style="color: #0033ff; font-weight: bold;">in</span> sourceInfo.variable<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
&nbsp;
                     <span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span>destination.<span style="color: #004993;">hasOwnProperty</span><span style="color: #000000;">&#40;</span>prop.@<span style="color: #004993;">name</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
                         destination<span style="color: #000000;">&#91;</span>prop.@<span style="color: #004993;">name</span><span style="color: #000000;">&#93;</span> = <span style="color: #004993;">source</span><span style="color: #000000;">&#91;</span>prop.@<span style="color: #004993;">name</span><span style="color: #000000;">&#93;</span>;
                     <span style="color: #000000;">&#125;</span>
&nbsp;
                 <span style="color: #000000;">&#125;</span>
&nbsp;
                 <span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #0033ff; font-weight: bold;">each</span><span style="color: #000000;">&#40;</span>prop <span style="color: #0033ff; font-weight: bold;">in</span> sourceInfo.accessor<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
                     <span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span>prop.@access == <span style="color: #990000;">&quot;readwrite&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
                         <span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span>destination.<span style="color: #004993;">hasOwnProperty</span><span style="color: #000000;">&#40;</span>prop.@<span style="color: #004993;">name</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
                             destination<span style="color: #000000;">&#91;</span>prop.@<span style="color: #004993;">name</span><span style="color: #000000;">&#93;</span> = <span style="color: #004993;">source</span><span style="color: #000000;">&#91;</span>prop.@<span style="color: #004993;">name</span><span style="color: #000000;">&#93;</span>;
                         <span style="color: #000000;">&#125;</span>
&nbsp;
                     <span style="color: #000000;">&#125;</span>
                 <span style="color: #000000;">&#125;</span>
             <span style="color: #000000;">&#125;</span>
             <span style="color: #0033ff; font-weight: bold;">catch</span> <span style="color: #000000;">&#40;</span>err<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Object</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
                 ;
             <span style="color: #000000;">&#125;</span>
         <span style="color: #000000;">&#125;</span>
     <span style="color: #000000;">&#125;</span>
 <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>by <a href="http://evolverine.blogspot.com/2008/05/how-to-clone-duplicate-object-in.html">Evolvernie</a><br />
<!-- adman --></p>


<p>Related posts:<ol><li><a href='http://blog.another-d-mention.ro/programming/flex-actionscript/serialize-javascript-object-to-json/' rel='bookmark' title='Permanent Link: Serialize JavaScript object to JSON'>Serialize JavaScript object to JSON</a></li>
<li><a href='http://blog.another-d-mention.ro/programming/neural-networks-in-actionscript-3/' rel='bookmark' title='Permanent Link: Neural networks in ActionScript 3'>Neural networks in ActionScript 3</a></li>
<li><a href='http://blog.another-d-mention.ro/programming/how-to-identify-at-runtime-if-swf-is-in-debug-or-release-mode-build/' rel='bookmark' title='Permanent Link: How to identify at runtime if the swf is in debug or release mode/build'>How to identify at runtime if the swf is in debug or release mode/build</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.another-d-mention.ro/programming/how-to-clone-duplicate-an-object-in-actionscript-3/feed/</wfw:commentRss>
		<slash:comments>19</slash:comments>
		</item>
		<item>
		<title>Create professional Flex components</title>
		<link>http://blog.another-d-mention.ro/programming/create-professional-flex-components/</link>
		<comments>http://blog.another-d-mention.ro/programming/create-professional-flex-components/#comments</comments>
		<pubDate>Fri, 05 Jun 2009 17:50:08 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Flex / ActionScript]]></category>
		<category><![CDATA[How To's]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[components]]></category>
		<category><![CDATA[custom]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[flex]]></category>

		<guid isPermaLink="false">http://blog.another-d-mention.ro/?p=412</guid>
		<description><![CDATA[Flex Builder has a great way to organize its components in tree mode, which is very a good way to organize things and make things clear to any user who are coming to Flex world. By default, every component you create that is not part of default Flex components you will have placed in the [...]


Related posts:<ol><li><a href='http://blog.another-d-mention.ro/programming/flex-components-pack/' rel='bookmark' title='Permanent Link: Flex Components Pack'>Flex Components Pack</a></li>
<li><a href='http://blog.another-d-mention.ro/programming/how-to-identify-at-runtime-if-swf-is-in-debug-or-release-mode-build/' rel='bookmark' title='Permanent Link: How to identify at runtime if the swf is in debug or release mode/build'>How to identify at runtime if the swf is in debug or release mode/build</a></li>
<li><a href='http://blog.another-d-mention.ro/programming/create-flexas3-applications-for-mobile-devices/' rel='bookmark' title='Permanent Link: Create Flex/AS3 applications for Mobile Devices'>Create Flex/AS3 applications for Mobile Devices</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Flex Builder has a great way to organize its components in tree mode, which is very a good way to organize things and make things clear to any user who are coming to Flex world.</p>
<p>By default, every component you create that is not part of default Flex components you will have placed in the [Custom] directory of <strong>Flex Components</strong> view in your <strong>Flex/Flash Builder</strong>, and no matter what properties you add to them, they will never be visible in the <strong>Flex Properties</strong> standard view.</p>
<p>But what if you want to customize that and create a component that have them all like flex components do? Well, it's not that hard so let's do that.</p>
<h4>Create the Component</h4>
<p>First, you have to <strong>create a new Flex Library Project</strong>. Do this by going to File-&gt;New and choose Flex Library Project. Give it a name, a location, choose whatever Flex SDK you wish to build this for and then click finish.</p>
<p>Now you have a blank library project in which you can create whatever components you want.<br />
Is <span style="color: #ff0000;">important</span> to use packages correctly and namespaces and not just drop the component in the [src] folder (you'll see later why). First create a package (eg. com.adm.component) in which you can add your custom component.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> com.adm.component
<span style="color: #000000;">&#123;</span>
      <span style="color: #0033ff; font-weight: bold;">import</span> mx.containers.Canvas;
&nbsp;
      <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> mycomponent extends Canvas
      <span style="color: #000000;">&#123;</span>
      <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Okay, now let's create some methods to have something going. We'll make this component be a big button with a method to enable the button and one to change it's caption. We'll use setters and getter's for those properties because some other actions might be required when changing them. So:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> com.adm.component
<span style="color: #000000;">&#123;</span>
     <span style="color: #0033ff; font-weight: bold;">import</span> mx.containers.Canvas;
     <span style="color: #0033ff; font-weight: bold;">import</span> mx.controls.Button;
&nbsp;
      <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> mycomponent extends Canvas
      <span style="color: #000000;">&#123;</span>
            <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _title <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">String</span> = <span style="color: #990000;">'Title'</span>;
            <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _active <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">Boolean</span> = <span style="color: #0033ff; font-weight: bold;">true</span>;
&nbsp;
            <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> btn <span style="color: #000000; font-weight: bold;">:</span> Button = <span style="color: #0033ff; font-weight: bold;">new</span> Button<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
            <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> CustomComponent<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                      <span style="color: #0033ff; font-weight: bold;">super</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
                      <span style="color: #0033ff; font-weight: bold;">this</span>.btn.<span style="color: #004993;">width</span> = <span style="color: #000000; font-weight:bold;">100</span>;
                      <span style="color: #0033ff; font-weight: bold;">this</span>.btn.<span style="color: #004993;">height</span> = <span style="color: #000000; font-weight:bold;">100</span>;
                      <span style="color: #0033ff; font-weight: bold;">this</span>.btn.label = <span style="color: #0033ff; font-weight: bold;">this</span>.label;
                      <span style="color: #0033ff; font-weight: bold;">this</span>.<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">this</span>.btn<span style="color: #000000;">&#41;</span>;
            <span style="color: #000000;">&#125;</span>
&nbsp;
            <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #0033ff; font-weight: bold;">set</span> title<span style="color: #000000;">&#40;</span>val <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">String</span><span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span>
            <span style="color: #000000;">&#123;</span>
                      <span style="color: #0033ff; font-weight: bold;">this</span>._title = val;
                      <span style="color: #0033ff; font-weight: bold;">this</span>.btn.label = val;
            <span style="color: #000000;">&#125;</span>
&nbsp;
            <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #0033ff; font-weight: bold;">get</span> title<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">String</span>
            <span style="color: #000000;">&#123;</span>
                     <span style="color: #0033ff; font-weight: bold;">return</span> <span style="color: #0033ff; font-weight: bold;">this</span>._title;
            <span style="color: #000000;">&#125;</span>
&nbsp;
            <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #0033ff; font-weight: bold;">set</span> <span style="color: #004993;">active</span><span style="color: #000000;">&#40;</span>val <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">Boolean</span><span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span>
            <span style="color: #000000;">&#123;</span>
                     <span style="color: #0033ff; font-weight: bold;">this</span>._active = val;
                     <span style="color: #0033ff; font-weight: bold;">this</span>.btn.<span style="color: #004993;">enabled</span>= val;
            <span style="color: #000000;">&#125;</span>
&nbsp;
            <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #0033ff; font-weight: bold;">get</span> <span style="color: #004993;">active</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">Boolean</span>
            <span style="color: #000000;">&#123;</span>
                    <span style="color: #0033ff; font-weight: bold;">return</span> <span style="color: #0033ff; font-weight: bold;">this</span>._active;
            <span style="color: #000000;">&#125;</span>
      <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>So, if you now build your project, a .swc file will be generated in your [bin] folder, which you can add in other projects and use. But now, the component will be placed in the [Custom] directory in the Components View and not the one you want. We'll do that a bit later now let's just....</p>
<h4>Give it an icon</h4>
<p>This is really simple. All you have to do is get a nice looking .png icon (16x16 pixels preferably) and place it next to your component. Then, use the <strong>IconFile</strong> metadata tag to link it to your component.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;">....
<span style="color: #000000;">&#91;</span>IconFile<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;icon.png&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> mycomponent extends Canvas
<span style="color: #000000;">&#123;</span>
       <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _title <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">String</span> = <span style="color: #990000;">'Title'</span>;
       .......</pre></div></div>

<h4>Inspectable properties</h4>
<p>If you have extra information about the property that will help code hints or the Property Inspector (such as enumeration values or that a String is actually a file path) then also add [Inspectable] metadata with that extra info. For our methods we have:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;">       ...
       <span style="color: #000000;">&#91;</span>Inspectable<span style="color: #000000;">&#40;</span>category=<span style="color: #990000;">&quot;General&quot;</span>, <span style="color: #004993;">type</span>=<span style="color: #990000;">&quot;String&quot;</span>, defaultValue=<span style="color: #990000;">&quot;&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
       <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #0033ff; font-weight: bold;">set</span> title<span style="color: #000000;">&#40;</span>val <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">String</span><span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span>
       .....
       .....
       <span style="color: #000000;">&#91;</span>Inspectable<span style="color: #000000;">&#40;</span>category=<span style="color: #990000;">&quot;General&quot;</span>, <span style="color: #004993;">type</span>=<span style="color: #990000;">&quot;Boolean&quot;</span>, defaultValue=<span style="color: #990000;">&quot;true&quot;</span>, enumeration=<span style="color: #990000;">&quot;true,false&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
       <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #0033ff; font-weight: bold;">set</span> <span style="color: #004993;">active</span><span style="color: #000000;">&#40;</span>val <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">Boolean</span><span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span></pre></div></div>

<p>This will also help a lot when we'll add this properties in the Flex Properties panel. For more informations about the [Inspectable] metadata tag visit <a href="http://livedocs.adobe.com/flex/2/docs/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&amp;file=00001658.html" target="_blank">http://livedocs.adobe.com/flex/2/docs/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&amp;file=00001658.html</a></p>
<h4>Create custom component folder</h4>
<p>So, if you want to build a professional component, you can't leave Flex add your component in the default [Custom] directory in the Components tree. So, in order to create your own folder, we must use few tricks.</p>
<p>First of all, you need two .xml files to describe the structure you want flex to use and overide it's default behavior.<br />
The first file is the manifest.xml which describes the components in the package and their namespaces. In our case we'll have:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;">&lt; ?xml <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;componentpackage<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;component</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;mycomponent&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.adm.component.mycomponent&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/componentpackage<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Second, we need another xml to describe the way the designer will interpret all this.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;">&lt; ?xml <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;design<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;namespaces<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;namespace</span> <span style="color: #000066;">prefix</span>=<span style="color: #ff0000;">&quot;adm&quot;</span> <span style="color: #000066;">uri</span>=<span style="color: #ff0000;">&quot;http://www.adm.org&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/namespaces<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;categories<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;category</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;Test&quot;</span> <span style="color: #000066;">label</span>=<span style="color: #ff0000;">&quot;Test Panel&quot;</span> <span style="color: #000066;">defaultExpand</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/categories<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;components<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;component</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;mycomponent&quot;</span> <span style="color: #000066;">namespace</span>=<span style="color: #ff0000;">&quot;adm&quot;</span> <span style="color: #000066;">category</span>=<span style="color: #ff0000;">&quot;Test&quot;</span> <span style="color: #000066;">displayName</span>=<span style="color: #ff0000;">&quot;Rename Me&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/components<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/design<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>In the design.xml, you can specify the namespaces you used for the components, in this case adm will point to components in the org.adm folder.</p>
<p>Categories tag describes the folders you want added in the Components panel. Each category must have an <strong>id</strong> which you'll use to tell components where they should reside, a <strong>label</strong> for the category to stand as the directory name in the Components panel. <strong>defaultExpand</strong> is an optional parameter which if set to true, the folder will be showed expanded by default.</p>
<p>In the components tag, you specify which component goes in what category and under what title. The <strong>name</strong> parameter must match the id of a component listed in the manifest.xml. All the other parameters are pretty self explanatory.</p>
<p>Next, you have to include this two files in .swc package. To do that, follow the steps:</p>
<p>* Right Click at your project and select Properties<br />
* In the left choose Flex Library Build Path<br />
* Select the assets tab and mark to include manifest.xml and design.xml files<br />
* Now select the Flex Library Compiler and include your namespace URL (in this case http://www.adm.org)<br />
* Include the manifest file .xml you've created<br />
* Click apply and ok to finish</p>
<p><img class="aligncenter size-full wp-image-432" title="design" src="http://blog.another-d-mention.ro/wp-content/uploads/2009/06/design.png" alt="design Create professional Flex components" width="476" height="375" /><br />
<img class="aligncenter size-full wp-image-433" title="manifest" src="http://blog.another-d-mention.ro/wp-content/uploads/2009/06/manifest.png" alt="manifest Create professional Flex components" width="483" height="380" /></p>
<p>After this, you should end up with something like this</p>
<p><img class="aligncenter size-full wp-image-428" title="comppanel" src="http://blog.another-d-mention.ro/wp-content/uploads/2009/06/comppanel.png" alt="comppanel Create professional Flex components" width="297" height="225" /></p>
<h4>Add properties to the Flex Properties view</h4>
<p>As I said before, no matter what properties you add to your component, they will never be visible in the <strong>Flex Properties</strong> standard view, only in the category view and that only if you use the [Inspectable] metadata tag. But few more lines in the design.xml file should take care of that.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;component</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;mycomponent&quot;</span> <span style="color: #000066;">namespace</span>=<span style="color: #ff0000;">&quot;adm&quot;</span> <span style="color: #000066;">category</span>=<span style="color: #ff0000;">&quot;Test&quot;</span> <span style="color: #000066;">displayName</span>=<span style="color: #ff0000;">&quot;Rename Me&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mxmlproperties<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;textfield</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;title&quot;</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;Component Title:&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;combo</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;active&quot;</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;Active:&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mxmlproperties<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;defaultattribute</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;active&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/component<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>The id of the mxmlProperties tag should be the function/variable names from your component you want to edit. You can also define default values for those properties using the defaultAttribute tag below. Here we've only used the textfield and the combo type but there are few more you can use.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;textfiled</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;propertyOrStyle&quot;</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;Label:&quot;</span> <span style="color: #66cc66;">&#91;</span><span style="color: #000066;">multiline</span>=<span style="color: #ff0000;">&quot;false&quot;</span><span style="color: #66cc66;">&#93;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;combo</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;propertyOrStyle&quot;</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;Label:&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;colorpicker</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;propertyOrStyle&quot;</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;Label:&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;filepicker</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;propertyOrStyle&quot;</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;Label:&quot;</span> <span style="color: #66cc66;">&#91;</span><span style="color: #000066;">wrapInEmbed</span>=<span style="color: #ff0000;">&quot;false&quot;</span><span style="color: #66cc66;">&#93;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;slider</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;propertyOrStyle&quot;</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;Label:&quot;</span> <span style="color: #000066;">min</span>=<span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #000066;">max</span>=<span style="color: #ff0000;">&quot;10&quot;</span> <span style="color: #000066;">increment</span>=<span style="color: #ff0000;">&quot;1&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></div></div>

<p> For combo boxes, if you use it for a Boolean property, it will automatically be populated with [true,false] values but if want something else, the [Inspectable] metadata tag has the enumeration property where you can define the properties from this combo.</p>
<p><img class="aligncenter size-full wp-image-431" title="flexprop" src="http://blog.another-d-mention.ro/wp-content/uploads/2009/06/flexprop.png" alt="flexprop Create professional Flex components" width="298" height="207" /></p>
<p>Another thing you must do in order to apply the values as soon as you change them from the properties view, is to set the functions/variables as [Bindable].</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;">    ....
    <span style="color: #000000;">&#91;</span>Inspectable<span style="color: #000000;">&#40;</span>category=<span style="color: #990000;">&quot;General&quot;</span>, <span style="color: #004993;">type</span>=<span style="color: #990000;">&quot;String&quot;</span>, defaultValue=<span style="color: #990000;">&quot;&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
    <span style="color: #000000;">&#91;</span>Bindable<span style="color: #000000;">&#93;</span>
    <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #0033ff; font-weight: bold;">set</span> title<span style="color: #000000;">&#40;</span>val <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">String</span><span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span>
	....
	....
    <span style="color: #000000;">&#91;</span>Inspectable<span style="color: #000000;">&#40;</span>category=<span style="color: #990000;">&quot;General&quot;</span>, <span style="color: #004993;">type</span>=<span style="color: #990000;">&quot;Boolean&quot;</span>, defaultValue=<span style="color: #990000;">&quot;true&quot;</span>, enumeration=<span style="color: #990000;">&quot;true,false&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
    <span style="color: #000000;">&#91;</span>Bindable<span style="color: #000000;">&#93;</span>
    <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #0033ff; font-weight: bold;">set</span> <span style="color: #004993;">active</span><span style="color: #000000;">&#40;</span>val <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">Boolean</span><span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span>
	....
	....</pre></div></div>

<h4>One more thing</h4>
<p>Now, compiling this will give you a 300 something KB .swc file which is a bit large to distribute. The user will use this component inside a flex component so embedding all the libraries and SDK inside your .swc is useless. So the next step is to go to Properties-&gt;Flex Library Build Path-&gt;Library path tab, expand the build path library try and edit everything inside the SDK tree on Link Type and choose <strong>External</strong></p>
<p><img class="aligncenter size-full wp-image-434" title="paths" src="http://blog.another-d-mention.ro/wp-content/uploads/2009/06/paths.png" alt="paths Create professional Flex components" width="526" height="287" /></p>
<p>Now the swc component only have 4KB. Big cut down, eh ?</p>
<h4>Done</h4>
<p>If this is to much trouble for you or you've missed something, I've attached the sources for this tutorial <a href="http://blog.another-d-mention.ro/stuff/component.zip">here</a>. You can import this skeleton  rename the package, namespace and the component and start building on this. I hope it all made sense and....happy coding.</p>


<p>Related posts:<ol><li><a href='http://blog.another-d-mention.ro/programming/flex-components-pack/' rel='bookmark' title='Permanent Link: Flex Components Pack'>Flex Components Pack</a></li>
<li><a href='http://blog.another-d-mention.ro/programming/how-to-identify-at-runtime-if-swf-is-in-debug-or-release-mode-build/' rel='bookmark' title='Permanent Link: How to identify at runtime if the swf is in debug or release mode/build'>How to identify at runtime if the swf is in debug or release mode/build</a></li>
<li><a href='http://blog.another-d-mention.ro/programming/create-flexas3-applications-for-mobile-devices/' rel='bookmark' title='Permanent Link: Create Flex/AS3 applications for Mobile Devices'>Create Flex/AS3 applications for Mobile Devices</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.another-d-mention.ro/programming/create-professional-flex-components/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>How To &#8211; Center a image on a canvas in flex</title>
		<link>http://blog.another-d-mention.ro/programming/how-to-center-a-image-on-a-canvas-in-flex/</link>
		<comments>http://blog.another-d-mention.ro/programming/how-to-center-a-image-on-a-canvas-in-flex/#comments</comments>
		<pubDate>Sun, 12 Apr 2009 21:11:52 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Flex / ActionScript]]></category>
		<category><![CDATA[How To's]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[canvas]]></category>
		<category><![CDATA[center]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[image]]></category>

		<guid isPermaLink="false">http://blog.another-d-mention.ro/?p=294</guid>
		<description><![CDATA[This is the solution for the anoying behaivor of the image control into a canvas or hbox or whatever. If the image is set to be scaled to a maximum width and height and maintaining the aspect ration, it won't center itself even if it has the horizontalCenter set to "0". So...here's how it looks [...]


Related posts:<ol><li><a href='http://blog.another-d-mention.ro/programming/right-click-and-custom-context-menu-in-flash-flex/' rel='bookmark' title='Permanent Link: Right click and custom context menu in Flash/Flex'>Right click and custom context menu in Flash/Flex</a></li>
<li><a href='http://blog.another-d-mention.ro/programming/create-professional-flex-components/' rel='bookmark' title='Permanent Link: Create professional Flex components'>Create professional Flex components</a></li>
<li><a href='http://blog.another-d-mention.ro/programming/how-to-clone-duplicate-an-object-in-actionscript-3/' rel='bookmark' title='Permanent Link: How to clone (duplicate) an object in ActionScript 3'>How to clone (duplicate) an object in ActionScript 3</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p><!-- adman --><br />
This is the solution for the anoying behaivor of the image control into a canvas or hbox or whatever. If the image is set to be scaled to a maximum width and height and maintaining the aspect ration, it won't center itself even if it has the horizontalCenter set to "0". So...here's how it looks (top) and how it suppose to look (bottom)</p>
<p><a href="http://blog.another-d-mention.ro/wp-content/uploads/2009/04/canvas.png"><img class="aligncenter size-full wp-image-295" title="canvas" src="http://blog.another-d-mention.ro/wp-content/uploads/2009/04/canvas.png" alt="canvas How To   Center a image on a canvas in flex" width="558" height="553" /></a></p>
<p><strong>Solution</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
</pre></td><td class="code"><pre class="actionscript" style="font-family:monospace;">&nbsp;
    <span style="color: #66cc66;">&lt;</span>mx :Script<span style="color: #66cc66;">&gt;</span>
        <span style="color: #66cc66;">&lt;</span> <span style="color: #66cc66;">!</span><span style="color: #66cc66;">&#91;</span>CDATA<span style="color: #66cc66;">&#91;</span>
&nbsp;
                <span style="color: #808080; font-style: italic;">// Maximum  width</span>
                <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> mxw:<span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">500</span>;              
                <span style="color: #808080; font-style: italic;">// Maximum height</span>
               <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> mxh:<span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">250</span>;
&nbsp;
               <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> onImageComplete<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
               <span style="color: #66cc66;">&#123;</span>
                <span style="color: #000000; font-weight: bold;">var</span> wthMaxRatio:<span style="color: #0066CC;">Number</span> = mxw <span style="color: #66cc66;">/</span> mxh;
&nbsp;
                <span style="color: #808080; font-style: italic;">// no resize needed</span>
                <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>.<span style="color: #0066CC;">target</span>.<span style="color: #006600;">contentWidth</span> <span style="color: #66cc66;">&lt;</span>= mxw <span style="color: #66cc66;">&amp;&amp;</span> <span style="color: #0066CC;">e</span>.<span style="color: #0066CC;">target</span>.<span style="color: #006600;">contentHeight</span> <span style="color: #66cc66;">&lt;</span>= mxh<span style="color: #66cc66;">&#41;</span>
                <span style="color: #66cc66;">&#123;</span>
                    <span style="color: #0066CC;">e</span>.<span style="color: #0066CC;">target</span>.<span style="color: #006600;">x</span> = <span style="color: #66cc66;">&#40;</span>mxw - <span style="color: #0066CC;">e</span>.<span style="color: #0066CC;">target</span>.<span style="color: #006600;">contentWidth</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">/</span> <span style="color: #cc66cc;">2</span>;
                    <span style="color: #0066CC;">e</span>.<span style="color: #0066CC;">target</span>.<span style="color: #006600;">y</span> = <span style="color: #66cc66;">&#40;</span>mxh - <span style="color: #0066CC;">e</span>.<span style="color: #0066CC;">target</span>.<span style="color: #006600;">contentHeight</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">/</span> <span style="color: #cc66cc;">2</span>;
                <span style="color: #66cc66;">&#125;</span>
                <span style="color: #b1b100;">else</span>
                <span style="color: #66cc66;">&#123;</span>
                    <span style="color: #000000; font-weight: bold;">var</span> wthImgRatio:<span style="color: #0066CC;">Number</span> = <span style="color: #0066CC;">e</span>.<span style="color: #0066CC;">target</span>.<span style="color: #006600;">contentWidth</span> <span style="color: #66cc66;">/</span> <span style="color: #0066CC;">e</span>.<span style="color: #0066CC;">target</span>.<span style="color: #006600;">contentHeight</span>;
&nbsp;
                    <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>wthImgRatio <span style="color: #66cc66;">&gt;</span> wthMaxRatio<span style="color: #66cc66;">&#41;</span>
                    <span style="color: #66cc66;">&#123;</span>
                        <span style="color: #808080; font-style: italic;">// will max out the width</span>
                        <span style="color: #0066CC;">e</span>.<span style="color: #0066CC;">target</span>.<span style="color: #0066CC;">width</span> = mxw;
                        <span style="color: #000000; font-weight: bold;">var</span> imgHeight:<span style="color: #0066CC;">Number</span> = <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">round</span><span style="color: #66cc66;">&#40;</span> <span style="color: #66cc66;">&#40;</span>mxw <span style="color: #66cc66;">/</span> <span style="color: #0066CC;">e</span>.<span style="color: #0066CC;">target</span>.<span style="color: #006600;">contentWidth</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">*</span> <span style="color: #0066CC;">e</span>.<span style="color: #0066CC;">target</span>.<span style="color: #006600;">contentHeight</span> <span style="color: #66cc66;">&#41;</span>;
                        <span style="color: #000000; font-weight: bold;">var</span> newY:<span style="color: #0066CC;">Number</span> = <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">round</span><span style="color: #66cc66;">&#40;</span> <span style="color: #66cc66;">&#40;</span>mxh - imgHeight<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">/</span> <span style="color: #cc66cc;">2</span> <span style="color: #66cc66;">&#41;</span>;
                        <span style="color: #0066CC;">e</span>.<span style="color: #0066CC;">target</span>.<span style="color: #006600;">x</span> = <span style="color: #cc66cc;">0</span>;
                        <span style="color: #0066CC;">e</span>.<span style="color: #0066CC;">target</span>.<span style="color: #006600;">y</span> = newY;
                    <span style="color: #66cc66;">&#125;</span>
                    <span style="color: #b1b100;">else</span>
                    <span style="color: #66cc66;">&#123;</span>
                        <span style="color: #808080; font-style: italic;">// will max out the height</span>
                        <span style="color: #0066CC;">e</span>.<span style="color: #0066CC;">target</span>.<span style="color: #0066CC;">height</span> = mxh;
                        <span style="color: #000000; font-weight: bold;">var</span> imgWidth:<span style="color: #0066CC;">Number</span> = <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">round</span><span style="color: #66cc66;">&#40;</span> <span style="color: #66cc66;">&#40;</span>mxh <span style="color: #66cc66;">/</span> <span style="color: #0066CC;">e</span>.<span style="color: #0066CC;">target</span>.<span style="color: #006600;">contentHeight</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">*</span> <span style="color: #0066CC;">e</span>.<span style="color: #0066CC;">target</span>.<span style="color: #006600;">contentWidth</span> <span style="color: #66cc66;">&#41;</span>;
                        <span style="color: #000000; font-weight: bold;">var</span> newX:<span style="color: #0066CC;">Number</span> = <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">round</span><span style="color: #66cc66;">&#40;</span> <span style="color: #66cc66;">&#40;</span>mxw - imgWidth<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">/</span> <span style="color: #cc66cc;">2</span> <span style="color: #66cc66;">&#41;</span>;
                        <span style="color: #0066CC;">e</span>.<span style="color: #0066CC;">target</span>.<span style="color: #006600;">x</span> = newX;
                        <span style="color: #0066CC;">e</span>.<span style="color: #0066CC;">target</span>.<span style="color: #006600;">y</span> = <span style="color: #cc66cc;">0</span>;
                    <span style="color: #66cc66;">&#125;</span>
                <span style="color: #66cc66;">&#125;</span>
              <span style="color: #66cc66;">&#125;</span>
         <span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&gt;</span>
    <span style="color: #66cc66;">&lt;/</span>mx<span style="color: #66cc66;">&gt;</span>
&nbsp;
&nbsp;
      <span style="color: #66cc66;">&lt;</span>mx :Canvas <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;500&quot;</span> <span style="color: #0066CC;">height</span>=<span style="color: #ff0000;">&quot;250&quot;</span>
            verticalScrollPolicy=<span style="color: #ff0000;">&quot;off&quot;</span> horizontalScrollPolicy=<span style="color: #ff0000;">&quot;off&quot;</span> 
            <span style="color: #0066CC;">backgroundColor</span>=<span style="color: #ff0000;">&quot;#000000&quot;</span><span style="color: #66cc66;">&gt;</span>
&nbsp;
            <span style="color: #66cc66;">&lt;</span>mx :Image id=<span style="color: #ff0000;">&quot;theimage&quot;</span>
                maintainAspectRatio=<span style="color: #ff0000;">&quot;true&quot;</span>
		scaleContent=<span style="color: #ff0000;">&quot;true&quot;</span>
                complete=<span style="color: #ff0000;">&quot;onImageComplete(event)&quot;</span> <span style="color: #66cc66;">/&gt;</span>
&nbsp;
        <span style="color: #66cc66;">&lt;/</span>mx<span style="color: #66cc66;">&gt;</span></pre></td></tr></table></div>

<p><!-- adman --></p>


<p>Related posts:<ol><li><a href='http://blog.another-d-mention.ro/programming/right-click-and-custom-context-menu-in-flash-flex/' rel='bookmark' title='Permanent Link: Right click and custom context menu in Flash/Flex'>Right click and custom context menu in Flash/Flex</a></li>
<li><a href='http://blog.another-d-mention.ro/programming/create-professional-flex-components/' rel='bookmark' title='Permanent Link: Create professional Flex components'>Create professional Flex components</a></li>
<li><a href='http://blog.another-d-mention.ro/programming/how-to-clone-duplicate-an-object-in-actionscript-3/' rel='bookmark' title='Permanent Link: How to clone (duplicate) an object in ActionScript 3'>How to clone (duplicate) an object in ActionScript 3</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.another-d-mention.ro/programming/how-to-center-a-image-on-a-canvas-in-flex/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Sudoku solver in python</title>
		<link>http://blog.another-d-mention.ro/programming/sudoku-solver-in-python/</link>
		<comments>http://blog.another-d-mention.ro/programming/sudoku-solver-in-python/#comments</comments>
		<pubDate>Fri, 27 Mar 2009 22:00:51 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[How To's]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Stuff]]></category>
		<category><![CDATA[solver]]></category>
		<category><![CDATA[sudoku]]></category>

		<guid isPermaLink="false">http://blog.another-d-mention.ro/?p=273</guid>
		<description><![CDATA[Sudoku is a logic-based, combinatorial number-placement puzzle. The objective is to fill a 9×9 grid so that each column, each row, and each of the nine 3×3 boxes (also called blocks or regions) contains the digits from 1 to 9 only one time each. The puzzle setter provides a partially completed grid. I'm really not [...]


Related posts:<ol><li><a href='http://blog.another-d-mention.ro/programming/how-to-run-python-code-in-windows-batch-bat-files/' rel='bookmark' title='Permanent Link: How to run python code in Windows batch (bat) files'>How to run python code in Windows batch (bat) files</a></li>
<li><a href='http://blog.another-d-mention.ro/programming/python/quick-python-script-explanation/' rel='bookmark' title='Permanent Link: Quick Python Script Explanation'>Quick Python Script Explanation</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.another-d-mention.ro/wp-content/uploads/2009/03/lens1512255_sudoku12.gif"><img class="alignleft size-full wp-image-280" style="margin: 10px 10px 10px 0px;" title="lens1512255_sudoku12" src="http://blog.another-d-mention.ro/wp-content/uploads/2009/03/lens1512255_sudoku12.gif" alt="lens1512255 sudoku12 Sudoku solver in python" width="116" height="116" /></a>Sudoku is a logic-based, combinatorial number-placement puzzle. The objective is to fill a 9×9 grid so that each column, each row, and each of the nine 3×3 boxes (also called blocks or regions) contains the digits from 1 to 9 only <em>one</em> time each. The puzzle setter provides a partially completed grid.<br />
I'm really not a sudoku fan but I love solving problems and sudoku offers you a challenging one. So...here's a the shortest sudoku solver written in python</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">def</span> r<span style="color: black;">&#40;</span>a<span style="color: black;">&#41;</span>:i=a.<span style="color: black;">find</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'0'</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">;</span>~i <span style="color: #ff7700;font-weight:bold;">or</span> exit<span style="color: black;">&#40;</span>a<span style="color: black;">&#41;</span><span style="color: #66cc66;">;</span><span style="color: black;">&#91;</span>m
<span style="color: #ff7700;font-weight:bold;">in</span><span style="color: black;">&#91;</span><span style="color: black;">&#40;</span>i-j<span style="color: black;">&#41;</span><span style="color: #66cc66;">%</span>9<span style="color: #66cc66;">*</span><span style="color: black;">&#40;</span>i/<span style="color: #ff4500;">9</span>^j/<span style="color: #ff4500;">9</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">*</span><span style="color: black;">&#40;</span>i/<span style="color: #ff4500;">27</span>^j/<span style="color: #ff4500;">27</span>|i<span style="color: #66cc66;">%</span>9/<span style="color: #ff4500;">3</span>^j<span style="color: #66cc66;">%</span>9/<span style="color: #ff4500;">3</span><span style="color: black;">&#41;</span><span style="color: #ff7700;font-weight:bold;">or</span> a<span style="color: black;">&#91;</span>j<span style="color: black;">&#93;</span><span style="color: #ff7700;font-weight:bold;">for</span>
j <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">81</span><span style="color: black;">&#41;</span><span style="color: black;">&#93;</span><span style="color: #ff7700;font-weight:bold;">or</span> r<span style="color: black;">&#40;</span>a<span style="color: black;">&#91;</span>:i<span style="color: black;">&#93;</span>+m+a<span style="color: black;">&#91;</span>i+<span style="color: #ff4500;">1</span>:<span style="color: black;">&#93;</span><span style="color: black;">&#41;</span><span style="color: #ff7700;font-weight:bold;">for</span> m <span style="color: #ff7700;font-weight:bold;">in</span><span style="color: #483d8b;">'%d'</span><span style="color: #66cc66;">%</span>5<span style="color: #66cc66;">**</span><span style="color: #ff4500;">18</span><span style="color: black;">&#93;</span>
<span style="color: #ff7700;font-weight:bold;">from</span> <span style="color: #dc143c;">sys</span> <span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #66cc66;">*;</span>r<span style="color: black;">&#40;</span>argv<span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span></pre></td></tr></table></div>

<p>If you want to test that, save it in a file and use the command line to execute the code. Execute the code as following: <em>python solver.py puzzle</em> - where puzzle is an 81 character string representing the puzzle read left-to-right, top-to-bottom, and 0 is a blank space</p>

<div class="wp_syntax"><div class="code"><pre class="dos" style="font-family:monospace;">python solver.py <span style="color: #cc66cc;">530070000600195000098000060800060003400803001700020006060000280000419005000080079</span></pre></div></div>

<p>The problem with the above code is that is really slow. Here's another one that runs about 100x faster and is less cryptic.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
</pre></td><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">sys</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> same_row<span style="color: black;">&#40;</span>i,j<span style="color: black;">&#41;</span>: <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: black;">&#40;</span>i/<span style="color: #ff4500;">9</span> == j/<span style="color: #ff4500;">9</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">def</span> same_col<span style="color: black;">&#40;</span>i,j<span style="color: black;">&#41;</span>: <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: black;">&#40;</span>i-j<span style="color: black;">&#41;</span> <span style="color: #66cc66;">%</span> <span style="color: #ff4500;">9</span> == <span style="color: #ff4500;">0</span>
<span style="color: #ff7700;font-weight:bold;">def</span> same_block<span style="color: black;">&#40;</span>i,j<span style="color: black;">&#41;</span>: <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: black;">&#40;</span>i/<span style="color: #ff4500;">27</span> == j/<span style="color: #ff4500;">27</span> <span style="color: #ff7700;font-weight:bold;">and</span> i<span style="color: #66cc66;">%</span>9/<span style="color: #ff4500;">3</span> == j<span style="color: #66cc66;">%</span>9/<span style="color: #ff4500;">3</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> r<span style="color: black;">&#40;</span>a<span style="color: black;">&#41;</span>:
  i = a.<span style="color: black;">find</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'0'</span><span style="color: black;">&#41;</span>
  <span style="color: #ff7700;font-weight:bold;">if</span> i == -<span style="color: #ff4500;">1</span>:
    <span style="color: #dc143c;">sys</span>.<span style="color: black;">exit</span><span style="color: black;">&#40;</span>a<span style="color: black;">&#41;</span>
&nbsp;
  excluded_numbers = <span style="color: #008000;">set</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
  <span style="color: #ff7700;font-weight:bold;">for</span> j <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">81</span><span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">if</span> same_row<span style="color: black;">&#40;</span>i,j<span style="color: black;">&#41;</span> <span style="color: #ff7700;font-weight:bold;">or</span> same_col<span style="color: black;">&#40;</span>i,j<span style="color: black;">&#41;</span> <span style="color: #ff7700;font-weight:bold;">or</span> same_block<span style="color: black;">&#40;</span>i,j<span style="color: black;">&#41;</span>:
      excluded_numbers.<span style="color: black;">add</span><span style="color: black;">&#40;</span>a<span style="color: black;">&#91;</span>j<span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
&nbsp;
  <span style="color: #ff7700;font-weight:bold;">for</span> m <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #483d8b;">'123456789'</span>:
    <span style="color: #ff7700;font-weight:bold;">if</span> m <span style="color: #ff7700;font-weight:bold;">not</span> <span style="color: #ff7700;font-weight:bold;">in</span> excluded_numbers:
      <span style="color: #808080; font-style: italic;"># At this point, m is not excluded by any row, column, or block, so let's place it and recurse</span>
      r<span style="color: black;">&#40;</span>a<span style="color: black;">&#91;</span>:i<span style="color: black;">&#93;</span>+m+a<span style="color: black;">&#91;</span>i+<span style="color: #ff4500;">1</span>:<span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">if</span> __name__ == <span style="color: #483d8b;">'__main__'</span>:
  <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">len</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">sys</span>.<span style="color: black;">argv</span><span style="color: black;">&#41;</span> == <span style="color: #ff4500;">2</span> <span style="color: #ff7700;font-weight:bold;">and</span> <span style="color: #008000;">len</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">sys</span>.<span style="color: black;">argv</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span> == <span style="color: #ff4500;">81</span>:
    r<span style="color: black;">&#40;</span><span style="color: #dc143c;">sys</span>.<span style="color: black;">argv</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
  <span style="color: #ff7700;font-weight:bold;">else</span>:
    <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'Usage: python sudoku.py puzzle'</span></pre></td></tr></table></div>



<p>Related posts:<ol><li><a href='http://blog.another-d-mention.ro/programming/how-to-run-python-code-in-windows-batch-bat-files/' rel='bookmark' title='Permanent Link: How to run python code in Windows batch (bat) files'>How to run python code in Windows batch (bat) files</a></li>
<li><a href='http://blog.another-d-mention.ro/programming/python/quick-python-script-explanation/' rel='bookmark' title='Permanent Link: Quick Python Script Explanation'>Quick Python Script Explanation</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.another-d-mention.ro/programming/sudoku-solver-in-python/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How To &#8211; Setup a Subversion server on Windows</title>
		<link>http://blog.another-d-mention.ro/how-tos/how-to-setup-a-subversion-server-on-windows/</link>
		<comments>http://blog.another-d-mention.ro/how-tos/how-to-setup-a-subversion-server-on-windows/#comments</comments>
		<pubDate>Mon, 23 Feb 2009 16:50:48 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[How To's]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[svn]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://blog.another-d-mention.ro/?p=79</guid>
		<description><![CDATA[What is subversion Subversion (svn) is a version control system initiated in 2000 by CollabNet. It is used to maintain current and historical versions of files such as source code, web pages documentations etc. Google code also provides free Subversion hosting but if you want your own private server continue reading to learn how to [...]


Related posts:<ol><li><a href='http://blog.another-d-mention.ro/misc/eee-pc/install-windows-xp-on-your-asus-eee-pc-using-a-usb-flash-drive/' rel='bookmark' title='Permanent Link: Install Windows XP on your Asus Eee PC using a USB flash drive'>Install Windows XP on your Asus Eee PC using a USB flash drive</a></li>
<li><a href='http://blog.another-d-mention.ro/misc/alfresco-cifs-shared-drive-authentication-problem/' rel='bookmark' title='Permanent Link: Alfresco CIFS shared drive authentication problem'>Alfresco CIFS shared drive authentication problem</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p><!-- adman --><strong>What is subversion</strong></p>
<p>Subversion (svn) is a version control system initiated in 2000 by CollabNet. It is used to maintain current and historical versions of files such as source code, web pages documentations etc. Google code also provides free Subversion hosting but if you want your own private server continue reading to learn how to set up your own svn server</p>
<p>First: get the <a href="http://subversion.tigris.org/servlets/ProjectDocumentList?folderID=91&amp;expandFolder=91&amp;folderID=74">Subversion setup</a> and run it to install Subversion.</p>
<p><strong>Installing svnserve as a service</strong><br />
 <br />
The simplest way to set up a server on Windows is to use svnserv which can be installed as a Windows service.<br />
Run these commands in order to get the service up and running:<br />
 </p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="dos" style="font-family:monospace;">   <span style="color: #b1b100; font-weight: bold;">mkdir</span> c:\svn
   svnadmin create c:\svn\repos</pre></td></tr></table></div>

<p><strong>Start the service:</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="dos" style="font-family:monospace;">   sc create svn binpath= &quot;\&quot;C:\program files\Subversion\bin\svnserve.exe\&quot; --service -r C:\svn&quot; displayname= &quot;Subversion Server&quot; depend= Tcpip start= auto
   net start svn</pre></td></tr></table></div>

<p><strong>Note:</strong> There really are spaces after the = signs.<br />
Check that it worked by checking out the repository:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="dos" style="font-family:monospace;">   svn checkout svn://localhost/repos</pre></td></tr></table></div>

<p><strong>Adding security</strong></p>
<p>Edit C:\svn\repos\conf\svnserve.conf, uncomment these lines and change anon-access to none:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="apache" style="font-family:monospace;">   anon-access = <span style="color: #0000ff;">none</span>
   auth-access = write
   password-db = passwd
   realm = My Subversion Repository</pre></td></tr></table></div>

<p>Now edit C:\svn\repos\conf\passwd and add a user name and password to the users section:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="conf" style="font-family:monospace;">   [users]
   myusername = mypassword</pre></td></tr></table></div>

<p>Delete your first checkout and try to check out the repository again, this time you will have to supply a user name and a password.</p>
<p><strong>Using WebDAV via Apache 2.2</strong></p>
<p>Get and install <a href="http://www.apachefriends.org/en/xampp.html">XAMPP</a>, install Apache and MySQL as a service. Unblock ports as needed when the installation is finishing up.</p>
<p>As we are installing Apache 2.2 so we need builds of the Subversion Apache modules which are compatible with Apache 2.2 which are available here.</p>
<p>XAMPP has a prebuilt mod_dav_svn and mod_authz_svn - they don't work, replace them with the Apache 2.2 built ones which you have just downloaded, the zip file contains a complete build of Subversion but we only need the two Apache module files. The files to replace are mod_dav_svn and mod_authz_svn in c:\xampp\apache\modules.</p>
<p>Edit C:\xampp\apache\conf\httpd.conf and add:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="apache" style="font-family:monospace;">   <span style="color: #00007f;">Include</span> conf/extra/httpd-subversion.conf</pre></td></tr></table></div>

<p>Put this in that file:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="apache" style="font-family:monospace;">   <span style="color: #00007f;">LoadModule</span> authz_svn_module modules/mod_authz_svn.so
   <span style="color: #00007f;">LoadModule</span> dav_svn_module modules/mod_dav_svn.so
   &lt;<span style="color: #000000; font-weight:bold;">location</span> /svn/repos&gt;
     DAV svn
     SVNPath c:/svn/repos
   &lt;/<span style="color: #000000; font-weight:bold;">location</span>&gt;</pre></td></tr></table></div>

<p>Stop and start the Apache service, either using the command line or the XAMPP Control Panel Application. Fire up a web browser and go to http://localhost/svn/repos.</p>
<p><strong>Adding Security</strong></p>
<p>In httpd-subversion.conf, add this to the Location directive:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="apache" style="font-family:monospace;">   <span style="color: #00007f;">AuthType</span> Basic
   <span style="color: #00007f;">AuthName</span> <span style="color: #7f007f;">&quot;Subversion Repository&quot;</span>
   <span style="color: #00007f;">AuthUserFile</span> c:/svn/passwords
   <span style="color: #00007f;">Require</span> valid-<span style="color: #00007f;">user</span></pre></td></tr></table></div>

<p>Now create a password file and add a user, note: xamp htpasswd doesn't like drive letters.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="dos" style="font-family:monospace;">   C:\svn&gt;c:\xampp\apache\bin\htpasswd -cb \svn\passwords myusername mypassword
   Automatically using MD5 format.
   Adding password <span style="color: #00b100; font-weight: bold;">for</span> user myusername</pre></td></tr></table></div>

<p>Then restart Apache again. You will now need to use the user name and password to access your repository.</p>
<p>If you're not familliar with the svn command line or you find it to hard to use, just download <a href="http://tortoisesvn.net/downloads">TortoiseSVN</a>. You'll love it.<br />
<!-- adman --></p>


<p>Related posts:<ol><li><a href='http://blog.another-d-mention.ro/misc/eee-pc/install-windows-xp-on-your-asus-eee-pc-using-a-usb-flash-drive/' rel='bookmark' title='Permanent Link: Install Windows XP on your Asus Eee PC using a USB flash drive'>Install Windows XP on your Asus Eee PC using a USB flash drive</a></li>
<li><a href='http://blog.another-d-mention.ro/misc/alfresco-cifs-shared-drive-authentication-problem/' rel='bookmark' title='Permanent Link: Alfresco CIFS shared drive authentication problem'>Alfresco CIFS shared drive authentication problem</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.another-d-mention.ro/how-tos/how-to-setup-a-subversion-server-on-windows/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How To &#8211; get Cross Browser Compatibility Every Time</title>
		<link>http://blog.another-d-mention.ro/programming/css/how-to-get-cross-browser-compatibility-every-time/</link>
		<comments>http://blog.another-d-mention.ro/programming/css/how-to-get-cross-browser-compatibility-every-time/#comments</comments>
		<pubDate>Fri, 20 Feb 2009 17:15:05 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[How To's]]></category>
		<category><![CDATA[chrome]]></category>
		<category><![CDATA[comaptibility]]></category>
		<category><![CDATA[firefox]]></category>
		<category><![CDATA[ie6]]></category>
		<category><![CDATA[ie7]]></category>
		<category><![CDATA[ie8]]></category>
		<category><![CDATA[opera]]></category>

		<guid isPermaLink="false">http://blog.another-d-mention.ro/?p=37</guid>
		<description><![CDATA[Working with Internet Explorer can be a pain for the everyday web designer. But it doesn't have to be. Many, if not all, of the bugs can be fixed quickly and easily by understanding how the occur. I've put together a list of the major problems beginners have with cross browser compatibility. I'm only going [...]


Related posts:<ol><li><a href='http://blog.another-d-mention.ro/programming/cross-browser-inline-block/' rel='bookmark' title='Permanent Link: Cross browser inline-block'>Cross browser inline-block</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Working with Internet Explorer can be a pain for the everyday web designer. But it doesn't have to be. Many, if not all, of the bugs can be fixed quickly and easily by understanding how the occur. I've put together a list of the major problems beginners have with cross browser compatibility.</p>
<p>I'm only going to be concerned with the major browsers - Firefox 2+, Safari 3+ and Internet Explorer 6+. IE6 is slowly declining.  If you know the IE6 bugs you can generally know if your site will break before you even check it in a browser. This isn't an article for the super-experienced web designer, but hopefully will give some insight to some people who don't understand the mysteries of IE6 and cross browser compatibility.</p>
<h2>Summary</h2>
<p>Here is a quick summary for those of you who don't want to read the whole article:</p>
<ul>
<li>Always use strict doctype and standards-compliant HTML/CSS</li>
<li>Always use a reset at the start of your css</li>
<li>Use -moz-opacity:0.99 on text elements to clean up rendering in Firefox, and text-shadow: #000 0 0 0 in Safari</li>
<li>Never resize images in the CSS or HTML</li>
<li>Check font rendering in every browser. Don't use Lucida</li>
<li>Size text as a % in the body, and as em's throughout</li>
<li>All layout divs that are floated should include display:inline and overflow:hidden</li>
<li> Containers should have overflow:auto and trigger hasLayout via a width or height</li>
<li>Don't use any fancy CSS3 selectors</li>
<li>Don't use transparent PNG's unless you have loaded the alpha</li>
</ul>
<h2>Element Inconsistencies</h2>
<p>Every browser renders particular elements differently - different amounts of padding, margins, borders etc. This means your site can look different in every browser if you use default styles.</p>
<p><strong>Solution</strong></p>
<p>The first thing you should do, which most people most likely know about, is to reset your styles. A reset is some css you place at the start of your styles that removes the padding, margin, border and other inconsistencies from elements, and rebuilds them in a standard way.</p>
<p>Download Eric Meyer's <a href="http://meyerweb.com/eric/thoughts/2008/01/15/resetting-again/">reset.css</a> and place the code at the start of your styles. Bam! Clean, cross browser styles.</p>
<h2>Image Rendering</h2>
<p>IE6 and IE7 both render resized images extremely badly. When you change the size of an image with CSS or in the HTML, it appears blocky and edgy.<br />
<strong>Solution</strong></p>
<p>Don't do it. Always size your images to your desired size before you use them on your site</p>
<h2>Font Rendering</h2>
<p>I told you not all issues were with IE. Safari 3+ has an issue with the way it renders light type on a dark background. Some would argue whether this is good or bad, but there's a way to make it appear lighter. Here's an example of standard white on black text rendering in Safari 3.1:</p>
<p><img class="alignnone size-full wp-image-38" style="border: 1px solid black; padding: 3px;" title="safari-before" src="http://blog.another-d-mention.ro/wp-content/uploads/2009/02/safari-before.png" alt="safari before How To   get Cross Browser Compatibility Every Time" width="351" height="165" /></p>
<p><strong>Solution</strong><br />
Easy fix. You need to add this to your code.</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">p <span style="color: #00AA00;">&#123;</span>
   <span style="color: #000000; font-weight: bold;">text-shadow</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#000</span> <span style="color: #cc66cc;">0</span> <span style="color: #cc66cc;">0</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>Where #000 is your background colour. You will probably have to be more specific with the elements you select. I wouldn't suggest using this fix on the body tag. Other elements you might need to fix are the li, dt, dd, blockquote etc. Use this on any text element you want to appear 'thinner'</p>
<p>To make this fix in Firefox, you use the opacity fix:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">p <span style="color: #00AA00;">&#123;</span>
    -moz-opacity<span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0.99</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>You need to be careful with this fix, as it will break any Flash element that it touches in Firefox. There appears to be no workaround for it.</p>
<p>The type will now be rendered like this:</p>
<p><img class="alignnone size-full wp-image-46" style="border: 1px solid black; padding: 3px;" title="safari-after" src="http://blog.another-d-mention.ro/wp-content/uploads/2009/02/safari-after.png" alt="safari after How To   get Cross Browser Compatibility Every Time" width="336" height="157" /></p>
<h2>Font Selection</h2>
<p>There are common web fonts that we use - Arial, Georgia, Verdana etc. But there are some fonts that are common to both PC and Mac and can be used - Century Gothic, Arial Narrow etc. However, different browsers and OS's render type different, and you need to be aware of these differences, as your site could look dam ugly if you use the wrong font.</p>
<p><strong>Solution</strong></p>
<p>The font you choose is ultimately up to you. As long as it's a safe font you will be fine. However you should be aware of these rendering issues. One font you should probably not use is Lucida Grande/Sans. It renders awful in IE. Take a look at its rendering in Safari(Mac):</p>
<p><img class="alignnone size-full wp-image-47" style="border: 1px solid black; padding: 3px;" title="safari-lucida" src="http://blog.another-d-mention.ro/wp-content/uploads/2009/02/safari-lucida.png" alt="safari lucida How To   get Cross Browser Compatibility Every Time" width="600" height="120" /></p>
<p>Looks nice doesn't it? Too bad it looks like this in Internet Explorer(PC):</p>
<p><img class="alignnone size-full wp-image-48" style="border: 1px solid black; padding: 3px;" title="ie6-lucida" src="http://blog.another-d-mention.ro/wp-content/uploads/2009/02/ie6-lucida.png" alt="ie6 lucida How To   get Cross Browser Compatibility Every Time" width="600" height="120" /></p>
<p>Some people have stated that Lucida Sans will look fine in IE with ClearType, and others have said that it still looks bad. A smart alternative is to just not use Lucida Sans as your 'fallback font', and instead use Arial or another san-serif font.</p>
<h2>Font Sizing</h2>
<p>The ability to resize text differs amongst browsers and OS's. IE won't resize text thats set in pixels. If we set all text in em's, IE will exaggerate the text sizes when resized.</p>
<p><strong>Solution</strong></p>
<p>The best reference for font sizing is the article <a href="http://www.alistapart.com/articles/howtosizetextincss">How to Size Type in CSS</a> by Richard Rutter. The results - You need to specify the size as a percentage in the body element, and then size it in em's through the rest of the sheet. For line height, you need to define it in em's, rather than pixels, for consistent rendering.<br />
One thing to remember is that the default font size is 16px. So to resize our type to 12px we use:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">body <span style="color: #00AA00;">&#123;</span>
   <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span> <span style="color: #933;"><span style="color: #cc66cc;">75</span>%</span><span style="color: #00AA00;">;</span>
   <span style="color: #000000; font-weight: bold;">line-height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1.5em</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>Now you can size your type in em's like so:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">h1<span style="color: #00AA00;">&#123;</span>
   <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span> <span style="color: #933;">3em</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>Another suggested technique is to resize it down to 10px, which makes it easier to size upwards in em's. For example.</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">body <span style="color: #00AA00;">&#123;</span>
     <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span> <span style="color: #933;"><span style="color: #cc66cc;">62.5</span>%</span><span style="color: #00AA00;">;</span>
     <span style="color: #000000; font-weight: bold;">line-height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1.5em</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
h1 <span style="color: #00AA00;">&#123;</span>
      <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1.8em</span><span style="color: #00AA00;">;</span> <span style="color: #808080; font-style: italic;">/* 18px */</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
p <span style="color: #00AA00;">&#123;</span>
      <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1.2em</span><span style="color: #00AA00;">;</span> <span style="color: #808080; font-style: italic;">/* 12px */</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>here is an issue with this however, if people use small font option in Internet Explorer, it could be so small that it's unreadable. It's only a small chance. But worth noting.</p>
<h2>Double Margins on Floats</h2>
<p>We create CSS layouts by floating div's up against each other, like some form of horizontal tetris. When it reaches the end of a row, it drops down to the next. The common method for creating a grid is this:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#content</span> <span style="color: #00AA00;">&#123;</span>
     <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">right</span><span style="color: #00AA00;">;</span>
     <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">300px</span><span style="color: #00AA00;">;</span>
     <span style="color: #000000; font-weight: bold;">margin-right</span><span style="color: #00AA00;">:</span> <span style="color: #933;">10px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #cc00cc;">#sidebar</span> <span style="color: #00AA00;">&#123;</span>
     <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">right</span><span style="color: #00AA00;">;</span>
     <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">100px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>This is what it should look like in a browser:</p>
<p><img class="alignnone size-medium wp-image-58" style="border: 1px solid black; padding: 3px;" title="doublemargin-ff" src="http://blog.another-d-mention.ro/wp-content/uploads/2009/02/doublemargin-ff-300x264.png" alt="doublemargin ff 300x264 How To   get Cross Browser Compatibility Every Time" width="300" height="264" /></p>
<p>This is what IE does to it:</p>
<p><img class="alignnone size-full wp-image-59" style="border: 1px solid black; padding: 3px;" title="doublemargin-ie" src="http://blog.another-d-mention.ro/wp-content/uploads/2009/02/doublemargin-ie.png" alt="doublemargin ie How To   get Cross Browser Compatibility Every Time" width="400" height="353" /></p>
<p>The margin width is doubled. Any margin that is on the same side as the float will be doubled. Don't ask why. It's just IE. This means the element on the left will have that margin stretched out to 20px, which will probably break the layout.</p>
<p><strong>Solution</strong></p>
<p>To fix it, all you need to do is put display:inline on your layout divs.</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#content</span> <span style="color: #00AA00;">&#123;</span>
     <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">right</span><span style="color: #00AA00;">;</span>
     <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">300px</span><span style="color: #00AA00;">;</span>
     <span style="color: #000000; font-weight: bold;">margin-right</span><span style="color: #00AA00;">:</span> <span style="color: #933;">10px</span><span style="color: #00AA00;">;</span>
     <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">inline</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #cc00cc;">#sidebar</span> <span style="color: #00AA00;">&#123;</span>
     <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">right</span><span style="color: #00AA00;">;</span>
     <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">100px</span><span style="color: #00AA00;">;</span>
     <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">inline</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>Now that margin bug is all fixed. Even though it only effects margins on the same side as the float, it can still be useful to include this fix. You never know when you might use a margin on the float side. It won't effect any other browser, so you can use it safely.</p>
<h2>Expanding Box</h2>
<p>The expanding box problem is a big issue with many css layouts. When you have a standard layout, with floats sitting next to each other, with set widths, but an image or long string of text is longer than this width, the layout will break in IE6. Take a look at this example:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#content</span> <span style="color: #00AA00;">&#123;</span>
     <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span>
     <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">300px</span><span style="color: #00AA00;">;</span>
     <span style="color: #000000; font-weight: bold;">margin-right</span><span style="color: #00AA00;">:</span> <span style="color: #933;">10px</span><span style="color: #00AA00;">;</span>
     <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">inline</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #cc00cc;">#sidebar</span> <span style="color: #00AA00;">&#123;</span>
     <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span>
     <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">100px</span><span style="color: #00AA00;">;</span>
     <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">inline</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>This will render like in this most browsers:</p>
<p><img class="alignnone size-full wp-image-63" style="border: 1px solid black; padding: 3px;" title="expandingbox" src="http://blog.another-d-mention.ro/wp-content/uploads/2009/02/expandingbox.png" alt="expandingbox How To   get Cross Browser Compatibility Every Time" width="400" height="353" /></p>
<p>However, in IE6, it will break like so:</p>
<p><img class="alignnone size-full wp-image-64" style="border: 1px solid black; padding: 3px;" title="expandingbox-ie" src="http://blog.another-d-mention.ro/wp-content/uploads/2009/02/expandingbox-ie.png" alt="expandingbox ie How To   get Cross Browser Compatibility Every Time" width="400" height="353" /></p>
<p><strong>Solution</strong></p>
<p>The solution is to use the overflow property. If you place overflow:hidden; into the layout divs, the layout won't break in IE6.</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#content</span> <span style="color: #00AA00;">&#123;</span>
     <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span>
     <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">300px</span><span style="color: #00AA00;">;</span>
     <span style="color: #000000; font-weight: bold;">margin-right</span><span style="color: #00AA00;">:</span> <span style="color: #933;">10px</span><span style="color: #00AA00;">;</span>
     <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">inline</span><span style="color: #00AA00;">;</span>
     <span style="color: #000000; font-weight: bold;">overflow</span><span style="color: #00AA00;">:</span><span style="color: #993333;">hidden</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #cc00cc;">#sidebar</span> <span style="color: #00AA00;">&#123;</span>
     <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span>
     <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">100px</span><span style="color: #00AA00;">;</span>
     <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">inline</span><span style="color: #00AA00;">;</span>
     <span style="color: #000000; font-weight: bold;">overflow</span><span style="color: #00AA00;">:</span><span style="color: #993333;">hidden</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>This could, however, cause some issues with layouts depending on how complex they are. It also won't cause the text to wrap, and it will just remain hidden. It's unlikely you'll have a string long enough to break a layout, but it could happen. Another option is to use word-wrap: break-word; in an IE specific stylesheet. This won't effect images though, so you'll have to make a choice about with method is appropriate for your situation.</p>
<h2>Clearing Floats</h2>
<p>What we mean when we talk about clearing floats, is when a container or wrapper div doesn't correctly wrap around the containing divs. Take a look at this example:</p>
<p><img class="alignnone size-full wp-image-66" style="border: 1px solid black; padding: 3px;" title="clearing" src="http://blog.another-d-mention.ro/wp-content/uploads/2009/02/clearing.png" alt="clearing How To   get Cross Browser Compatibility Every Time" width="400" height="353" /></p>
<p>See how the container is correctly containing the div's? This is what should happen. However, sometimes it does not clear correctly, like so:</p>
<p><img class="alignnone size-full wp-image-67" style="border: 1px solid black; padding: 3px;" title="noclearing" src="http://blog.another-d-mention.ro/wp-content/uploads/2009/02/noclearing.png" alt="noclearing How To   get Cross Browser Compatibility Every Time" width="400" height="353" /></p>
<p>The container isn't correctly wrapping around it. You probably won't notice this until you try and put a background on your container.</p>
<p><strong>Solution</strong></p>
<p>There are a few different solutions for clearing. The best solution however, is a simple <strong>overflow:auto</strong> or <strong>overflow:hidden</strong> in your container</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#container</span> <span style="color: #00AA00;">&#123;</span>
     <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">966px</span><span style="color: #00AA00;">;</span>
     <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span> <span style="color: #993333;">auto</span><span style="color: #00AA00;">;</span>
     <span style="color: #000000; font-weight: bold;">overflow</span><span style="color: #00AA00;">:</span><span style="color: #993333;">auto</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>You need to keep in mind that overflow:auto might cause some issues in Firefox. If you do have any issues, use overflow:hidden instead. If this is still causing issues, take a look at <a href="http://www.sitepoint.com/blogs/2005/02/26/simple-clearing-of-floats/">some other forms of clearing floats</a>. Apart from just adding this, you'll need to make sure hasLayout is triggered in IE6. You can do this by specifying a width or height. If you don't have a width in your container, you can use height:1% to trigger it, or zoom:1; if you can't afford to give it a height.</p>
<h2>CSS Selectors</h2>
<p>Although we would like to use all the brand spanking new CSS3 selectors, IE6 doesn't support all of the major ones. There are also still some CSS2 child and sibling selectors you simply shouldn't use if you want to support IE6:</p>
<ul>
<li>E &gt; F</li>
<li>E + F</li>
<li>E ~ F</li>
<li>:root</li>
<li>:last-child</li>
<li> <img src='http://blog.another-d-mention.ro/wp-includes/images/smilies/icon_surprised.gif' alt=':o' class='wp-smiley' title="How To   get Cross Browser Compatibility Every Time" /> nly-child</li>
<li>:nth-child()</li>
<li>:nth-last-child()</li>
<li>:first-of-type</li>
<li>:last-of-type</li>
<li> <img src='http://blog.another-d-mention.ro/wp-includes/images/smilies/icon_surprised.gif' alt=':o' class='wp-smiley' title="How To   get Cross Browser Compatibility Every Time" /> nly-of-type</li>
<li>:nth-of-type()</li>
<li>:nth-last-of-type()</li>
<li>:empty</li>
<li>:not()</li>
<li>:target</li>
<li>:enable</li>
<li>:disabled</li>
<li>:checked</li>
<li>Any of the E[attribute] Selectors</li>
<li>:first-child</li>
<li>:lang()</li>
<li>:before</li>
<li>::before</li>
<li>:after</li>
<li>::after</li>
</ul>
<p>f course, a lot of these selectors aren't supported by even Firefox 3. For a full list of supported selectors, check out evotech.net's post on <a href="http://www.evotech.net/blog/2008/05/browser-css-selector-support/">browser css selector support</a></p>
<p><strong>Solution</strong></p>
<p>Stick to your standard selectors. Nothing fancy. Only use E + F, E &gt; F, E ~ F when it won't make a huge difference in IE. If you really need to use these selectors, you should look at using IE8.js which gives IE6 better selector support. However this will slow down your site. But we don't really care about IE6 users do we?</p>
<h2>PNG Transparency</h2>
<p>IE6 doesn't support alpha transparency in PNG's. This is possibly the most annoying bug/issue with IE.</p>
<p><strong>Solution</strong></p>
<p>There are a few solutions for this problem. You can either use AlphaImageLoader in an IE specific stylesheet, link to a behaviour file in an IE specific stylesheet or use JS to fix the issue. Not matter which way you choose, there is no way to have transparent repeating background images.<br />
To use AlphaImageLoader, it's a little bit tricky. Add these properties to any png image you want to have transparency. (You need to put this code in an IE specific stylesheet if you want your CSS to validate)</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #6666ff;">.trans</span> <span style="color: #00AA00;">&#123;</span>
     <span style="color: #000000; font-weight: bold;">background-image</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
     filter<span style="color: #00AA00;">:</span> progid<span style="color: #3333ff;">:DXImageTransform</span><span style="color: #6666ff;">.Microsoft</span>.AlphaImageLoader<span style="color: #00AA00;">&#40;</span>src<span style="color: #00AA00;">=</span><span style="color: #ff0000;">'/images/transparent.png'</span><span style="color: #00AA00;">,</span> sizingMethod<span style="color: #00AA00;">=</span><span style="color: #ff0000;">'image/scale/crop'</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>Let's say you've given all your png image tags a class "trans", you select them with your css and use the filter property. You need to create a 1x1 transparent png file and link to it in the src attribute.</p>
<p>An even better way to do this is via a behaviour. It's similar to the AlphaImageLoader, except that you link to a behaviour script that triggers the transparency.</p>
<p>The third method is to use IE8.js which I mentioned earlier. It's even safer than the previous method, and you are very unlikely to run into any problems. Link to the script in your HTML, and it will make any png ending in -trans alpha-capable. eg. myimage-trans.png.</p>
<p><strong>With all this methods, you need to be aware that you might still run into problems with transparent pngs. Make sure you test it in IE6 extensively</strong></p>


<p>Related posts:<ol><li><a href='http://blog.another-d-mention.ro/programming/cross-browser-inline-block/' rel='bookmark' title='Permanent Link: Cross browser inline-block'>Cross browser inline-block</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.another-d-mention.ro/programming/css/how-to-get-cross-browser-compatibility-every-time/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
