<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-31054059</id><updated>2011-04-21T19:33:51.327-07:00</updated><title type='text'>Learning UJML</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://ujml.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/31054059/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://ujml.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Lauren Smith</name><uri>http://www.blogger.com/profile/01523158891010339130</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://photos1.blogger.com/img/158/8299/320/050923_003L1.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>14</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-31054059.post-6468273158002504358</id><published>2007-06-06T22:03:00.000-07:00</published><updated>2007-06-06T22:18:27.490-07:00</updated><title type='text'>Animation 1: Moving stuff around</title><content type='html'>Animation 1: Moving stuff around&lt;br /&gt;&lt;br /&gt;There are two basic kinds of animation techniques that UJML allows. The first, which I will cover in this lesson, is sliding/moving. The other kind is strip animation (like animated gifs).&lt;br /&gt;&lt;br /&gt;Sliding or moving an image on the screen is very simple in UJML. It relies on the &amp;lt;delay&amp;gt; tag to pause briefly between painting so that the shown image appears to move smoothly.&lt;br /&gt;&lt;br /&gt;I usually create a boolean state-variable called sTick whose job it is to delay for a few milliseconds, then call a function called step() which calculates the next paint position. The step() function then clears and sets a state variable called sDisplay which paints the image at the updated position.&lt;br /&gt;&lt;br /&gt;Naturally, you should use whatever naming scheme is most comfortable for you.&lt;br /&gt;&lt;br /&gt;Here is a barebones implementation of a moving image. Note that the state variables exist only to display the image or to fire a timer event. The positioning code is contained in the step() function.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;lt;state-variables&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;state-var name="sDisplay" type="boolean"/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;state-var name="sTick" type="boolean"/&amp;gt;&lt;br /&gt;&amp;lt;/state-variables&amp;gt;&lt;br /&gt;&amp;lt;variables&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;var name="mImgX" type="int"/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;var name="mImgY" type="int"/&amp;gt;&lt;br /&gt;&amp;lt;/variables&amp;gt;&lt;br /&gt;&amp;lt;functions&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;function name="step" type="void"&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;script&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;sTick = false;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;// Calculate the next position to display the image&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;mImgX = mImgX + 10;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;mImgY = mImgY + 10;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if (_gt(mImgX, mScrWidth))&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;mImgX = 0;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if (_gt(mImgY, mScrHeight))&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;mImgY = 0;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;_clear_state(sDisplay);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;sDisplay = true;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;sTick = true;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/script&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/function&amp;gt;&lt;br /&gt;&amp;lt;/functions&amp;gt;&lt;br /&gt;&amp;lt;states&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;state var="sDisplay"&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;transition value="true"&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;display&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;image&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;url&amp;gt;&amp;IMGURL;&amp;lt;/url&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;x&amp;gt;&amp;lt;eval&amp;gt;mImgX&amp;lt;/eval&amp;gt;&amp;lt;/x&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;y&amp;gt;&amp;lt;eval&amp;gt;mImgY&amp;lt;/eval&amp;gt;&amp;lt;/y&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;width&amp;gt;&amp;IMGW;&amp;lt;/width&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;height&amp;gt;&amp;IMGH;&amp;lt;/height&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/image&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/display&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/transition&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/state&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;state var="sTick"&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;transition value="true"&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;delay&amp;gt;33&amp;lt;/delay&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;script&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;step();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/script&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/transition&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/state&amp;gt;&lt;br /&gt;&amp;lt;/states&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;A common twist on this is to determine the "slide distance" and the "slide duration" of the movement, then use the timer to move some percentage of the way towards the end point of the slide. You will see this commonly in menus where a button press will cause the sliding menu to be shown and clicking an item in the menu will cause the menu to slide off the screen (or to a docking position).&lt;br /&gt;&lt;br /&gt;In order to do this, you must remember the time you started the movement in order to determine what percentage of "slide distance" you need to move.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;lt;variables&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;var name="mSlideStart" type="int"/&amp;gt;&lt;br /&gt;&amp;lt;/variables&amp;gt;&lt;br /&gt;&amp;lt;functions&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;function name="startSlide" type="void"&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;script&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;mSlideStart = _msec(); // save the starting time&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;step();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/script&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/function&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;function name="step" type="void"&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;variables&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;var name="timedelta" type="int"/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/variables&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;script&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;sTick = false;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;_clear_state(sDisplay);&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;timedelta = mSlideStart - _msec();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if (_gte(timedelta, &amp;SLIDETIME;))&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;// The slide has completed&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;mImgX = &amp;IMGPOSX;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;mImgY = &amp;IMGPOSY;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;sDisplay = true;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;else&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;// The slide is only partially through&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;// Get the fractional amount to move&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;mImgX = &amp;IMGPOSX; * timedelta / &amp;SLIDETIME;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;mImgY = &amp;IMGPOSY; * timedelta / &amp;SLIDETIME;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;sDisplay = true;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;sTick = true; // do another tick until &amp;SLIDETIME is reached&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/script&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/function&amp;gt;&lt;br /&gt;&amp;lt;/functions&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;In this example, the program now has a function called startSlide() which is used to begin the sliding process. While the elapsed time is less than the total sliding time, the step() function calculates the distance to move based on the elapsed time and the total distance to move. If the elapsed time has not reached the total time, the sTick timer is set to fire another event later. Once the elapsed time has passed the expected total time, the image is placed at its final position and displayed. The timer is not set again (until the user calls startSlide() again).&lt;br /&gt;&lt;br /&gt;Other improvements can be made to this sliding technique. Using a logarithmic sliding distance is a clever way to simulate accelerating objects. Likewise, a callback function signalling the "slide end" can be created to allow the sliding item a way to notify the user that it has completed its slide. Inverting the sign of the slide distance can be used to reverse a slide (very useful for hiding a menu).&lt;br /&gt;&lt;br /&gt;In all, this is a very simple technique based solely on painting, moving, and delaying. All animation in UJML is based on this technique.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31054059-6468273158002504358?l=ujml.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ujml.blogspot.com/feeds/6468273158002504358/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=31054059&amp;postID=6468273158002504358' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/31054059/posts/default/6468273158002504358'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/31054059/posts/default/6468273158002504358'/><link rel='alternate' type='text/html' href='http://ujml.blogspot.com/2007/06/animation-1-moving-stuff-around.html' title='Animation 1: Moving stuff around'/><author><name>Lauren Smith</name><uri>http://www.blogger.com/profile/01523158891010339130</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://photos1.blogger.com/img/158/8299/320/050923_003L1.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-31054059.post-6758379826663450437</id><published>2007-05-31T01:07:00.000-07:00</published><updated>2007-05-31T01:13:22.471-07:00</updated><title type='text'>Mea Culpa: _run is not _link</title><content type='html'>I mentioned in &lt;a href="http://ujml.blogspot.com/2007/03/lesson-7-loading-and-unloading.html"&gt;Lesson 7&lt;/a&gt; that the _run() API is essentially identical to the _link() API. That is incorrect.&lt;br /&gt;&lt;br /&gt;When an application is _run(), it pushes the current application down the application stack and disables it. The _run() application is then loaded and executed.&lt;br /&gt;&lt;br /&gt;When an application is _link(), it becomes part of the currently running application.&lt;br /&gt;&lt;br /&gt;The difference between these two is that all functions of the previous application are disabled when a subprogram is _run(). A _link()ed partition is loaded into memory as part of the current application, so all features of the current application are still enabled.&lt;br /&gt;&lt;br /&gt;The _replace() API falls into the same category as _run() in that it disables the currently running application. The difference is that when the _run() application completes, the "pushed" application is re-activated (from initialization, not from where it left off). A _replace()ed application is pushed out of the application stack forever.&lt;br /&gt;&lt;br /&gt;Sorry for the bad information.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31054059-6758379826663450437?l=ujml.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ujml.blogspot.com/feeds/6758379826663450437/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=31054059&amp;postID=6758379826663450437' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/31054059/posts/default/6758379826663450437'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/31054059/posts/default/6758379826663450437'/><link rel='alternate' type='text/html' href='http://ujml.blogspot.com/2007/05/mea-culpa-run-is-not-link.html' title='Mea Culpa: _run is not _link'/><author><name>Lauren Smith</name><uri>http://www.blogger.com/profile/01523158891010339130</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://photos1.blogger.com/img/158/8299/320/050923_003L1.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-31054059.post-5159314004458627254</id><published>2007-05-31T01:06:00.001-07:00</published><updated>2007-05-31T01:06:36.893-07:00</updated><title type='text'>Adjustable User Interface</title><content type='html'>Once you start working with UJML and targetting various devices, one thing becomes abundantly clear: Screen sizes are never the same. The screen size may be VGA (640x480), but most likely you won't be able to use the entire screen. What matters to you, the application developer, is not the total screen size, but the "usable screen size". This is the screen area that can be updated by the program.&lt;br /&gt;&lt;br /&gt;In order to determine the screen size, UJML provides the API _getIntProperty(). This API takes an integer parameter defined in the DTD file and returns the appropriate information from the system. The two parameters that concern screen size are _PROPERTY_INT_SCREEN_WIDTH and _PROPERTY_INT_SCREEN_HEIGHT. By passing these parameters to _getIntProperty, we can retrieve the width and height of the usable screen area.&lt;br /&gt;&lt;br /&gt;This code is boilerplate for the vast majority of applications:&lt;br /&gt;&lt;br /&gt;mScrWidth = _getIntProperty( &amp;_PROPERTY_INT_SCREEN_WIDTH; );&lt;br /&gt;mScrHeight = _getIntProperty( &amp;_PROPERTY_INT_SCREEN_HEIGHT; );&lt;br /&gt;&lt;br /&gt;From this information, positioning objects on the screen is simply a matter of calculating offsets from the top, bottom, left, and right. If you wish to place an object flush to the right-hand side of the screen, you set its &amp;lt;x&amp;gt; parameter to be mScrWidth - objectwidth. Likewise, placing an object relative to the bottom of the screen means setting its &amp;lt;y&amp;gt; parameter to be the object's height subtracted from mScrHeight.&lt;br /&gt;&lt;br /&gt;Knowing this simple concept, it is possible to draw anything, anywhere on the screen (or even off the screen!) However, UJML has some pitfalls which are easily worked around, yet frustrating if you don't realize the problem.&lt;br /&gt;&lt;br /&gt;One of the first applications of screen positioning is the use of percentage offsets. Say you want to fill a certain area of the screen with _COLOR_RED. What you may find is that the area you are trying to paint never appears. The problem is a result of UJML's lack of floating point numbers. You can't say "mScrWidth * 0.42" and expect to get 42% of the screen width. UJML only provides integer arithmetic, so in order to get 42% of the screen width, you must first multiply the screen width by 42, then divide it by 100.&lt;br /&gt;&lt;br /&gt;mPosX = mScrWidth * 42 / 100; // OK&lt;br /&gt;mPosX = mScrWidth / 100 * 42; // NG: this will lose signficant digits&lt;br /&gt;&lt;br /&gt;Keep in mind that integer arithmetic truncates, so don't divide before multiplying!&lt;br /&gt;&lt;br /&gt;Another issue that crops up a lot is overlapping percentages. Since integer arithmetic truncates fractional values, sometimes your calculated areas will overlap each other by a pixel. In most cases, this is not a big deal, but for those of us who don't want our applications looking like they were developed by a sysadmin, it makes sense to be aware of this problem.&lt;br /&gt;&lt;br /&gt;A decent solution is to use offsets based on the values returned by the percentage calculations. While this may have the side effect of moving the pixel problem off to the edge of the screen, those are pixels that not many people notice anyway. Better to have a row or column of black pixels on the edge of the screen than to have uneven display in the middle.&lt;br /&gt;&lt;br /&gt;To implement this, just keep track of where you are positioning items. Then, instead of basing the position of the next item on the x,y origin, base it on the offset from the item immediately adjacent to it.&lt;br /&gt;&lt;br /&gt;mPosX = 0; // this is the first object, based on the x,y origin&lt;br /&gt;mPosW = mScrWidth * 42 / 100;&lt;br /&gt;mPosX2 = mPosX + mPosW; // This is the second object, dynamically positioning itself relative to the first object&lt;br /&gt;&lt;br /&gt;In a nutshell, that's it. Positioning items on the screen is relatively easy, and UJML provides excellent drawing capabilities for the application developer. Since we can't depend on the screen size of our devices to always be the same, it is important that our applications adapt to the screen size we are given.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31054059-5159314004458627254?l=ujml.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ujml.blogspot.com/feeds/5159314004458627254/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=31054059&amp;postID=5159314004458627254' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/31054059/posts/default/5159314004458627254'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/31054059/posts/default/5159314004458627254'/><link rel='alternate' type='text/html' href='http://ujml.blogspot.com/2007/05/adjustable-user-interface.html' title='Adjustable User Interface'/><author><name>Lauren Smith</name><uri>http://www.blogger.com/profile/01523158891010339130</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://photos1.blogger.com/img/158/8299/320/050923_003L1.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-31054059.post-8546963235551382681</id><published>2007-03-06T21:13:00.000-08:00</published><updated>2007-03-06T21:26:07.979-08:00</updated><title type='text'>Lesson 7: Loading and Unloading applications</title><content type='html'>&lt;a href="http://developer.uievolution.com/docs/en/LangRef/Application_Files.html"&gt;UJML applications&lt;/a&gt; can be thought of as residing on a stack. The earliest launched application lives at the lowest stack position and the most recently launched application lives at the top of the stack. This lesson will discuss the methods for launching applications.&lt;br /&gt;&lt;br /&gt;A UJML application is the code between the &lt;application&gt; or &lt;partition&gt; tags in a file with a &lt;span style="font-family: courier new;"&gt;.ujml &lt;/span&gt;extension. The compiler looks for &lt;span style="font-family: courier new;"&gt;*.ujml&lt;/span&gt; to determine the application source files, so every application must conform to those requirements.&lt;br /&gt;&lt;br /&gt;Practically, there is no difference between code contained in an &lt;application&gt;&lt;span style="font-family: courier new;"&gt;&lt;application&gt;&lt;/span&gt; tag and code contained in a &lt;span style="font-family: courier new;"&gt;&lt;partition&gt;&lt;/span&gt;&lt;partition&gt; tag. Conceptually, an &lt;/partition&gt;&lt;/application&gt;&lt;/partition&gt;&lt;/application&gt;&lt;span style="font-family: courier new;"&gt;&lt;application&gt;&lt;/span&gt;&lt;application&gt;&lt;partition&gt;&lt;application&gt;&lt;partition&gt;&lt;application&gt; is a standalone application that is &lt;span style="font-family: courier new;"&gt;_run()&lt;/span&gt; while a &lt;/application&gt;&lt;/partition&gt;&lt;/application&gt;&lt;/partition&gt;&lt;/application&gt;&lt;span style="font-family: courier new;"&gt;&lt;partition&gt;&lt;/span&gt;&lt;application&gt;&lt;partition&gt;&lt;application&gt;&lt;partition&gt;&lt;application&gt;&lt;partition&gt; is a smaller part of a larger application that is &lt;span style="font-family: courier new;"&gt;_link()&lt;/span&gt;ed to the parent application. In practice, there is no difference except in name. As a rule of thumb, I use &lt;/partition&gt;&lt;/application&gt;&lt;/partition&gt;&lt;/application&gt;&lt;/partition&gt;&lt;/application&gt;&lt;span style="font-family: courier new;"&gt;&lt;application&gt;&lt;/span&gt;&lt;application&gt;&lt;partition&gt;&lt;application&gt;&lt;partition&gt;&lt;application&gt;&lt;partition&gt;&lt;application&gt; in my startup application file while I use &lt;partition&gt;&lt;/partition&gt;&lt;/application&gt;&lt;/partition&gt;&lt;/application&gt;&lt;/partition&gt;&lt;/application&gt;&lt;/partition&gt;&lt;/application&gt;&lt;span style="font-family: courier new;"&gt;&lt;partition&gt;&lt;/span&gt;&lt;application&gt;&lt;partition&gt;&lt;application&gt;&lt;partition&gt;&lt;application&gt;&lt;partition&gt;&lt;application&gt;&lt;partition&gt; in all other files.&lt;br /&gt;&lt;br /&gt;There are three ways to &lt;a href="http://developer.uievolution.com/docs/en/LangRef/Running_Files.html"&gt;launch an application&lt;/a&gt; from within another application. The first is the easiest, but affords the least control over the startup parameters. To launch another application, call &lt;a href="http://developer.uievolution.com/docs/en/LangRef/_run().html"&gt;&lt;span style="font-family: courier new;"&gt;_run(appURL)&lt;/span&gt;&lt;/a&gt;. Use the URL to your application as the parameter to this API. When this is called, the launched application takes the top position in the stack and also takes the topmost position in the Z-order.&lt;br /&gt;&lt;br /&gt;Applications that are launched with &lt;span style="font-family: courier new;"&gt;_run()&lt;/span&gt; control their own lifetime. They can exit and return control to the owning application by calling &lt;a href="http://developer.uievolution.com/docs/en/LangRef/_unloadSelf().html"&gt;&lt;span style="font-family: courier new;"&gt;_unloadSelf()&lt;/span&gt;&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;The second type of &lt;a href="http://developer.uievolution.com/docs/en/LangRef/Linking_Files.html"&gt;application activation&lt;/a&gt; is the &lt;a href="http://developer.uievolution.com/docs/en/LangRef/_link().html"&gt;&lt;span style="font-family: courier new;"&gt;_link()&lt;/span&gt;&lt;/a&gt; API. This has two advantages over &lt;span style="font-family: courier new;"&gt;_run()&lt;/span&gt;. First, it provides a way to give a name to the application. This is useful because it means that the launching application can &lt;span style="font-family: courier new;"&gt;_unlink()&lt;/span&gt; the partition explicitly. In the &lt;/partition&gt;&lt;/application&gt;&lt;/partition&gt;&lt;/application&gt;&lt;/partition&gt;&lt;/application&gt;&lt;/partition&gt;&lt;/application&gt;&lt;span style="font-family: courier new;"&gt;_run()&lt;/span&gt;&lt;application&gt;&lt;partition&gt;&lt;application&gt;&lt;partition&gt;&lt;application&gt;&lt;partition&gt;&lt;application&gt;&lt;partition&gt; case, the launching application must wait for the &lt;/partition&gt;&lt;/application&gt;&lt;/partition&gt;&lt;/application&gt;&lt;/partition&gt;&lt;/application&gt;&lt;/partition&gt;&lt;/application&gt;&lt;span style="font-family: courier new;"&gt;_run()&lt;/span&gt;&lt;application&gt;&lt;partition&gt;&lt;application&gt;&lt;partition&gt;&lt;application&gt;&lt;partition&gt;&lt;application&gt;&lt;partition&gt; application to &lt;/partition&gt;&lt;/application&gt;&lt;/partition&gt;&lt;/application&gt;&lt;/partition&gt;&lt;/application&gt;&lt;/partition&gt;&lt;/application&gt;&lt;span style="font-family: courier new;"&gt;_unloadSelf()&lt;/span&gt;&lt;application&gt;&lt;partition&gt;&lt;application&gt;&lt;partition&gt;&lt;application&gt;&lt;partition&gt;&lt;application&gt;&lt;partition&gt; itself. The other benefit is that &lt;/partition&gt;&lt;/application&gt;&lt;/partition&gt;&lt;/application&gt;&lt;/partition&gt;&lt;/application&gt;&lt;/partition&gt;&lt;/application&gt;&lt;span style="font-family: courier new;"&gt;_link()&lt;/span&gt;&lt;application&gt;&lt;partition&gt;&lt;application&gt;&lt;partition&gt;&lt;application&gt;&lt;partition&gt;&lt;application&gt;&lt;partition&gt; allows the launching application to set the Z-order of the &lt;/partition&gt;&lt;/application&gt;&lt;/partition&gt;&lt;/application&gt;&lt;/partition&gt;&lt;/application&gt;&lt;/partition&gt;&lt;/application&gt;&lt;span style="font-family: courier new;"&gt;_link()&lt;/span&gt;&lt;application&gt;&lt;partition&gt;&lt;application&gt;&lt;partition&gt;&lt;application&gt;&lt;partition&gt;&lt;application&gt;&lt;partition&gt;ed partition. Depending on how the whole application is designed, it may be useful to load certain partitions higher or lower in the Z-order. A pop-up screen (like a notification) would need a very high Z-order while a resource loader could use a lower Z-order. Leaving off the Z-order value in the call will cause the application to be loaded above the launching application.&lt;br /&gt;&lt;br /&gt;A &lt;/partition&gt;&lt;/application&gt;&lt;/partition&gt;&lt;/application&gt;&lt;/partition&gt;&lt;/application&gt;&lt;/partition&gt;&lt;/application&gt;&lt;span style="font-family: courier new;"&gt;_link()&lt;/span&gt;&lt;application&gt;&lt;partition&gt;&lt;application&gt;&lt;partition&gt;&lt;application&gt;&lt;partition&gt;&lt;application&gt;&lt;partition&gt;ed partition may call &lt;/partition&gt;&lt;/application&gt;&lt;/partition&gt;&lt;/application&gt;&lt;/partition&gt;&lt;/application&gt;&lt;/partition&gt;&lt;/application&gt;&lt;span style="font-family: courier new;"&gt;_unloadSelf()&lt;/span&gt;&lt;application&gt;&lt;partition&gt;&lt;application&gt;&lt;partition&gt;&lt;application&gt;&lt;partition&gt;&lt;application&gt;&lt;partition&gt; to remove itself from the application stack, but the more typical method is by using the &lt;/partition&gt;&lt;/application&gt;&lt;/partition&gt;&lt;/application&gt;&lt;/partition&gt;&lt;/application&gt;&lt;/partition&gt;&lt;/application&gt;&lt;a href="http://developer.uievolution.com/docs/en/LangRef/_unlink().html"&gt;&lt;span style="font-family: courier new;"&gt;_unlink()&lt;/span&gt;&lt;/a&gt;&lt;application&gt;&lt;partition&gt;&lt;application&gt;&lt;partition&gt;&lt;application&gt;&lt;partition&gt;&lt;application&gt;&lt;partition&gt; API. The string parameter passed to &lt;/partition&gt;&lt;/application&gt;&lt;/partition&gt;&lt;/application&gt;&lt;/partition&gt;&lt;/application&gt;&lt;/partition&gt;&lt;/application&gt;&lt;span style="font-family: courier new;"&gt;_unlink()&lt;/span&gt;&lt;application&gt;&lt;partition&gt;&lt;application&gt;&lt;partition&gt;&lt;application&gt;&lt;partition&gt;&lt;application&gt;&lt;partition&gt; is the name that was passed as the first parameter to &lt;/partition&gt;&lt;/application&gt;&lt;/partition&gt;&lt;/application&gt;&lt;/partition&gt;&lt;/application&gt;&lt;/partition&gt;&lt;/application&gt;&lt;span style="font-family: courier new;"&gt;_link()&lt;/span&gt;&lt;application&gt;&lt;partition&gt;&lt;application&gt;&lt;partition&gt;&lt;application&gt;&lt;partition&gt;&lt;application&gt;&lt;partition&gt;.&lt;br /&gt;&lt;br /&gt;Be careful with the naming, though. If the same partition name is used for than once, the first &lt;/partition&gt;&lt;/application&gt;&lt;/partition&gt;&lt;/application&gt;&lt;/partition&gt;&lt;/application&gt;&lt;/partition&gt;&lt;/application&gt;&lt;span style="font-family: courier new;"&gt;_link()&lt;/span&gt;&lt;application&gt;&lt;partition&gt;&lt;application&gt;&lt;partition&gt;&lt;application&gt;&lt;partition&gt;&lt;application&gt;&lt;partition&gt;ed partition will be automatically &lt;/partition&gt;&lt;/application&gt;&lt;/partition&gt;&lt;/application&gt;&lt;/partition&gt;&lt;/application&gt;&lt;/partition&gt;&lt;/application&gt;&lt;span style="font-family: courier new;"&gt;_unlink()&lt;/span&gt;&lt;application&gt;&lt;partition&gt;&lt;application&gt;&lt;partition&gt;&lt;application&gt;&lt;partition&gt;&lt;application&gt;&lt;partition&gt;ed to make room for the next partition.&lt;br /&gt;&lt;br /&gt;The third type of application launch is &lt;a href="http://developer.uievolution.com/docs/en/LangRef/_replace().html"&gt;_replace()&lt;/a&gt;. This is a relatively minor API compared to &lt;/partition&gt;&lt;/application&gt;&lt;/partition&gt;&lt;/application&gt;&lt;/partition&gt;&lt;/application&gt;&lt;/partition&gt;&lt;/application&gt;&lt;span style="font-family: courier new;"&gt;_link()&lt;/span&gt;&lt;application&gt;&lt;partition&gt;&lt;application&gt;&lt;partition&gt;&lt;application&gt;&lt;partition&gt;&lt;application&gt;&lt;partition&gt; or &lt;/partition&gt;&lt;/application&gt;&lt;/partition&gt;&lt;/application&gt;&lt;/partition&gt;&lt;/application&gt;&lt;/partition&gt;&lt;/application&gt;&lt;span style="font-family: courier new;"&gt;_run()&lt;/span&gt;&lt;application&gt;&lt;partition&gt;&lt;application&gt;&lt;partition&gt;&lt;application&gt;&lt;partition&gt;&lt;application&gt;&lt;partition&gt;. It has most of the same characteristics of &lt;/partition&gt;&lt;/application&gt;&lt;/partition&gt;&lt;/application&gt;&lt;/partition&gt;&lt;/application&gt;&lt;/partition&gt;&lt;/application&gt;&lt;span style="font-family: courier new;"&gt;_run()&lt;/span&gt;&lt;application&gt;&lt;partition&gt;&lt;application&gt;&lt;partition&gt;&lt;application&gt;&lt;partition&gt;&lt;application&gt;&lt;partition&gt;, but instead of loading the application at the next open stack position, it implicitly &lt;/partition&gt;&lt;/application&gt;&lt;/partition&gt;&lt;/application&gt;&lt;/partition&gt;&lt;/application&gt;&lt;/partition&gt;&lt;/application&gt;&lt;span style="font-family: courier new;"&gt;_unlink()&lt;/span&gt;&lt;application&gt;&lt;partition&gt;&lt;application&gt;&lt;partition&gt;&lt;application&gt;&lt;partition&gt;&lt;application&gt;&lt;partition&gt;s the current application and &lt;/partition&gt;&lt;/application&gt;&lt;/partition&gt;&lt;/application&gt;&lt;/partition&gt;&lt;/application&gt;&lt;/partition&gt;&lt;/application&gt;&lt;span style="font-family: courier new;"&gt;_link()&lt;/span&gt;&lt;application&gt;&lt;partition&gt;&lt;application&gt;&lt;partition&gt;&lt;application&gt;&lt;partition&gt;&lt;application&gt;&lt;partition&gt;s the new one at that position. I have not found this API to be of any use, personally.&lt;br /&gt;&lt;br /&gt;Although the UJML documentation says that the launching application is de-activated, it is actually suppressed in the Z-order. If an event comes in and the topmost application does not handle it, the event will trickle down the application stack until a handler is found or it reaches the bottom of the stack. Be sure that no unwanted event handlers are active when launching an application.&lt;br /&gt;&lt;br /&gt;By effectively using the application stack, it is possible to write multi-featured applications in a small space since you can &lt;/partition&gt;&lt;/application&gt;&lt;/partition&gt;&lt;/application&gt;&lt;/partition&gt;&lt;/application&gt;&lt;/partition&gt;&lt;/application&gt;&lt;span style="font-family: courier new;"&gt;_link()&lt;/span&gt;&lt;application&gt;&lt;partition&gt;&lt;application&gt;&lt;partition&gt;&lt;application&gt;&lt;partition&gt;&lt;application&gt;&lt;partition&gt; and &lt;span style="font-family: courier new;"&gt;_unlink()&lt;/span&gt; necessary components on the fly.&lt;/partition&gt;&lt;/application&gt;&lt;/partition&gt;&lt;/application&gt;&lt;/partition&gt;&lt;/application&gt;&lt;/partition&gt;&lt;/application&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31054059-8546963235551382681?l=ujml.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ujml.blogspot.com/feeds/8546963235551382681/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=31054059&amp;postID=8546963235551382681' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/31054059/posts/default/8546963235551382681'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/31054059/posts/default/8546963235551382681'/><link rel='alternate' type='text/html' href='http://ujml.blogspot.com/2007/03/lesson-7-loading-and-unloading.html' title='Lesson 7: Loading and Unloading applications'/><author><name>Lauren Smith</name><uri>http://www.blogger.com/profile/01523158891010339130</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://photos1.blogger.com/img/158/8299/320/050923_003L1.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-31054059.post-3075967799840914697</id><published>2007-02-28T18:51:00.000-08:00</published><updated>2007-02-28T18:58:36.679-08:00</updated><title type='text'>Lesson 6: State machines</title><content type='html'>At this point we've covered the basics of the UJML language. You know how to display images, capture user events, set up and execute states, and write functions. Putting this all together, we can create &lt;a href="http://developer.uievolution.com/docs/en/LangRef/state-machines.html"&gt;&amp;lt;state-machines&amp;gt;&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;A &lt;a href="http://developer.uievolution.com/docs/en/LangRef/State_Machines.html"&gt;state machine&lt;/a&gt; is a collection of state variables, variables, functions, and states that can be used to modularize UJML code. Every state machine has a name which is used as a prefix to the functions and variables of the state machine.&lt;br /&gt;&lt;br /&gt;You can create a state machine inline in your UJML code or you can separate it out into another file and include the file in your UJML code. Either way, the state machine code is copied into the UJML code at compile time.&lt;br /&gt;&lt;br /&gt;Here is an example of a separately written state machine module. The filename extension is .ujms which indicates that it is a UJML state machine definition.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;hello.ujms&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;lt;ujml&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;partition&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;state-machines&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;state-machine name="HelloWorld"&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;state-variables&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;state-var name="sShow" type="boolean"/&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/state-variables&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;variables&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;var name="mName" type="string"/&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/variables&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;functions&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;function name="setName" type="void" visibility="public"&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;parameters&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;var name="aName" type="string"/&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/parameters&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;script&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;mName = aName;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/script&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/function&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;function name="show" type="void" visibility="public"&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;script&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;_clear_state(sShow);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;sShow = true;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/script&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/function&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/functions&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;states&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;state var="sShow"&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;transition value="true"&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;display&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;label&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;text&amp;gt;&amp;lt;eval&amp;gt;_strcat("Hello, ", mName, "!")&amp;lt;/eval&amp;gt;&amp;lt;/text&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/label&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/display&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/transition&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/state&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/states&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/state-machine&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/state-machines&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/partition&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;lt;/ujml&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;To use this state machine, you first need to include it into your application.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;lt;ujml&amp;gt;&lt;br /&gt;  &amp;lt;application&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;  &amp;lt;state-machines&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;  &amp;lt;include file="hello.ujms" state-machine="HelloWorld" /&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;  &amp;lt;/state-machines&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;  ...&lt;br /&gt;  &amp;lt;/application&amp;gt;&lt;br /&gt;&amp;lt;/ujml&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Now, you can call the state machine functions from any script block.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;lt;ujml&amp;gt;&lt;br /&gt;  &amp;lt;application&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;  ...&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;  &amp;lt;script&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;  HelloWorld.setName("Lauren");&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;  HelloWorld.show();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;  &amp;lt;/script&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;  ...&lt;br /&gt;  &amp;lt;/application&amp;gt;&lt;br /&gt;&amp;lt;/ujml&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;By separating out this code, you make your main application code simpler and easier to follow. Since the state machine code is encapsulated in another file, you can keep logically separate code isolated.&lt;br /&gt;&lt;br /&gt;It is important to be aware of Z-order when using state machines. An application may include the &amp;lt;state-machine&amp;gt; block at either the top of the partition or at the bottom or both. If the state machine is included at the top of the partition, then it will display with a lower Z-order (underneath) the display of the partition. Alternatively, if the state machine is included at the bottom of the partition, it will display with a higher Z-order than the partition's display. This is a common error to make. The clues are that your state machine variables are correct in the debugger but nothing is displayed on the screen. It is likely that your state machine has a lower Z-order than it needs to display correctly.&lt;br /&gt;&lt;br /&gt;Another important point is that state machines are not objects. There is no concept of a state machine 'object', so you can't create multiple instances of a state machine. State machines are merely collections of functions, variables, and states that encapsulate some functionality for your application.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31054059-3075967799840914697?l=ujml.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ujml.blogspot.com/feeds/3075967799840914697/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=31054059&amp;postID=3075967799840914697' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/31054059/posts/default/3075967799840914697'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/31054059/posts/default/3075967799840914697'/><link rel='alternate' type='text/html' href='http://ujml.blogspot.com/2007/02/lesson-6-state-machines.html' title='Lesson 6: State machines'/><author><name>Lauren Smith</name><uri>http://www.blogger.com/profile/01523158891010339130</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://photos1.blogger.com/img/158/8299/320/050923_003L1.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-31054059.post-116298065724890390</id><published>2006-11-08T02:10:00.000-08:00</published><updated>2006-11-21T02:10:34.540-08:00</updated><title type='text'>Lesson 5: Functions</title><content type='html'>Lesson 5: Functions&lt;br /&gt;&lt;br /&gt;Functions are sections of code that can be executed by a script. If you are familiar with programming, then this needs no introduction, but if you are brand new to programming, you may want to familiarize yourself with the concept &lt;a href="http://developer.uievolution.com/docs/en/LangRef/Using_Functions.html"&gt;here&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Generally, functions have a name, return value, parameter list, and executable code. In addition, functions have a property called &lt;a href="http://developer.uievolution.com/docs/en/LangRef/Function_Scoping_and_Sharing.html"&gt;scope&lt;/a&gt; and another property called visibility.&lt;br /&gt;&lt;br /&gt;You declare functions in a child-leaf of the &lt;a href="http://developer.uievolution.com/docs/en/LangRef/functions.html"&gt;&amp;lt;functions&amp;gt;&lt;/a&gt; tag. The following is an example of a very simple function.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;lt;functions&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;function name="SetName" type="boolean"&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;parameters&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;var name="name" type="string" /&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/parameters&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;variables&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;var name="ret" type="boolean" /&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/variables&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;script&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;mName = name;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ret = true;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/script&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;return&amp;gt;&amp;lt;eval&amp;gt;ret&amp;lt;/eval&amp;gt;&amp;lt;/return&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/function&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;lt;/functions&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;In this example, a function called "SetName" is defined. It returns a boolean value to the caller. The caller passes in a string variable called "name", and the function defines a local boolean variable called "ret". When called, the script is executed (the value of name is assigned to the global variable mName and true is assigned to the local variable ret). The function returns the value contained inside of ret.&lt;br /&gt;&lt;br /&gt;If you are familiar with C++, the following is approximately equivalent code:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;bool SetName(string name)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;bool ret;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;mName = name;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;ret = true;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;return ret;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;To call a function from code, type the function name, append appropriate parameters, and if desirable, assign the return value to a variable. The following is an example of some code calling SetName.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;lt;variables&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;var name="mName" type="string" /&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;var name="mIsSet" type="string" /&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;lt;/variables&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;lt;script&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;mIsSet = SetName("Lauren");&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;This snippet shows the script calling SetName with the string "Lauren". It catches the return value and stores it in a global variable called "mIsSet".&lt;br /&gt;&lt;br /&gt;Functions may also call other functions. However, they may not call themselves. A function that calls itself is called a &lt;a href="http://en.wikipedia.org/wiki/Recursion_%28computer_science%29"&gt;recursive function&lt;/a&gt;. UJML does not permit &lt;a href="http://developer.uievolution.com/docs/en/LangRef/User_Defined_Functions.html"&gt;functions to be recursive&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;That's the gist of it. You use functions to execute code. By splitting your program up into a logical set of functions and giving each function a good name, your code will be cleaner, easier to read, and have a better architecture than if you tried to build the program out of a single block of executable script code.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31054059-116298065724890390?l=ujml.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ujml.blogspot.com/feeds/116298065724890390/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=31054059&amp;postID=116298065724890390' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/31054059/posts/default/116298065724890390'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/31054059/posts/default/116298065724890390'/><link rel='alternate' type='text/html' href='http://ujml.blogspot.com/2006/11/lesson-5-functions.html' title='Lesson 5: Functions'/><author><name>Lauren Smith</name><uri>http://www.blogger.com/profile/01523158891010339130</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://photos1.blogger.com/img/158/8299/320/050923_003L1.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-31054059.post-116134357537398153</id><published>2006-10-20T04:25:00.000-07:00</published><updated>2006-10-20T04:36:45.386-07:00</updated><title type='text'>Lesson 4c: Resources and Display control</title><content type='html'>Lesson 4c: Resources and Display control&lt;br /&gt;&lt;br /&gt;What we've discovered so far is that it is very easy to draw things on the screen and straightforward to update the screen using state transitions. However there lies a very subtle problem that affects the display on actual devices. &lt;br /&gt;The problem is that visual elements are shown as soon as they are loaded. This does not sound like a problem, and on devices with fast filesystems, network connections, and graphics cards it isn't. The problem occurs when you attempt to run the code on a slower device with lots of network overhead or a slow graphics chip. Since the display only shows items as they are loaded, a page may not render fully because it is waiting for the requested images to arrive over the network.&lt;br /&gt;&lt;br /&gt;Users may find this acceptable for some applications like web browsing or news browsing when the primary user interaction is reading text, but once the focus falls on displaying images, it becomes very difficult to provide a uniform, pleasant user experience if images are not displayed in a reasonable manner.&lt;br /&gt;&lt;br /&gt;The most reasonable manner for most applications is to display all the images at once. This means that the program will load all the images before displaying them.&lt;br /&gt;&lt;br /&gt;To manage resources, UJML provides the &lt;a href="http://developer.uievolution.com/docs/en/LangRef/resource.html"&gt;resource&lt;/a&gt; tag. Resources are defined by a URL, and they have the ability to give status notification via the &lt;a href="http://developer.uievolution.com/docs/en/LangRef/event.html"&gt;event&lt;/a&gt; tag. Resources are also peculiar because they are only definable within &lt;a href="http://developer.uievolution.com/docs/en/LangRef/State_Transitions.html"&gt;state transitions&lt;/a&gt;. So by using a state variable it is possible to directly affect when a resource is loaded, and by effectively handling the load events it is possible to control the program flow.&lt;br /&gt;&lt;br /&gt;When the state transition is active, the resources defined in it are loaded. When the state transition becomes inactive, the loaded resources are unloaded and any pending network requests are cancelled.&lt;br /&gt;&lt;br /&gt;This lends itself to two straightforward applications. The first is very useful for applications that use a lot of images that provide the program's "look and feel". Putting all the images that will exist for the life of the application in a single state transition and setting it at the outset of the program will guarantee that those images will be immediately available any time they are needed. The second is to force all displayable items to be drawn simultaneously by not drawing the screen until all items have been loaded.&lt;br /&gt;&lt;br /&gt;To create a "permanent resource partition", as I like to call it, all you need to do is define a new partition with a boolean state variable which is set to true in the &lt;a href="http://developer.uievolution.com/docs/en/LangRef/script.html"&gt;script&lt;/a&gt; section of the partition definition. To complete the partition, a state transition is defined for the variable that contains all the permanent application resources.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;lt;ujml&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;partition&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;state-variables&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;state-var name="sLoadResources" type="boolean" /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/state-variables&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;script&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;sLoadResources = true;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/script&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;states&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;state var="sLoadResources"&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;transition value="true"&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;resources&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;resource&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;url&gt;http://example.com/a.jpg&amp;lt;/url&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/resource&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;resource&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;url&gt;http://example.com/b.jpg&amp;lt;/url&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/resource&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/resources&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/transition&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/state&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/states&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/partition&gt;&lt;br /&gt;&amp;lt;/ujml&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;In the above example code, two image resources are loaded when this partition is &lt;a href="http://developer.uievolution.com/docs/en/LangRef/_link().html"&gt;linked&lt;/a&gt; to the main application. The script is run immediately and sLoadResources is activated. Since sLoadResources is never set to false, the resources in the partition are available for the entire lifetime of the application, even from other partitions which may be loaded later.&lt;br /&gt;&lt;br /&gt;That is the most straightforward usage of resources, however to gain the full benefit of the management technique, it is necessary to use the event tag to catch resource events.&lt;br /&gt;&lt;br /&gt;There are two resource events. &lt;a href="http://developer.uievolution.com/docs/en/LangRef/onResourceAvailable.html"&gt;onResourceAvailable&lt;/a&gt; for successful loading, and &lt;a href="http://developer.uievolution.com/docs/en/LangRef/onResourceError.html"&gt;onResourceError&lt;/a&gt; when an error occurred in the loading of the resource. These two events provide you with the tools necessary to regulate program flow.&lt;br /&gt;&lt;br /&gt;The second technique which I mentioned above makes heavy use of resource events. The key is to tie each resource event to a counter which will signal when the program should proceed with processing.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;lt;ujml&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;partition&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;state-variables&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;state-var name="sLoad" type="boolean" /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;state-var name="sDraw" type="boolean" /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/state-variables&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;variables&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;var name="mLoadCnt" type="int" /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;var name="mToLoad" type="int" /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/variables&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;functions&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;function name="AllResourcesLoaded" type="void"&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;script&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;// All resources have been loaded, so paint the screen&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;sDraw = true;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/script&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/function&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/functions&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;script&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;mLoadCnt = 0; // No resources loaded yet&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;mToLoad = 2;  // We are expecting two resources&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;sLoad = true; // Begin the resource loading routine&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/script&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;states&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;state var="sLoad"&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;transition value="true"&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;resources&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;resource&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;url&gt;http://example.com/a.jpg&amp;lt;/url&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;event name="onResourceAvailable"&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;script&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;mLoadCnt++;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if (_eq(mLoadCnt, mToLoad))&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;AllResourcesLoaded();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/script&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/event&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;event name="onResourceError"&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;script&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;mToLoad--;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if (_eq(mLoadCnt, mToLoad))&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;AllResourcesLoaded();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/script&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/event&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/resource&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;resource&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;url&gt;http://example.com/b.jpg&amp;lt;/url&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;event name="onResourceAvailable"&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;script&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;mLoadCnt++;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if (_eq(mLoadCnt, mToLoad))&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;AllResourcesLoaded();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/script&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/event&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;event name="onResourceError"&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;script&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;mToLoad--;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if (_eq(mLoadCnt, mToLoad))&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;AllResourcesLoaded();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/script&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/event&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/resource&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/resources&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/transition&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/state&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;state var="sDraw"&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;display&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;image&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;url&gt;http://example.com/a.jpg&amp;lt;/url&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;x&gt;0&amp;lt;/x&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;y&gt;0&amp;lt;/y&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;width&gt;100&amp;lt;/width&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;height&gt;100&amp;lt;/height&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/image&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;image&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;url&gt;http://example.com/b.jpg&amp;lt;/url&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;x&gt;100&amp;lt;/x&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;y&gt;0&amp;lt;/y&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;width&gt;100&amp;lt;/width&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;height&gt;100&amp;lt;/height&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/image&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/display&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/state&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/states&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/partition&gt;&lt;br /&gt;&amp;lt;/ujml&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Briefly, when the partition is loaded, it immediately begins loading the resources by setting the sLoad state variable to true. When each resource fires its success/error event, the corresponding script checks to see if all resources have been loaded, and if they have been, it sets sDraw to true to paint the two pictures side by side.&lt;br /&gt;&lt;br /&gt;This technique can be extended to as many resources as you want, given the device's memory constraints. Also, if a function is provided that sets sLoad to false, the resources can be unloaded as well. It is even possible to create an array of boolean state variables to provide fine-grained loading and unloading of resources.&lt;br /&gt;&lt;br /&gt;One key item to remember, though, is that as long as a resource is in use (by either the resource tag or a display tag) the resource is kept in memory. So in order to force a.jpg and b.jpg out of memory in the example above, it is necessary to set both sLoad and sDraw to false so that no state transition using the resource is active.&lt;br /&gt;&lt;br /&gt;Resource do not necessarily have to be images, too. Sound files, even other UJBC files may be loaded using the resource tag.&lt;br /&gt;&lt;br /&gt;The resource tag is the most important tool UJML provides for managing memory and providing users with a solid user experience. There are other even more fine-grained tools for resource management like &lt;a href="http://developer.uievolution.com/docs/en/LangRef/_prefetch().html"&gt;_prefetch&lt;/a&gt; and &lt;a href="http://developer.uievolution.com/docs/en/LangRef/_discard().html"&gt;_discard&lt;/a&gt;, but most of the heavy lifting will typically be handled using the &lt;a href="http://developer.uievolution.com/docs/en/LangRef/resources.html"&gt;resource&lt;/a&gt; tag.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31054059-116134357537398153?l=ujml.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ujml.blogspot.com/feeds/116134357537398153/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=31054059&amp;postID=116134357537398153' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/31054059/posts/default/116134357537398153'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/31054059/posts/default/116134357537398153'/><link rel='alternate' type='text/html' href='http://ujml.blogspot.com/2006/10/lesson-4c-resources-and-display.html' title='Lesson 4c: Resources and Display control'/><author><name>Lauren Smith</name><uri>http://www.blogger.com/profile/01523158891010339130</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://photos1.blogger.com/img/158/8299/320/050923_003L1.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-31054059.post-115681872987532109</id><published>2006-08-28T19:31:00.000-07:00</published><updated>2006-08-28T19:46:15.183-07:00</updated><title type='text'>Lesson 4b: State variables and transitions</title><content type='html'>In the previous sublesson, I mentioned state variables and that they may be used to display visual elements. This is a simplification of their purpose, but in regards to displays, &lt;b&gt;state variables are the only way to update the display&lt;/b&gt;.&lt;br /&gt;&lt;br /&gt;I find that thinking of applications as a series of screens helps me understand the concept behind state variables. On mobile phones, this is very obvious. You press the menu button to show the menu (a screen), you select an item from the menu and it loads a different part of the application (another screen). Any of the menu items may lead to any number of other screens. One screen, in other words, may have many different screen transitions.&lt;br /&gt;&lt;br /&gt;In a typical programming language, you'd set up an object's member variables (color=red, size=10, etc) and then call a method which then performs some processing based upon the updated object state. A state is defined in this situation by its defining characteristics (variables) and its behavior is defined by the results of the execution (method). To change state, the program must explicitly call the state transition with the correct variables. If the input parameters are incorrect, the program may behave in an undefined manner.&lt;br /&gt;&lt;br /&gt;UJML introduces the concept of state variables. They are different from normal variables because they have special knowledge about their internal values. When a state variable's value changes, it reacts by executing a script defined for that particular value. This leads to two fundamental properties of state variables:&lt;br /&gt;&lt;br /&gt;1) State variables may be any type except for &lt;a href="http://developer.uievolution.com/docs/en/LangRef/reference_data_type.html"&gt;reference data types&lt;/a&gt;.&lt;br /&gt;2) State variable execution scripts can be called implicitly by the UIE Player.&lt;br /&gt;&lt;br /&gt;The second property is the more interesting of the two. By simply changing the value of a state variable, the specified script is executed.&lt;br /&gt;&lt;br /&gt;State variables are declared as follows:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;lt;ujml&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;application&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;state-variables&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;state-var name="sPaintScreen" type="boolean" /&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/state-variables&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/application&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;lt;/ujml&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The state variable is scoped to the entire application block, so it may be accessed anywhere from within the block. It is also possible to define state variables that have more restricted scope, but I'll try to cover that later when I discuss state machines.&lt;br /&gt;&lt;br /&gt;When a state variable is updated, it transitions to a new state. This is called a &lt;a href="http://developer.uievolution.com/docs/en/LangRef/State_Transitions.html"&gt;state transition&lt;/a&gt;. A state transition may contain a display routine, audio routine, script routine, or a resource definition. It may also use a variable declaration to provide any necessary local variables to the script.&lt;br /&gt;&lt;br /&gt;This is an example of a simple state transition that displays an image.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;lt;state var="sPaintScreen"&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;transition value="true"&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;display&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;image&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;url&amp;gt;http://photos1.blogger.com/img/158/8299/320/050923_003L1.jpg&amp;lt;/url&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;x&amp;gt;0&amp;lt;/x&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;y&amp;gt;0&amp;lt;/x&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;width&amp;gt;240&amp;lt;/width&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;height&amp;gt;320&amp;lt;/height&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/image&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/display&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/transition&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;lt;/state&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;This state transition will display the specified image on the screen when the 'sPaintScreen' state variable is set to "true". When 'sPaintScreen' is set to "false", anything specified in the "true" transition will be deleted. In short, "true" shows the image, and "false" hides the image.&lt;br /&gt;&lt;br /&gt;Now, to paint the image to the screen, the application's script just sets the sPaintScreen state variable to true.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;lt;ujml&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;application&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;state-variables&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;state-var name="sPaintScreen" type="boolean" /&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/state-variables&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;script&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;// Paint the image&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;sPaintScreen = true;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/script&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;states&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;state var="sPaintScreen"&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;transition value="true"&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;display&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;image&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;url&amp;gt;http://photos1.blogger.com/img/158/8299/320/050923_003L1.jpg&amp;lt;/url&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;x&amp;gt;0&amp;lt;/x&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;y&amp;gt;0&amp;lt;/y&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;width&amp;gt;240&amp;lt;/width&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;height&amp;gt;320&amp;lt;/height&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/image&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/display&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/transition&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/state&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/states&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/application&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;lt;/ujml&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The code above does essentially the same thing as the code in the previous lesson. The difference is that this version separates the painting of the image from the application display. When a visual element is included directly in the application's display, it remains on the screen at the lowest Z-order. By moving the visual element into a state transition display, it can be shown and erased from the display programmatically.&lt;br /&gt;&lt;br /&gt;We previously used function key accelerators to handle user interactions. If we use the same technique here, we can update the display in response to user key presses.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;lt;fn&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;text&amp;gt;Update Display&amp;lt;/text&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;event name="onselect"&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;accelerators&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;key&amp;gt;F1&amp;lt;/key&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/accelerators&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;script&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;// flip flop the boolean value&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;sPaintScreen = !sPaintScreen;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/script&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/event&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;lt;/fn&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;This key handler will either show or erase the image on the screen when the user presses the F1 key. The program we have been working on is now interactive!&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;lt;ujml&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;application&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;state-variables&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;state-var name="sPaintScreen" type="boolean" /&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/state-variables&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;script&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;// Paint the image&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;sPaintScreen = true;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/script&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;display&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;fn&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;text&amp;gt;Update Display&amp;lt;/text&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;event name="onselect"&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;accelerators&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;key&amp;gt;F1&amp;lt;/key&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/accelerators&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;script&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;// flip flop the boolean value&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;sPaintScreen = !sPaintScreen;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/script&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/event&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/fn&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/display&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;states&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;state var="sPaintScreen"&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;transition value="true"&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;display&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;image&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;url&amp;gt;http://photos1.blogger.com/img/158/8299/320/050923_003L1.jpg&amp;lt;/url&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;x&amp;gt;0&amp;lt;/x&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;y&amp;gt;0&amp;lt;/y&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;width&amp;gt;240&amp;lt;/width&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;height&amp;gt;320&amp;lt;/height&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/image&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/display&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/transition&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/state&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/states&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/application&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;lt;/ujml&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Briefly, the above code declares a state variable called 'sPaintScreen'. The sPaintScreen variable is set to 'true' which puts the sPaintScreen=true state transition into the queue. The display is updated with the F1 key bound to the 'onselect' event. The pending state transition is executed and the image is shown on the screen. When the user presses the F1 key, sPaintScreen is set to 'false' which then erases any visual elements specified in 'true'. Since there is no explicit 'false' transition, no special handling is performed. If the user presses the F1 key again, sPaintScreen is set to 'true' which puts the image back on the screen.&lt;br /&gt;&lt;br /&gt;Try the code and play with it for a little while. Investigate adding an event handler into the sPaintScreen=true state transition. Doing so will allow you to change the text of the F1 key accelerator.&lt;br /&gt;&lt;br /&gt;Next time I will cover using the &lt;a href="http://developer.uievolution.com/docs/en/LangRef/resources.html"&gt;resources&lt;/a&gt; tag to manage the handling of images.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31054059-115681872987532109?l=ujml.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ujml.blogspot.com/feeds/115681872987532109/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=31054059&amp;postID=115681872987532109' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/31054059/posts/default/115681872987532109'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/31054059/posts/default/115681872987532109'/><link rel='alternate' type='text/html' href='http://ujml.blogspot.com/2006/08/lesson-4b-state-variables-and.html' title='Lesson 4b: State variables and transitions'/><author><name>Lauren Smith</name><uri>http://www.blogger.com/profile/01523158891010339130</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://photos1.blogger.com/img/158/8299/320/050923_003L1.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-31054059.post-115556957444070594</id><published>2006-08-14T07:53:00.000-07:00</published><updated>2006-08-24T01:30:41.360-07:00</updated><title type='text'>Lesson 4a: Displaying images</title><content type='html'>By now you're probably wondering when I'm going to get to the good stuff, you know, like showing pictures and stuff. Well, let's get to it.&lt;br /&gt;&lt;br /&gt;First, it is important to understand that images are &lt;a href="http://developer.uievolution.com/docs/en/LangRef/Resources1.html"&gt;resources&lt;/a&gt;. This means that once they are loaded they stay loaded only while they are needed. Once a resource is loaded, though, it is available immediately to any code that needs it. It's a very powerful idiom, and we will explore using images as resources in the second half of this lesson.&lt;br /&gt;&lt;br /&gt;Images are defined by the &lt;a href="http://developer.uievolution.com/docs/en/LangRef/image.html"&gt;&amp;lt;image&amp;gt;&lt;/a&gt; tag. You tell the player which file to load by providing it with a &lt;a href="http://developer.uievolution.com/docs/en/LangRef/url.html"&gt;URL&lt;/a&gt;. URLs are merely the URI-format location of the file on disk or internet. UJML treats URLs as relative addresses to the location of the executing UJML program. The exception is when you specify a complete URI with either an http:// or file:/// or other URI header.&lt;br /&gt;&lt;br /&gt;I'll use the graphic located at &lt;span style="font-family: courier new;"&gt;http://photos1.blogger.com/img/158/8299/320/050923_003L1.jpg&lt;/span&gt; as the sample image for this lesson.&lt;br /&gt;&lt;br /&gt;If you just specify an image with the URL, the image will be displayed at 0,0 (or the top-left corner of the screen). Unfortunately, it will also be displayed with a width of 0,0 which means that it won't be visible at all. This is a common theme in UJML: the default values are typically 0, so it's important to set them correctly. DO NOT RELY ON UJML TO SET DEFAULTS.&lt;br /&gt;&lt;br /&gt;I'm not so interested in displaying the image somewhere in the middle of the screen, so for the time being I'm not going to change the x,y offsets. However it is important that I change the width and height properties so that the image is properly displayed. The image is 240 pixels wide and 320 pixels high.&lt;br /&gt;&lt;br /&gt;I specify the image as follows:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;lt;image&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;url&gt;http://photos1.blogger.com/img/158/8299/320/050923_003L1.jpg&amp;lt;/url&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;width&gt;240&amp;lt;/width&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;height&gt;320&amp;lt;/height&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;lt;/image&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Logically it follows that since this is part of the display it should go into the display tag of our application. The simplified code follows:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;lt;ujml&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;application&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;display&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;image&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;url&gt;http://photos1.blogger.com/img/158/8299/320/050923_003L1.jpg&amp;lt;/url&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;width&gt;240&amp;lt;/width&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;height&gt;320&amp;lt;/height&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/image&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/display&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/application&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;lt;/ujml&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Now, like the original Hello World program from Lesson 1, we have created a program that can display the data we wish to show the user.&lt;br /&gt;&lt;br /&gt;One important aspect of this is that &lt;a href="http://developer.uievolution.com/docs/en/LangRef/Visual_Elements.html"&gt;visual elements&lt;/a&gt; like images and labels can be stacked on one another. This is called &lt;a href="http://developer.uievolution.com/docs/en/LangRef/Z-Order.html"&gt;Z-order&lt;/a&gt;. Items specified first will be displayed first, so each item drawn after that will be layered on top of it. You can think of this like a stack of visual elements where the last item drawn is on top of the stack while the first item drawn is all the way at the bottom and possibly even covered up by elements above it.&lt;br /&gt;&lt;br /&gt;Let's say we wanted to write Hello World on top of the image we just drew. All that's necessary is to add a label to the display area.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;lt;ujml&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;application&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;display&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;image&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;url&gt;http://photos1.blogger.com/img/158/8299/320/050923_003L1.jpg&amp;lt;/url&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;width&gt;240&amp;lt;/width&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;height&gt;320&amp;lt;/height&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/image&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;label&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;text&gt;Hello World!&amp;lt;/text&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/label&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/display&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/application&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;lt;/ujml&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Now, since the label is drawn after the image it is shown on top. If the order was reversed, the label would be invisible because the image would completely cover it up.&lt;br /&gt;&lt;br /&gt;Next time I will discuss state variables and using them to display elements.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31054059-115556957444070594?l=ujml.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ujml.blogspot.com/feeds/115556957444070594/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=31054059&amp;postID=115556957444070594' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/31054059/posts/default/115556957444070594'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/31054059/posts/default/115556957444070594'/><link rel='alternate' type='text/html' href='http://ujml.blogspot.com/2006/08/lesson-4a-displaying-images.html' title='Lesson 4a: Displaying images'/><author><name>Lauren Smith</name><uri>http://www.blogger.com/profile/01523158891010339130</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://photos1.blogger.com/img/158/8299/320/050923_003L1.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-31054059.post-115492989160423222</id><published>2006-08-06T22:50:00.000-07:00</published><updated>2006-08-28T19:51:07.233-07:00</updated><title type='text'>Lesson 3: Elementary events</title><content type='html'>At this point, we've familiarized ourselves with the UIE SDK and have a vague understanding of what the heck is going on.&lt;br /&gt;&lt;br /&gt;Briefly, the steps we've covered so far are 1) Write some UJML code, 2) Open the IDE, 3) Compile the UJML code, and 4) Run our Hello World program. That's not really a lot.&lt;br /&gt;&lt;br /&gt;The first thing we probably want to do now that we've got those basics covered, is figure out how we are going to allow users to actually shut off the program. If you've read through the automatically generated Hello World example  from the SDK, you already know, and you can probably skip this lesson.&lt;br /&gt;&lt;br /&gt;For those of you still with me, let's jump in and see what UJML provides.&lt;br /&gt;&lt;br /&gt;On any mobile phone, you'll typically have a set of buttons above the numeric keypad. There is the directional pad which provides a means of entering UP, DOWN, LEFT, and RIGHT. It usually has a button in the middle which sends a command named FIRE to whatever application is currently active. Then surrounding the directional pad, there are two to four more buttons. Starting on the top-left, these are F1, (top-right) F2, (bottom-left) F3, and (bottom-right) F4. The UIPlayer can support up to F10, but most ports only support F1 and F2. This is unfortunate on Japanese phones because F1-F4 are almost universal here.&lt;br /&gt;&lt;br /&gt;Let's tie the keypress of one of the F-buttons to an event and have it execute some code. In English, that means that when someone presses a button, something happens on the device. I would like to start with adding "Exit Program" functionality to the Hello World application. The F2 key is as good a place as any to put this.&lt;br /&gt;&lt;br /&gt;To implement this type of functionality, UJML provides the &amp;lt;fn&gt; tag. And fn contains a text label and an event handler. These are cleverly given the tags &amp;lt;text&gt; and &amp;lt;event&gt;.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;lt;fn&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;text&gt;Exit Program&amp;lt;/text&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;event name="onSelect"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;accelerators&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;key&gt;F2&amp;lt;/key&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/accelerators&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;script&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;_unload();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/script&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/event&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;lt;/fn&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;What I have done there is specified a new function key with the text "Exit Program". It will be tied to an event called "onSelect" and will be fired by the key F2. When the onSelect event is fired, the script will be executed. The &lt;a href="http://developer.uievolution.com/docs/en/LangRef/_unload%28%29.html"&gt;_unload()&lt;/a&gt; function causes the program to unload itself from the application stack.&lt;br /&gt;&lt;br /&gt;The event "onSelect" occurs when a button is pressed. That action "selects" the key and fires that event. Only one event handler can fire per event, so the handler with the highest Z-order will handle the event. If the top-most handler does not implement a handler, the event is passed down through the Z-order to each remaining handler. If no one handles an event (like if you press a key in the original Hello World application) then no script will be executed.&lt;br /&gt;&lt;br /&gt;So the action that I've defined is that when the user presses the F2 (top-right) key, the program will call _unload() and exit.&lt;br /&gt;&lt;br /&gt;Since a function key goes on the screen, it belongs in the &amp;lt;display&gt; tag hierarchy. In fact, all events require &amp;lt;display&gt; tags because in UJML only &lt;a href="http://developer.uievolution.com/docs/en/LangRef/Visual_Elements.html"&gt;Visual Elements&lt;/a&gt; can receive user events. This will become clearer later when we tire other events to other visual elements.&lt;br /&gt;&lt;br /&gt;Combining this code with the original Hello World code we get the following program:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;lt;?xml version="1.0" encoding="UTF-8"?&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;lt;!DOCTYPE ujml PUBLIC "-//UIEVOLUTION//DTD UJML 1.5//EN" "http://www.uievolution.com/dtd/ujml-1.5.dtd"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;lt;ujml&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;application&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;display&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;label&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;text&gt;Hello UJML!&amp;lt;/text&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/label&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;fn&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;text&gt;Exit Program&amp;lt;/text&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;event name="onSelect"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;accelerators&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;key&gt;F2&amp;lt;/key&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/accelerators&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;script&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;_unload();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/script&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/event&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/fn&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/display&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/application&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;lt;/ujml&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;If you run it in the IDE, you should now have a button on the bottom right of the screen that says "Exit Program". Open up the Runtime tab in the debugger and you can see the _unload() function get called whenever you press the F2 button.&lt;br /&gt;&lt;br /&gt;If you're thinking what I'm thinking, you're probably wondering why the program isn't exiting. Well, the reason for that is that the emulator is designed to restart the original program after the program exits. So what you're seeing is actually the emulator closing the program then restarting it. The screen doesn't have any repainting to do, so it just looks like it's not shutting down. Don't worry, it is calling _unload() correctly. It just doesn't have anywhere to go once it calls it.&lt;br /&gt;&lt;br /&gt;Try other function keys and see how they work. Take a look at your own cell phone and see how other applications use the function keys. See whether they are static or dynamic, what sorts of functions you can execute from them, etc. From a programmer perspective, function keys are absolutely essential to creating usable user interfaces.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31054059-115492989160423222?l=ujml.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ujml.blogspot.com/feeds/115492989160423222/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=31054059&amp;postID=115492989160423222' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/31054059/posts/default/115492989160423222'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/31054059/posts/default/115492989160423222'/><link rel='alternate' type='text/html' href='http://ujml.blogspot.com/2006/08/lesson-3-elementary-events.html' title='Lesson 3: Elementary events'/><author><name>Lauren Smith</name><uri>http://www.blogger.com/profile/01523158891010339130</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://photos1.blogger.com/img/158/8299/320/050923_003L1.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-31054059.post-115448564588922998</id><published>2006-08-01T19:13:00.000-07:00</published><updated>2006-08-01T19:27:25.923-07:00</updated><title type='text'>Sidenote: My UJML Editor</title><content type='html'>If you're using the UIEvolution SDK, you know that it's based on &lt;a href="http://www.eclipse.org/"&gt;Eclipse&lt;/a&gt;, the open-source, extensible, all-singing, all-dancing, IDE. It's really great, and the UIEvolution engineers worked hard to integrate the IDE with the UJML language and compiler/debugger stack.&lt;br /&gt;&lt;br /&gt;However, plain vanilla UIE IDE is pretty harsh to write UJML in. Because the language is based on XML, there are just a ton of tags that need to be written and the IDE doesn't help at all when composing a program.&lt;br /&gt;&lt;br /&gt;To help that, I've heard that some programmers use an Eclipse extension called &lt;a href="http://www.xmlbuddy.com/"&gt;XML Buddy&lt;/a&gt; which provides some XML-language assistance. I tried it and couldn't make heads or tails of it. Others swear by it.&lt;br /&gt;&lt;br /&gt;Personally, I use &lt;a href="http://msdn.microsoft.com/vstudio/express/"&gt;Visual C++ (or VC#) Express&lt;/a&gt; to compose my programs. It does automatic ENTITY checking, auto-closes XML tags, and is freely available from Microsoft with only online registration being required. There are things that I wish it did better. I wish it would read the UJML DTD and automatically provide a list of valid tags for the current tagnode. I wish it didn't leak memory like there's no tomorrow (it eats up to 380MB of RAM sometimes, and it takes up to 10 minutes to close).&lt;br /&gt;&lt;br /&gt;What you use is up to you. The SDK comes with a decent IDE which can be extended. MS provides a free IDE which has a lot of niceties built in. Whatever you feel comfortable with is what you should use. Except for Notepad. Do yourself a favor and try something (anything) else.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31054059-115448564588922998?l=ujml.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ujml.blogspot.com/feeds/115448564588922998/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=31054059&amp;postID=115448564588922998' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/31054059/posts/default/115448564588922998'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/31054059/posts/default/115448564588922998'/><link rel='alternate' type='text/html' href='http://ujml.blogspot.com/2006/08/sidenote-my-ujml-editor.html' title='Sidenote: My UJML Editor'/><author><name>Lauren Smith</name><uri>http://www.blogger.com/profile/01523158891010339130</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://photos1.blogger.com/img/158/8299/320/050923_003L1.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-31054059.post-115435507905160763</id><published>2006-07-31T07:10:00.000-07:00</published><updated>2006-08-01T19:28:47.020-07:00</updated><title type='text'>Lesson 2: Getting started in the IDE</title><content type='html'>Before we get too far ahead of ourselves, it's probably a good time to take a break from actual UJML code and test drive the UIE SDK tools.  UIE provides an Eclipse-based IDE which can be used to create, edit, debug, and finally release your brilliant UJML application.&lt;br /&gt;&lt;br /&gt;It also comes with a clever little device emulator that allows you test your design on various screen sizes and resolutions. If that doesn't get your juices pumping, that very emulator also includes graphics that make it look like the device it's emulating! Maybe I'm getting a little carried away there.&lt;br /&gt;&lt;br /&gt;Let's jump in. Fire up the IDE. It's called "UIE Developer" and it should be in your Start menu.&lt;br /&gt;&lt;br /&gt;First thing you see is a screen with three possible selections.&lt;br /&gt;&lt;br /&gt;New UJML Project&lt;br /&gt;Samples&lt;br /&gt;Support&lt;br /&gt;&lt;br /&gt;The samples are very good, but a little advanced at this point. Support is provided by the online help. So what we are most interested in is taking our code from the last lesson and creating a new UJML project.&lt;br /&gt;&lt;br /&gt;Click on New UJML Project. It should bring up some UJML source code in the Edit window. This is a very well-written Hello World sample that does all sorts of things that haven't been covered yet like centering text on the screen and changing the text color and using key accelerators to provide events to the program. It's worth your while to read through this source code and see how programmers at UIE use UJML to create their own applications.&lt;br /&gt;&lt;br /&gt;I'm just going to go ahead and delete the entire source code and replace it with the code from the last lesson.&lt;br /&gt;&lt;br /&gt;STOP! Wait a second. Last lesson I said we were going to use DTD 1.5, but at the top of this file it specifies DTD 2.0. That's good news for us, because we want to be using the latest and greatest UJML language implementation.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&amp;lt;!DOCTYPE ujml PUBLIC "-//UIEVOLUTION//DTD UJML 2.0//EN" "http://www.uievolution.com/dtd/ujml-2.0.dtd" &gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;We'll replace the original 1.5 DTD in our old code with this one from now on. Sometimes it pays to play around with the software instead of reading the manual!&lt;br /&gt;&lt;br /&gt;In any case, copy the previous lesson's code into the source code and save the file. Now you've got a working UJML 2.0 program which can be run from the IDE. To run the code, just click on the little green Play icon.&lt;br /&gt;&lt;br /&gt;The first thing to notice is that the IDE compiles the program into an intermediate bytecode format called UJBC. Then it opens the emulator using the default skin (the RAZR skin is the default on my system) and loads the UJBC file as a program in the emulator.&lt;br /&gt;&lt;br /&gt;The output should say "Hello World!" if you've followed along correctly.&lt;br /&gt;&lt;br /&gt;To change the skin, click on the "Edit UJML Debugging Parameters" icon. It is right next to the Play icon and looks like a newspaper. The second tab is "Skin". All available emulator skins are listed along with the UIPlayer type (MIDP, DoJa, BREW, etc) and the screen resolution. Pick the skin that is most appropriate for your development. I use the DoCoMo SH505i skin because I think Sharp is the bestest.&lt;br /&gt;&lt;br /&gt;I've only scratched the surface of IDE features, but you're always welcome to play with it and see what other goodies are available. We've covered creating a new UJML project, running an application in the Emulator, and changing the Emulator skin. It's not a lot, by any means, but these seem to be the most often repeated steps in UJML programming, so it's good to get them introduced right away.&lt;br /&gt;&lt;br /&gt;Next time we discuss the IDE, it might make sense to talk about publishing and debugging. That will come later. For now, just poke around the IDE and see what you can find.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31054059-115435507905160763?l=ujml.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ujml.blogspot.com/feeds/115435507905160763/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=31054059&amp;postID=115435507905160763' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/31054059/posts/default/115435507905160763'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/31054059/posts/default/115435507905160763'/><link rel='alternate' type='text/html' href='http://ujml.blogspot.com/2006/07/lesson-2-getting-started-in-ide.html' title='Lesson 2: Getting started in the IDE'/><author><name>Lauren Smith</name><uri>http://www.blogger.com/profile/01523158891010339130</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://photos1.blogger.com/img/158/8299/320/050923_003L1.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-31054059.post-115277221857793305</id><published>2006-07-12T22:12:00.000-07:00</published><updated>2006-07-12T23:41:16.186-07:00</updated><title type='text'>Lesson 1: Hello World!</title><content type='html'>Let's begin our first lesson by building a very simple UJML application. It doesn't have to do much, so we can just do the standard Hello World program.&lt;br /&gt;&lt;br /&gt;UJML is based on XML, so it requires that a DOCTYPE be specified in order to validate the source code.  What?  A programming language based on XML?  Isn't that a little &amp;lt;VERBOSE&amp;gt;???&lt;br /&gt;&lt;br /&gt;Yes.  But we'll just overlook that for now and see what sort of benefits we can gain with UJML as a programming language.&lt;br /&gt;&lt;br /&gt;Back to the DOCTYPE.  UIEvolution's SDK provides three DTDs which define different versions of the UJML language. Since we're hip and up to date, we'll stick with DTD 1.5. (This is subject to change as newer versions are released, but at the time I am writing this 1.5 seems to be the version all the SDK-supplied samples use.)&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;lt;!DOCTYPE ujml PUBLIC "-//UIEVOLUTION//DTD UJML 1.5//EN" "http://www.uievolution.com/dtd/ujml-1.5.dtd"&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;That's boilerplate code right there. It will go at the top of every single UJML file you write. It imports the UIE UJML 1.5 DTD which can then be used to validate the UJML code that we will write later.&lt;br /&gt;&lt;br /&gt;The next step is to begin writing code. All code in UJML must be gathered under the &amp;lt;ujml&amp;gt; element.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;lt;ujml&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;some code&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;lt;/ujml&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;That's easy enough. This is also pretty much boilerplate code as well. The &amp;lt;ujml&amp;gt; tag tells the compiler that this is where the UJML code resides.&lt;br /&gt;&lt;br /&gt;What comes next is an application element. Think of this as the main object of your program. You declare an application element using the &amp;lt;application&amp;gt; tag.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;lt;ujml&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;application&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;some code&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/application&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;lt;/ujml&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Underneath the &amp;lt;ujml&amp;gt; element, there are actually a few elements which may be used. &amp;lt;partition&amp;gt; elements are linked or included in another file at runtime. &amp;lt;extensions&amp;gt; elements are used to provide access to non-UJML code (native) implementations of functions and events that are not included in the UJML player. &amp;lt;component&amp;gt; is used to pull together related functions, templates, and state machines into a single package (like a C++ namespace). &amp;lt;interfaces&amp;gt;  is used to describe the public services of a component. &amp;lt;uses&amp;gt; is used to include external source code directly into the current code.&lt;br /&gt;&lt;br /&gt;Needless to say, except for &amp;lt;application&amp;gt; these are beyond the scope of our current program, but we will try to come back to them later.&lt;br /&gt;&lt;br /&gt;What we've got so far will compile and run. It won't do anything, but this is the absolute shortest UJML program possible.&lt;br /&gt;&lt;br /&gt;Let's make it do something.&lt;br /&gt;&lt;br /&gt;There are actually quite a few UJML elements which may be used beneath the &amp;lt;application&amp;gt; element. What we are interested in, though, is getting something up on the screen. UJML uses the &amp;lt;display&amp;gt; tag to define the visual elements which are displayed when the application is active.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;lt;ujml&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;application&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;display&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;some display elements&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/display&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/application&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;lt;/ujml&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;If you take a look at the &lt;a href="http://developer.uievolution.com/docs/en/LangRef/Visual_Elements.html"&gt;Visual Elements&lt;/a&gt; reference page, it lists all the available elements that may be used within the &amp;lt;display&amp;gt; element.&lt;br /&gt;&lt;br /&gt;We will use the &amp;lt;label&amp;gt; element to display the greeting text on the screen.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;lt;!DOCTYPE ujml PUBLIC "-//UIEVOLUTION//DTD UJML 1.5//EN" "http://www.uievolution.com/dtd/ujml-1.5.dtd"&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;lt;ujml&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;application&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;display&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;label&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;text&amp;gt;Hello UJML!&amp;lt;/text&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/label&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/display&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/application&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;lt;/ujml&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;That's all there is to it! Now we've got a UJML program which will display "Hello UJML!".&lt;br /&gt;&lt;br /&gt;Still, it's useless unless we can run it. Save this file for now as "Hello.ujml" and we'll compile and run it in the next installment of this series.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31054059-115277221857793305?l=ujml.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ujml.blogspot.com/feeds/115277221857793305/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=31054059&amp;postID=115277221857793305' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/31054059/posts/default/115277221857793305'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/31054059/posts/default/115277221857793305'/><link rel='alternate' type='text/html' href='http://ujml.blogspot.com/2006/07/lesson-1-hello-world.html' title='Lesson 1: Hello World!'/><author><name>Lauren Smith</name><uri>http://www.blogger.com/profile/01523158891010339130</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://photos1.blogger.com/img/158/8299/320/050923_003L1.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-31054059.post-115276569671044404</id><published>2006-07-12T21:33:00.000-07:00</published><updated>2006-07-12T21:41:36.720-07:00</updated><title type='text'>First things first</title><content type='html'>Hi. I'm Lauren and I'll be your guide to learning &lt;a href="http://developer.uievolution.com/docs/en/LangRef/index.html"&gt;UJML&lt;/a&gt;. This will be an interactive learning experience for both you the reader and me the writer.&lt;br /&gt;&lt;br /&gt;You see, I'm learning this stuff right along with you. So I look forward to your input and questions and we'll see where this can go.&lt;br /&gt;&lt;br /&gt;The topic that I will focus on is programming UJML. UJML is &lt;a href="http://uievolution.com/"&gt;UIEvolution's&lt;/a&gt; programming language for writing small, embedded programs that will run atop their UIEngine. The UIEngine itself runs on many platforms, so your UJML program will be automatically cross-platform once written. Or that's the promise at least.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;&lt;a href="http://en.wikipedia.org/wiki/Small_print"&gt;Please keep in mind that nothing I say here represents the opinions of UIEvolution or its customers or sponsors or employees. Everything is offerred AS-IS and confers no warranty or license or anything else. Use this site at your own risk.&lt;/a&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31054059-115276569671044404?l=ujml.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ujml.blogspot.com/feeds/115276569671044404/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=31054059&amp;postID=115276569671044404' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/31054059/posts/default/115276569671044404'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/31054059/posts/default/115276569671044404'/><link rel='alternate' type='text/html' href='http://ujml.blogspot.com/2006/07/first-things-first.html' title='First things first'/><author><name>Lauren Smith</name><uri>http://www.blogger.com/profile/01523158891010339130</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://photos1.blogger.com/img/158/8299/320/050923_003L1.jpg'/></author><thr:total>0</thr:total></entry></feed>
