Dodona gives you answers

Archive for the ‘Actionscript’ Category

How can I adjust letter spacing with sIFR 2?

leave a comment »

I know, sIFR 3 allows you to style your text, including letterspacing. But I had to update an older website using sIFR 2.0.7 and also had to adjust the letter spacing. So I wondered; is there a way to do this without upgrading to sIFR 3? Yes there is:

  • First, edit “dont_customize_me.as” and place the following code at line 92:
    if (letterSpacing != null) fmt.letterSpacing = Number(letterSpacing);
  • Next, edit “sifr.js” on line 7:
    Where it says “var a=6;” change the 6 to an 8. This ensures that you’re detecting for Flash v8.
  • Where you make your replacement calls add the following to sFlashVars:
    sFlashVars:"textalign=center&offsetTop=6&letterSpacing=3"
  • Lastly, be sure to save your font SWFs as Flash 8, with Actionscript 2.0 enabled using the “Publish Settings…” menu.

But, this only works for titles of 1 line long. Longer titles won’t wrap anymore but will be scaled down instead. To fix this I guess you still have to upgrade to sIFR 3.

Link: discuss.joyent.com/viewtopic.php?pid=102296
Status: Tested it, works, line wrapping is broken.

Advertisements

Written by lutsen

April 21, 2010 at 2:44 pm

Posted in Actionscript, Web

How do I generate an EPS or a vector based PDF from an SWF?

leave a comment »

Well, you don’t. Nowadays it’s very well possible to generate a JPG or other pixel-based format with an SWF, and with some server-side scripting to turn it in to a PDF. But all the images will still be pixel-based.

But after some surfing, I found out the way to vectors is SVG (Scalable Vector Graphics). And after some more surfing, I found Degrafa. This is an open source declarative graphics framework in Flex. And with it, it looks relatively easy to generate a SVG image from Flex (example). And an SVG image can be converted to a PDF serverside or clientside, or edited in programs like Adobe Illustrator.

So, no (vector based) PDF from an SWF, but an SVG from Flex; that’s pretty close.

Status: Didn’t test it yet, but looks promising
Link: http://www.degrafa.org/

Written by lutsen

December 29, 2009 at 10:16 am

Posted in Actionscript, DTP, Web

How do I redirect a non www address to a www address?

leave a comment »

In my case, I built a Flash site with SWFAddress to allow deeplinking. The downside to this was the site didn’t work well if a user used a URL like exaple.com instead of www.example.com.

If your site runs on an Apache server, you can use .htaccess to redirect all users visiting a example.com URL (without the www) to a www.example.com URL (with the www). This is the code you need:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]

Put it in a file named .htaccess, upload it to the root directory of your website, and your good to go.

Link:
www.stepforth.com/resources/web-marketing-knowledgebase/non-www-redirect

Written by lutsen

December 9, 2009 at 2:13 pm

Posted in Actionscript, Web

How do I program a random value of either 1 or -1?

leave a comment »

In in my case actionscript or any other programming language, you might want to code a random value to be either 1 or -1, for example to randomly have an object rotate clockwise or counter-clockwise. This is how you can get this value in actionscript:

var randomDirection:Number = Math.round(Math.random())*2-1;

Now the randomDirection variable will always be either 1 or -1.

Written by lutsen

December 8, 2009 at 11:34 pm

Posted in Actionscript

How do I prevent a textfield in Actionscript from scrolling 1 line when it shouldn’t scroll?

leave a comment »

There is a strange bug in Actionscript which makes a textfield which shouldn’t scroll still scroll one line. I only found this bug in Windows and only when scrolling using the scroll-wheel.
The code below, although not very beautiful, will prevent the textfield from scrolling. I found it here.

myTextField.addEventListener(Event.SCROLL, onScroll);

function onScroll(evt:Event):void {
    myTextField.scrollV = 0;
}


Link
: http://www.kirupa.com/forum/showthread.php?t=288955

Status: Tested it, works

Written by lutsen

September 12, 2008 at 11:28 am

Posted in Actionscript

How can I convert vector drawings to actionscript code?

leave a comment »

This on-line tool extracts shapes from Flash .swf files and returns them in a format which can be rendered by actionscript. This way you can manipulate drawn vector graphics with actionscript.

Link: Quasimondo’s Actionscript Shape Decoder

Status: Tested it, works

Written by lutsen

August 28, 2008 at 9:37 pm

Posted in Actionscript

How do I find and replace a string in actionscript 2?

leave a comment »

I use this findReplace function to replace a string in actionscript:


// (from http://proto.layer51.com/d.aspx?f=23)
var findReplace = function(searchStr:String, findStr:String, replaceStr:String) {
   var locationNum:Number = searchStr.indexOf(findStr, 0);
   while (locationNum != -1) {
      var sub1 = searchStr.substr(0, locationNum);
      locationNum += findStr.length;
      var sub2 = searchStr.substr(locationNum, searchStr.length);
      var searchStr = sub1 + replaceStr + sub2;
      var locationNum = searchStr.indexOf(findStr, sub1.length);
   }
   return(searchStr);
}

Status: tested it, like it

Link: I found this function here

Written by lutsen

August 19, 2008 at 11:37 am

Posted in Actionscript, Web