Code for various actions when clicking a button

July 4th, 2009

Here is the code for moving to a different frame when clicking a button, open a pdf file when clicking a button, open a url when a button on an image is clicked, and play the flash again when an image is clicked.

/* This code is placed in frame 1 on the action layer .
When the user clicks somewhere this code runs. */
stop();

import flash.events.MouseEvent;

/* Listen for mouse clicks. */
addEventListener(MouseEvent.CLICK, clickHandler);

/* When the user clicks somewhere with the mouse, this function is running. */
function clickHandler(event:MouseEvent):void
 {

 /* if what was clicked was not a button then do nothing */
 if(!(event.target is SimpleButton))
  {
   return;
   }

/*
These are the possible button names:
btnframe(label of frame) - example: btnframepage43 - action: goto frame 43
btnpdf(file name of pdf without the .pdf extension) -
example: btnpdfmanual -
action: open the file manual.pdf, the files is in the folder pdf/
btnurl(name of web site) - example: btnurlcnn -
example: open the website cnn, the url is given in the code below
btnplayagain - example: btnplayagain - action: play the flash file again
 */     

   /* remove the btn part of the button name*/
  var name:String = event.target.name.toLowerCase().replace("btn", "");

  if (name.indexOf("frame") != -1)
    {
    trace("Going to frame " + name);
    gotoAndStop(name);
    }  

 if(name.indexOf("pdf") != -1)
   {
   var pdfName:String = "pdf/" + name.replace("pdf", "") + ".pdf";
   trace("Open PDF file " + pdfName);
   navigateToURL(new URLRequest(pdfName));
   return;
   }

 /* if an image is clicked and a url should open */
  if (name.indexOf("url") != -1)
    {
    name = name.replace("url", "");
    var urlName:String = "";
    switch(name)
      {
       case "cnn":
          urlName = "http://www.cnn.com/";
          break;
      case "andres":
           urlName = "http://www.andresnordgreen.com/";
           break;
       }
       trace("Open URL: " + urlName);
       navigateToURL(new URLRequest(urlName));
       return;
   }

if (name.indexOf("playagain") != -1)
  {
  trace("Play again");
  goto(1);
  }   

}

How to make a button that jumps to another frame (internal web page)

June 25th, 2009

I found the code here and video tutorials here and here for how to do it with Action Script 3.

Update June 28:

The code was something like this. If someone clicks the button My_btn the function CursorClick will run. CursorClick moves to frame 2.

stop();
import flash.events.MouseEvent;
My_btn.addEventListener(MouseEvent.CLICK, CursorClick);
function CursorClick(event:MouseEvent):void
{
  gotoAndStop("2");
}

Thanks to some code from my son Paulo, here is better code. The listening for mouse click is set at frame 1 in the action layer and any click is listened for. If a button is clicked one moves to the frame given by the name of the button (the ‘btn’ part is removed). The frame one jumps to needs to have a layer with label identical to the name of the button. This is a far better solution as only one piece of code is needed and not one piece of code for each button.

stop();
import flash.events.MouseEvent;
addEventListener(MouseEvent.CLICK, clickHandler); function clickHandler(event:MouseEvent):void  {  if(!(event.target is SimpleButton))    {     return;     }   var name:String = event.target.name.toLowerCase().replace("btn", "");
gotoAndStop(name);   }

The next step is to add code for what should happen if a button that opens a pdf file or opens a window with an external url is clicked.

Action script

June 24th, 2009

Again, last time was in 2007, I have decided to learn a little bit of Action Script that is used in Flash.

Here are a few posts from the blog I made (it has now been deleted):

Learning by stealing

April 19, 2007 by jannordgreenA compiled flash file has extension swf. When you see a nice flash you want to save you can not just right-click it and save it as you can do with images.

Here are a few ways to copy a swf file to your hard disk.

  1. In Firefox, File – Save Page As – Web Page, complete. This gives you a folder you can open. It contains all the swf files on the page you saved.
  2. In Firefox, use the tool Web Developer. Information – Web Page Information – Media. Scroll to a swf file and click Save As.
  3. Download Sothink SWF Catcher for Firefox. Click Alt+C and all the swf files on the page are listed on the left.

A flash source file has extension fla. How do you decompile a swf file to a fla file so you can have a look at to see how it was made?

Sothink SWF Decompiler is the only tool I have found so far. The free download does not include any action script in the swf file, and it lasts only 30 days. The full version comes with a full price at $79.99. (I don’t know about you, but I intend to buy a chocolate with the one cent it is off $80.)

Now I have found a few more! Here is a list.

DeFlash costs only $12, but has dubious information about its availability:

Resources for beginners

May 2, 2007 by jannordgreenI have received some resource tips:

Thanks Paulo Fierro for the tips!

Roland Garros without a TV

June 7th, 2009

http://www.fromsport.com/video-29954.html gives me NBC’s image and commentaries while http://www.rolandgarros.com gives me French radio and live scoreboard. So, who needs a TV?

It sounded like this. It was recorded with Free MP3 Sound Recorder.

Barcelona champion

May 28th, 2009

I used this page to find links for the match and downloaded SopCast from here.

I believe channel 6001 was the one I used after having tried a few others that was offline.

Justin.TV did not work as they said the quota for my country was full and I would have to pay to see the game.

BBC radio did not stream the match! However, RTVE and NRK did.

Another data loss

May 27th, 2009

Last week my 300GB external hard disk died on me. Most of the data on the disk were backuped elsewhere, but not all. Stupid me!

To avoid future data loss I bought a 8GB usb drive and two external WD My Passport Essential 500GB hard drives. The hard drives take their power from the USB2 port so AC adapters are not needed.

On the usb drive I store all the data I am currently working on. Daily I take a backup of the drive to the hard drive on my laptop. To keep the data on the usb stick is very practical as I work on the data both at home and at work.

Data I do not longer work on I archive to one of the 500GB drives. The second 500GB drive is a synchronised copy of the first. If a file is deleted from the first, it is deleted from the second.

By the way, Mediafire offers unlimited free data storage while Mozy gives for free a program that automatically backups 2GB of your data to their online servers.

18,000 files compared

May 26th, 2009

I ran the program CompareFiles and found 35 files out of 18,838 that had not been copied. Nice to know when one is doing archiving.

Speeding things up

May 26th, 2009

If your computer is slow try these free programs to speed things up.

All of the programs, except the last one, are from this page:

Get rid of the crap:

21. CCleaner: a fantastic hard drive cleaner that can rid your system of temp files, internet traces such as your surfing history, cookies, logfiles, cached files and other unused files from your computer. Installer comes with Yahoo toolbar included, so be careful to uncheck that during the installation process so it doesn’t install on your computer. Also includes a registry cleaner.

Make it faster for the machine to load and save files:

17. JKDefrag GUI: this is the graphical user interface for JKDefrag a hard disk defragmentation program. There are 3 reasons why you should use this program (a) JKDefrag has recently been tested and found to be the best amongst x different defragmentation programs, free and paid, (b) it provides the option to install itself as a screen saver, which will kick-off the defragmentation process whenever your computer is idle and goes into screensaver mode, and (c) it is fast and delivers excellent performance (see this blog for an interesting comparison of free and commercial defraggers, where JKDefrag was deemed the best freeware defrag program)..

Sweep your ram:

45. SweepRAM: a tiny, no-install RAM optimizer that frees system RAM by allowing applications all the RAM that they need, but no more (i.e. does not deprive programs from RAM). Use it to free RAM whenever your available memory plummets and/or your system becomes sluggish.

Where did all the hard drive space go? Part I:

18. Folder Size: this free Windows Explorer extension provides a “Folder Size” column in Windows explorer’s ’Detail’ view that shows the size of both files and folders (Windows shows the size of files but not that of folders). My second choice for a for a free program that does this would be “Aurionix FileUsage“; the latter offers more columns but requires .NET and therefore much more resources than Folder Size does.

Where did all the hard drive space go? Part II:

SpaceSniffer is a freeWare (or, better, donationWare) and portable tool application that gives you an idea of how folders and files are structured on your disks. By using a Treemapvisualization layout, you have immediate perception of where big folders and files are situated on your devices. Treemap concept was invented by Prof. Ben Shneiderman, who kindly permitted the use of his concept into this tool.

Update May 27:

You may also like to update your drivers:

Like any software, drivers are upgraded and updated by the manufacturers, to remove bugs, add extra functionality to the hardware or to improve the performance of the device. Unless you update your drivers regularly you may face problems ranging from the relatively minor, such as having hardware that seems buggy and poorly performing, to the more major such as hardware failures, conflicts and complete system crashes.

A free program can be found at http://www.liutilities.com/products/campaigns/affiliate/offer/gen/ds/. The program scans for outdated drivers and if you pay $29.95 you can get the new drivers downloaded automatically.

If you have other suggestions, please type a comment below.

Episodes from a digital world

May 24th, 2009

I have been copying files today and it made me feel real dumb. Read on and you see why.

1. I was copying 6GB to a USB drive and was told it would take 139 minutes. I have only USB 1 so I have to live with low speed so I went for a walk. When I returned two hours later the machine had done 3 minutes of work and flashed questions like these on me:

xxx is a read only file, do you want to copy it?

You stupid cow! Why didn’t you ask me that before you started copying? Give me all options before you copy and when I return from my walk you will have completed the job.

2. I was copying 6GB to a USB drive. After 55 minutes a message appeared:

The file xxx can not be copied. It is corrupt. Press OK.

I pressed OK and what happened? Did it skip the file and copy the next? No way! It just stopped, leaving me to find out which files had been copied and which had not.

3. The error message at the top I take to mean that Windows XP can only copy files that do not exist. There are possibly better interpretations, but life is too short for me to find out.

So why did all this copying make me feel dumb. It made me feel dumb since I am a typical member of a race that buys Windows more than any other operating system in spite of its unfriendliness and sheer insulting behaviour.

Update 25 May:

I downloaded Teracopy today:

TeraCopy is a free utility designed to copy/move files faster and more secure. TeraCopy can resume broken file transfers. TeraCopy skips bad files during copy and even shows the skipped files at the end of files transfer. Calculates files CRC checksum on the fly to speed up source and target files comparison. Seamless integration with Windows Explorer allows you to keep working with files as usual.

Time for a new laptop

May 9th, 2009

Five years ago I bought a Gateway Laptop in Miami. It was just before Gateway closed all their retail shops. I paid around USD 1500 for a machine I have been extremely happy with. 

Today I can buy Gateway’s T-6345u for USD 430 + freight. Comparing my old machine with this new one is staggering. The Ram goes from 512Mb to 2GB, the hard disk goes from 60GB to 320GB, the weight drops to 2.5kg! Battery life = unknown.

Then I read this that made me think again ordering a Gateway product.

Here are the most popular portable computers at Amazon.com.