<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html
  PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
	<head>
		<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
		<link rel="stylesheet" type="text/css" href="content.css" />
		<title>
			Optimizing ActionScript for Flash Lite content on mobile devices
		</title>
<!-- Changed by: , 21-Mar-2006 -->
<script src="help.js" type="text/javascript" language="Javascript" charset="UTF-8">...</script> 
		
		
<script type="text/javascript">
<!--[CDATA[
handleContext(1);
if (use_ie_6_behavior) {
  document.write("<link rel=\"stylesheet\" type=\"text/css\" href=\"content-ie6.css\" />");
}
// ]]-->
</script> 
		
<script src="scripts.js" type="text/javascript" language="Javascript" charset="UTF-8">...</script> <script src="terms.js" type="text/javascript" language="Javascript" charset="UTF-8">...</script> 
	</head>
	<body id="content_body">
<!--googleoff: index-->
<!-- BEGIN PAGE CONTENT WRAPPER -->
		<div id="pneumonic">
			<h1 class="DeviceCentral">DeviceCentral</h1>
		</div>
		<div id="page_content_wrapper">
			<p class="sharedproducts">TOPIC APPEARS IN: </p><p class="sharedproductindicators"><img src="images/flashSharedIndicator.png" title="Flash" /></p>
<!-- BEGIN BREADCRUMBS -->
			<div id="breadcrumb">
<!-- BEGIN BREADCRUMBS -->
				
<div class="nav"><dl class="page"><dd class="prev"><a accesskey="p" class="prev" href="WS139D2B99-B13E-485e-8ED0-E9E2572A00BC.html" title="Optimizing Flash Lite frames for mobile devices"><img src="images/prev.gif" alt="Previous" /></a></dd><dd class="next"><a accesskey="n" class="next" href="WS4BC3BE1E-4574-4f96-BB90-23BFC3108D34.html" title="Managing Flash Lite file memory for mobile devices"><img src="images/next.gif" alt="Next" /></a></dd></dl></div><div class="hierarchy"><a href="WS28F6F81C-55B3-4ad5-B632-171637249F5B.html">Create, preview, and test content in Adobe Device Central</a> /
     <a href="WS3A29C98D-5768-45ea-AB2F-75FAF64078EE.html"><b>Tips for creating content for mobile devices</b></a> 
     </div>

<!-- END BREADCRUMBS -->
			</div>
<!-- END BREADCRUMBS -->
<!-- BEGIN PAGE TITLE -->
<!--googleon: index-->
			<h1>
				Optimizing ActionScript for Flash Lite content on mobile devices
			</h1>
<!--googleoff: index-->
<!-- END PAGE TITLE -->
<!-- BEGIN CONTENT WRAPPER -->
			<div id="content_wrapper">
<!--googleon: index-->
				<div><p>
                        
                        
                        Because
of the processing speed and memory limitations on most mobile devices,
follow these guidelines when developing ActionScript for Flash Lite content
used on mobile devices:</p>
<div class="p">
                        <ul><li>
                              <p>Keep the file and its code as simple as possible.
Remove unused movie clips, delete unnecessary frame and code loops,
and avoid too many frames or extraneous frames.</p>

                           </li>
<li>
                              <p>Using <samp class="codeph">FOR</samp> loops can be expensive because
of the overhead incurred while the condition is checked with each
iteration. When the costs of the iteration and the loop overhead
are comparable, execute multiple operations individually instead
of using a loop. The code may be longer, but performance will improve.</p>

                           </li>
<li>
                              <p>Stop frame-based looping as soon as it is no longer needed.</p>

                           </li>
<li>
                              <p>When possible, avoid string and array processing because
it can be CPU-intensive.</p>

                           </li>
<li>
                              <p>Always try to access properties directly rather than using
ActionScript getter and setter methods, which have more overhead
than other method calls.</p>

                           </li>
<li>
                              <p>Manage events wisely. Keep event listener arrays compact
by using conditions to check whether a listener exists (is not <samp class="codeph">null</samp>)
before calling it. Clear any active intervals by calling <samp class="codeph">clearInterval</samp>,
and remove any active listeners by calling <samp class="codeph">removeListener</samp> before
removing content using <samp class="codeph">unloadapplication</samp> or <samp class="codeph">removeapplicationClip</samp>.
Flash does not re-collect SWF data memory (for example, from intervals
and listeners) if any ActionScript functions are still referring
to the SWF data when a movie clip is unloaded. </p>

                           </li>
<li>
                              <p>When variables are no longer needed, delete them or set them
to <samp class="codeph">null</samp>, which marks them for garbage collection.
Deleting variables helps optimize memory use during run time, because
unneeded assets are removed from the SWF file. It is better to delete
variables than to set them to <samp class="codeph">null</samp>.</p>

                           </li>
<li>
                              <p>Explicitly remove listeners from objects by calling <samp class="codeph">removeListener</samp> before
garbage collection.</p>

                           </li>
<li>
                              <p>If a function is being called dynamically and passing a fixed
set of parameters, use <samp class="codeph">call</samp> instead of <samp class="codeph">apply</samp>.</p>

                           </li>
<li>
                              <p>Make namespaces (such as paths) more compact to reduce startup
time. Every level in the package is compiled to an <samp class="codeph">IF</samp> statement
and causes a new <samp class="codeph">Object </samp>call, so having fewer levels
in the path saves time. For example, a path with the levels <samp class="codeph">com.xxx.yyy.aaa.bbb.ccc.funtionName</samp> causes
an object to be instantiated for <samp class="codeph">com.xxx.yyy.aaa.bbb.ccc</samp>.
Some Flash developers use preprocessor software to reduce the path
to a unique identifier, such as <samp class="codeph">58923409876.functionName</samp>,
before compiling the SWF code.</p>

                           </li>
<li>
                              <p>If a file consists of multiple SWF files that use the same
ActionScript classes, exclude those classes from select SWF files
during compilation. This can help reduce file download time and
run‑time memory requirements.</p>

                           </li>
<li>
                              <p>Avoid using <samp class="codeph">Object.watch</samp> and <samp class="codeph">Object.unwatch</samp>,
because every change to an object property requires the player to
determine whether a change notification must be sent. </p>

                           </li>
<li>
                              <p>If ActionScript code that executes on a keyframe in the timeline
requires more than 1 second to complete, consider splitting up that
code to execute over multiple keyframes. </p>

                           </li>
<li>
                              <p>Remove <samp class="codeph">trace</samp> statements from the code when
publishing the SWF file. To do this, select the Omit Trace Actions
check box on the Flash tab in the Publish Settings dialog box. </p>

                           </li>
<li>
                              <p>Inheritance increases the number of method calls and uses
more memory: a class that includes all the functionality it needs
is more efficient at run time than a class that inherits some of
its functionality from a superclass. Therefore, you may need to
make a design trade‑off between extensibility of classes and efficiency
of code.</p>

                           </li>
<li>
                              <p>When one SWF file loads another SWF file that contains a
custom ActionScript class (for example, <samp class="codeph">foo.bar.CustomClass</samp>)
and then unloads the SWF file, the class definition remains in memory.
To save memory, explicitly delete any custom classes in unloaded
SWF files. Use the <samp class="codeph">delete</samp> statement and specify
the fully qualified class name, such as: <samp class="codeph">delete foo.bar.CustomClass.</samp>
                              </p>

                           </li>
<li>
                              <p>Limit the use of global variables, because they are not marked
for garbage collection if the movie clip that defined them is removed.</p>

                           </li>
<li>
                              <p>Avoid using the standard user interface components (available
in the Components panel in Flash). These components are designed
to run on desktop computers and are not optimized to run on mobile
devices.</p>

                           </li>
<li>
                              <p>Whenever possible, avoid deeply nested functions.</p>

                           </li>
<li>
                              <p>Avoid referencing nonexistent variables, objects, or functions.
Compared to the desktop version of Flash Player, Flash Lite 2 looks
up references to nonexistent variables slowly, which can significantly
affect performance.</p>

                           </li>
<li>
                              <p>Avoid defining functions using anonymous syntax. For example, <samp class="codeph">myObj.eventName =
function{ ...}</samp>. Explicitly defined functions are more efficient,
such as <samp class="codeph">function myFunc { ...}; my Obj.eventName = myFunc;</samp>.</p>

                           </li>
<li>
                              <p>Minimize the use of Math functions and floating-point numbers.
Calculating these values slows performance. If you must use the
Math routines, consider precalculating the values and storing them
in an array of variables. Retrieving the values from a data table
is much faster than having Flash calculate them at run time.</p>

                           </li>
</ul>

                     </div>
</div>

<!--googleoff: index-->
			</div>
<!-- END CONTENT WRAPPER -->
		</div>
<!-- END PAGE CONTENT WRAPPER -->
		<br clear="both" />
		<div id="related">
			<div class="t">
				<div class="b">
					<div class="l">
						<div class="r">
							<div class="bl">
								<div class="br">
									<div class="tl">
										<div class="tr">
											<div id="related_in">
												<h3>
<script type="text/javascript">document.write(terms_Related_Information);</script> 
												</h3>
												
												<h4>
<script type="text/javascript">document.write(terms_AHV_HELP_RESOURCE_CENTER);</script> 
												</h4>
												<ul class="link-list"><li class="icon external"><a target="_blank" title="This page on the Web" href="http://help.adobe.com/en_US/DeviceCentral/1.0/WSD7F8E1A9-680A-4000-9BA9-D7B01FDD7ECD.html">This page on the Web</a></li></ul>
												
											</div>
											<br clear="both" />
										</div>
									</div>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
		<br clear="both" />
	</body>
</html>