Archive for October, 2008

Video cue points

Wednesday, October 29th, 2008

If you want to trigger some events at certain times of a playing video, an easy solution is to use cue points.

You need to

a) place an instance of the VideoPlayer component on the stage

b) on the as file for your animation, add cue point on the video:

this.videoComponent.addASCuePoint(5, "firstCuePoint");
this.videoComponent.addASCuePoint(10, "secondCuePoint");

This add 1 cue point at 5.00 seconds of the video, and another at 10.00 seconds

c) add a listener

this.videoComponent.addEventListener(MetadataEvent.CUE_POINT, _handleCuePoint);

d) on the listening function, find out which cue point was triggered, and play along!

private function _handleCuePoint(pEvent:MetadataEvent) {
trace("CUE POINT REACHED!");
if (pEvent.info.name == "firstCuePoint"){
  //do something regarding the first cue point
}else{
  //do something regarding the second cue point
}
}

Use of constants

Monday, October 27th, 2008

In flash projects, there are often a set of colors used and reused through the project. It is quite easier to manage by defining them as constants like GREEN_LEMON rather than obscure 0×123456. Practically, you just need a Config.as file where you define them as static constants

e.g.:

public static const GREEN_LEMON:uint = 0×123456;

And then access

You can them easily access it throughout your application:

myTextFormat.color = Config.GREEN_LEMON;

Using symfony “sync” command on Windows

Tuesday, October 21st, 2008

The php Symfony frameworks has a very handy deployment feature: on a single command line you can deploy your application to various environments. You just need to configure the ssh login/password for each of your environment and the files to ignore during the transfer.(see the link above for the details)

However, this tool relies on rsync, a file synchronisation tool which is on all Linux machines, but not on Windows. rsync relies itself on ssh – so if, like me, you re developing on a Windows machine, you need to have both installed on your machine.

The good  news is there a readily available archive containing all this here.

AS3: checking the environment at runtime.

Friday, October 17th, 2008

It can sometimes be useful to now at runtime in which environment is running our flash animation (from the CS3 flash player, from a test server, from the production server…). For example, you may want to display the framerate when testing, but not on the production environment. Or you may need to access another WebORB (or whatever) server in test and prod environment.

As the flash application runs in the client, I found that the easier was to rely on a flashvars set in the index file.
So all you need to do is:

In the html file embedding the swf: (change “production” to “local” or “testing” on the corresponding environment)

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
  codebase="http://macromedia.com/cabs/swflash.cab#version=9,0,0,0"
  id=flaMovie width=800 height=600>
  <param name=movie value="flaMovie.swf">
  <param name=FlashVars value="environment=production">
  <param name=quality value=medium>
  <param name=bgcolor value=#00000>
  <embed src="flaMovie.swf" 
    FlashVars="environment=production" 
    bgcolor=#000000 width=800 height=600
    type="application/x-shockwave-flash">
  </embed>
</object>

And then in the action script code:

var paramObj:Object = LoaderInfo(this.root.loaderInfo).parameters;
var environment:String = paramObj["environment"];

And then you can use this environment flag to show / hide debug informations.


Rounded corners and floating elements in CSS

Wednesday, October 15th, 2008

I have got to implement the design (from psd/jpg to html/css) for a website of mine, which is kind of a new experience to me.
The first challenges were about implementing boxes with rounded corners and floating elements.

Rounded corners:
There are plenty of way to do rounded corners; but I wanted one without js and without image.
So I used the tips described in here:
http://www.html.it/articoli/nifty/index.html

The html looks like:

<b class="rtop">
  <b class="r1"></b> <b class="r2"></b> <b class="r3"></b> <b class="r4"></b>
</b>

<div class="content">
My content here
</div>
<b class="rbottom">
   <b class="r4"></b><b class="r3"></b><b class="r2"></b><b class="r1"></b>
</b>

And the css:

/* 1 */
.rtop, .rbottom{
display:block
}

/* 2 */
.rtop *, .rbottom *{
display: block;
height: 1px;
overflow: hidden;
background: #08572a none repeat scroll 0 0
}

/* 3 */
.r1{margin: 0 5px}
.r2{margin: 0 3px}
.r3{margin: 0 2px}
.r4{margin: 0 1px; height: 2px}

/* 4 */
.content{
  background-color: #08572a;
  padding: 1em;
}

The first chunk of the css ensure the content of the rtop and rbottom <b> are displayed as block (not inline) in the doc.

The second chunk do the same for the inner <b>, force the height, and set the background color.The overflow does not seems to be of used, at least in Firefox. Probably is in IE.

The third chunk set decreasing margin to each inner <b>, to actually create lines increasing (top section) decreasing (bottom section) in size.

The fourth chunk is just about setting the same background color for the content than for the borders.

Floating elements
I also have a list of elements in a left panel (floating), each elements having inner floating elements as well. My problem was that the inners element were half getting out of there container.
Normally a <div style=”clear:both” /> below the last element does the trick, but as the container panel is floating itself, the content normally in the right of the left panel get displayed below (that is: the whole page get cleared, not only the elements in the left panel).

A simple fix to that is to specify “overflow:auto” for the containing element (the left panel in my case) – which does not make much sense, as the expected behaviour for this property is defined as follow (http://www.w3schools.com/css/pr_pos_overflow.asp):
“If the content is clipped, the browser should display a scroll-bar to see the rest of the content”

Automated backup via subversion

Tuesday, October 14th, 2008

[EDIT: this script was not fully working, now corrected. see details in this post]
We are using Subversion as resource control for our (flash) projects, and we recently though we could use it to automate our backups.

The subversion server is in our local network, and the backup machine outside.

To make things easy, we ve got two ISPs, that we switch every 2 weeks (the ISPs being not terrible reliable here in New Zealand)

So I had to:

- configure the router in our local network so that the subversion server get always attributed the same ip
- configure the router in our local network so that incoming request on the svn port get redirected to the subversion server (identified by its IP, hence the first step)
- checkout all our projects in the backup server
- install a command-line subversion client on the backup server
- write a dos script on the backup server (a windows machine) to update all projects

As I did not know much about dos scripting, it took me a little while.
I had to
- check what is the current IP of our local router from outside (depeding on which ISP we’re plug at the moment of the update)
- if required, relocate the subversion url of all projects
- update all projects
- log some error in case of failure

So below is the corresponding script.

@echo off
REM set the two possible urls for fracture
SET URL1=https://1.2.3.4:8443/svn/
SET URL2=https://5.6.7.8:8443/svn/

REM get the current location: parse the file currentUrl.txt (which contains only one line) and set CURRENT_LOCATION
FOR /f %%a IN (currentUrl.txt) DO SET CURRENT_LOCATION=%%a
REM Current location set to... %CURRENT_LOCATION%
REM try updating a project
CD project1
svn update
REM ERRORLEVEL is changed by most of the commands upon execution, usually to 0 if success, 1 or more if failure
IF ERRORLEVEL 1 (
 cd ..
 REM Update the log file
 echo %DATE% Notice: changing url to %CURRENT_LOCATION% >> error.log
 REM Reset CURRENT_LOCATION
 SET OLD_LOCATION=%CURRENT_LOCATION%
 IF %CURRENT_LOCATION%==%URL1% (
  SET CURRENT_LOCATION=%URL2%
 ) ELSE (
  SET CURRENT_LOCATION=%URL1%
 )
 REM Update currentUrl file
 echo %CURRENT_LOCATION%> currentUrl.txt
 REM Relocate all folders
 FOR /D %%b in (*) DO (
  cd %%b svn switch --relocate %OLD_LOCATION%/%%b/trunk %CURRENT_LOCATION%/%%b/trunk
  IF ERRORLEVEL 1 echo %DATE% WARNING: project %%b could not be relocated >> ../error.log
  cd ..
 )
) ELSE (
 cd ..
)

REM Update all projects
FOR /D %%b in (*) DO (
 cd %%b
 svn update
 IF ERRORLEVEL 1 echo %DATE% ERROR: project %%b could not be updated >> ../error.log
 cd ..
)

@echo off
Setlocal ENABLEDELAYEDEXPANSION
REM set the two possible urls for fracture
Set URL1=https://125.236.208.239:8443/svn/
Set URL2=https://203.109.198.29:8443/svn/

REM get the current location
For /f %%a IN (currentUrl.txt) DO Set CURRENT_LOCATION=%%a

REM Current location set to... %CURRENT_LOCATION%

REM try updating a project
CD Debug
svn update
If ERRORLEVEL 1 (
CD ..
echo %DATE% Notice: changing url from %CURRENT_LOCATION% >> error.log
REM Reset CURRENT_LOCATION
Set OLD_LOCATION=%CURRENT_LOCATION%

If %CURRENT_LOCATION%==%URL1% (
Set CURRENT_LOCATION=%URL2%
) ELSE (
Set CURRENT_LOCATION=%URL1%
)

REM Update currentUrl file
echo !CURRENT_LOCATION! > currentUrl.txt
REM Relocate all folders

For /D %%b IN (*) DO (
CD %%b
svn switch --relocate !OLD_LOCATION!/%%b/trunk !CURRENT_LOCATION!/%%b/trunk
If ERRORLEVEL 1 echo %DATE% WARNING: project %%b could not be relocated >> ../error.log
CD ..
)
) ELSE (
CD ..
)

REM Update all

For /D %%b IN (*) DO (
CD %%b
svn update
If ERRORLEVEL 1 echo %DATE% ERROR: project %%b could not be updated >> ../error.log
CD ..
)