Archive for the ‘flash, actionscript, flex’ Category

h1

firefox, swfobject and zotero not playing well together

October 29, 2009

Argh. Four steps back, none forward, can we start over today?

Couldn’t get a swf to display in Firefox today. Found out pretty quickly that it had to do with the swfobject code used to embed it. Search search read read argh argh. Some folks with similar probs found out that they had to put the swfobject js code in the head section of the html page. That’s where mine was. Search search read read argh argh. Aha, plugins. Disabled the latest one, zotero. Bingo.

Looks like Firefox 3.5.4 with Zotero 1.0.10 plugin and the swfobject.js do not play well together. Zotero has been sent to sit in the corner.

 

Thanks to this post for turning the lightbulb on: http://activeden.net/forums/thread/problem-with-swfobject-on-firefox/14944

h1

easily resize flash stage dynamically: BrowserCanvas rocks

March 24, 2009

Over at doesnotcompute the headline reads: “BrowserCanvas. The World’s Easiest Way to Dynamically Resize Flash”. It’s true.

A few months back I looked into this in preparation for a current project. Checked it out, put it aside for later. Now is later, and the proof is in: this is really easy to implement. It took no time to integrate the BrowserCanvas class into my code and use it successfully. Very very nice.

Noel Billig, maker of BrowserCanvas, mentions a few things that you have to have set right to make it work. Reiterating what I needed to do here, just for convenience:

First, the stage settings:

stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = stage.align = StageAlign.TOP_LEFT;

Then, if you want to view the effects locally (from a file, not over http), you need to set the security for your Flash player accordingly.

That’s it. It’s very satisfying to use a tool like this and have it all go so smoothly. I needed that. Thanks Noel!  :)

h1

textarea component’s textformat style is case sensitive – sometimes

January 27, 2009

This one cost me a few hairs, so I’m jotting it down in case it can save someone else some time (like me, down the line).

In a TextFormat object, verdana is not the same as Verdana. Duh! But the flash stand alone player might make you think it is…

I’m working with a couple CS 3 textarea components, adding them to stage from code (AS 3), and updating the text at runtime (fed from an XML file).

Using the CS 3 compiler, and therefore the stand alone player to view the compiled swf, all looked fine. So far so good. But when looking at the swf embedded in an html page, all of a sudden all the fonts were off. The TextFormat’s font was not sticking. Search, scratch, search, argh.

It didn’t seem to make sense that the stand alone player was displaying the font as desired, but the plug-in player didn’t pick up the style.

It was a stupid spelling error: myTextFormat.font = "verdana" ;
The stand alone player didn’t care, somehow it figured it out. The plug-in player didn’t like it though, and reverted to a default text style.
The fix: myTextFormat.font = "Verdana" ;

Like I said. Duh! Lunchtime, finally.

h1

launch windows apps with quicksilver

January 5, 2009

Another post-it note to self…

Yeah! It’s possible to launch a windows app (in vmware fusion) from your mac using quicksilver. Thanks to Shayne at http://shayne.powerlot.net/2008/07/23/vmware-fusion-apps/

The only app I’m accessing like this so far is Flash Develop.

h1

your mouse on drugs

September 2, 2008

Here’s a really fun example of e-learning. Those poor (really?) mice…

[Update] After watching this a couple times and sending the link along for others to see, it occurred to me that the Mouse Party is an excellent example of what you can do to solve the problem of voice-over versus text on screen. The basics of multimedia learning tell us that stuffing users’ brains with voice-over to hear and text to read at the same time leads to cognitive overload: not good for learning!

The Mouse Party shows a nice in between solution for this: first you get the sound, then the text appears. For something as complex as neurological connections, even in this simplified form, it is helpful to have time to read the info – after you’ve heard it. So the text and the sound don’t get in each other’s way.

I could have used that idea recently when asked by a client to record voice-overs for some educational slide shows. The content was not very complex, but the audience was mostly non-native English speakers, so allowing them read the text was important to the client. Unfortunately, they insisted that learners be bombarded with sound and text at the same time. Had I only visited the Mouse Party previously I could have done the voice-overs the same way: first the sound, then the text (paused, so there’s time to read it at your own pace). Live and learn… :)

Learn all about what goes on in lab mice’s brains:

http://learn.genetics.utah.edu/units/addiction/drugs/mouse.cfm

h1

pdf and flash add-ons – love firefox 3!

July 6, 2008

One thing that I (used to) miss when I come home to my Mac after working on a Windows machine all day: viewing pdfs directly in the browser. Found a pdf browser plug-in, but it didn’t work on intel macs. Sigh.

firefox

But wait: there is a solution, but you have to download Firefox 3 first. That was enough for me,  I went ahead and got FF 3 so I could install the Add-on Quartz PDF Plugin. (Um, is that an Add-on or a plugin then? ;) ). Worked right away. Yes! Highly recommend it.

What was also really nice about installing FF 3 is that other Add-ons (plugins? extensions?) that got broken  had working alternatives. Flash Tracer, for example. And Delicious. And Resizable Text Area.

Then the real icing on the cake: Flash Switcher! I didn’t even know that existed for Mac!  Happy me. Grazie Alessandro (aka sephiroth.it, well known friend of Flashers :) ).

So what is the difference between a Firefox add-on, extension, and plug-in?

h1

actionscript sound: still hear volume set to negative value?

May 19, 2008

A negative volume is still audible? Wait, that can’t be.

Just got bit by this one today, so a little reminder for myself here. Using ActionScript 2 I was creating a little slider widget for controlling volume. Easy peasy, right? Get the position of a slider relative to a slider bar to calculate the volume. Then use setVolume on a Sound object to, well, set the volume.

So far so good. The catch came with those calculations, which are based on graphics with x positions that are not necessarily straight forward (talk to the graphics department, I’m on coffee break!). Sometimes the value I was getting came out negative… but the sound was still audible! Hmmm. Strange.

Well, not really. The docs tell you that the volume can range from 0 to 100. Zero. Not -1 or something. But you can “set” the volume to -1 with mySound.setVolume( -1 ). Yet you might still hear something…

Why’s that? It seems that if you do that (silly you!), the Sound object will play at the last volume it was set to. In this case that was a quiet 2 or so, depending on how fast the slider had been moved down. So if you’re setting the volume based on wacky calculations that come up with a value less than zero, you have to set that explicitly to zero before you set the sound’s volume. Easy peasy.

Why doesn’t it just work that way anyway?

h1

see actionscript trace() from swf running in the browser

April 15, 2008

It is possible to see your ActionScript trace statements when you run your swf in a browser. Definitely nothing new, but something that I come back to seldom enough that I need a reminder of the necessary steps. That’s the purpose of this: a quick list in note-to-self form, just so that all the steps and links are condensed in one place.

The main ingredients: Flash debug player, a flashlog.txt file, and Terminal (to see live changes). For the record, I’m on a Mac with OS X, no help for Windows here.

The basic steps:

  • 1. Uninstall player (if necessary) and install debug player
  • 2. Make sure you have flashlog.txt in /Users/your_user_name/Library/Preferences/Macromedia/Flash\ Player/Logs/
  • 3. Open Terminal in that Logs location, do tail -f flashlog.txt

That’s it. Watch your trace messages – or more fun, anyone else’s you surf upon – appear in the Terminal window.

For the first step… Both the player uninstaller and the debug installer are on this page http://www.adobe.com/support/flashplayer/downloads.html. A really helpful page to check whether installing the debug version actually worked is here: http://kb.adobe.com/selfservice/viewContent.do?externalId=tn_15507. Special bonus: it tells you explicitly whether you have the debug version or not. (Page seems broken now, hopefully that’s not permanent.)

The second step is about the file that the trace statements get written to. If you don’t have one there, just save a text file there with that name.

And finally, the third step lets you watch the changes live. Otherwise I found I needed to close and re-open the file to see new traces. So you’re actually using Terminal to watch what happens to the log file.

Thanks! to

http://www.digitalflipbook.com/archives/2005/07/trace_from_the.php (more details there if you want em)

h1

color profiles from illustrator to flash

February 25, 2008

I’m clueless about basic graphics, but have been dealing with some issues caused – apparently – by color profiles. After importing some illustrator files into flash, the colors were not being displayed correctly. The hex codes in the color palette were right, but when I saved and sent the file on to someone else, they were not seeing the right colors. (It wasn’t a monitor thing, since she could clearly see the difference between the right and wrong colors being displayed on her screen.)

So far I’m not much smarter, but I picked up a hint or two that I’m jotting down here as a “note to self”. Here’s what Nik says over at actionscriptdiary.blogspot.com:

  • Flash only has one colour profile: sRGB
  • Photoshop has loads and tends to use Adobe RGB
  • So when file comes into Flash, Flash ignore the colour profile and just uses sRGB
  • When opening a file in Photoshop, always choose to use the embedded colour profile
  • Then copy the file and convery (edit > convert to profile) and choose sRGB

    To be continued…

    OK, here’s another tip I found at the MacRumors forums. Here’s what Evo says:

    Flash has no color management. You need to bring in your images with their profile to ensure color consistency. A good way to do this is to assign the profile in Photoshop(Edit Menu–> Assign Profile) to the image and then import into Flash. Most of the time if you use Adobe RGB 1998 for web images, when you save for web, the colors get desaturated. However, if you use the sRGB profile, the colors are preserved when you choose save for web and import into Flash.

    Soooo, from where I’m sitting it looks like this… If you’re working with Photoshop or Illustrator files and importing them into Flash, you need to embed the color profile in the file in Photoshop or Illustrator before you import it into Flash. Which in some cases (like mine, when you don’t have these nifty but very expensive programs) you need to ask the person sending the files to you to do the embedding first. Hopefully that’ll do it!

    h1

    convert code in adobe flash 9 live docs to class file

    January 17, 2008

    Playing around with ActionScript 3.0 but haven’t bought Flash CS3? Me too. One day I will buy the update, because I like the combination of visual and coding tools. For now, though, my experiments with AS 3 are done using the free flex sdk and textmate (described previously).

    Thing is, the code samples in Adobe live docs assume we’re using the Flash IDE to compile it. It’s formatted to be copied and pasted onto a timeline frame. So I thought I’d jot down the steps necessary to get that code into shape for compiling with the sdk.

    As an example, I’ll use the code sample provided for the droptarget property (I got there via the AS 3 Language Reference > Movie Clip > Public Properties > show Inherited Public Properties). By the way, download the docs, the online live docs are not very lively, i.e. excruciatingly slow.

    The first step is to copy the sample code into a file, let’s name it DropTargetTest.as. Here’s what the sample code starts out like:

    import flash.display.Sprite;
    import flash.events.MouseEvent;
    
    var circle:Sprite = new Sprite();
    circle.graphics.beginFill(0xFFCC00);
    circle.graphics.drawCircle(0, 0, 40);
    
    var target1:Sprite = new Sprite();
    target1.graphics.beginFill(0xCCFF00);
    target1.graphics.drawRect(0, 0, 100, 100);
    target1.name = "target1";
    
    var target2:Sprite = new Sprite();
    target2.graphics.beginFill(0xCCFF00);
    target2.graphics.drawRect(0, 200, 100, 100);
    target2.name = "target2";
    
    addChild(target1);
    addChild(target2);
    addChild(circle);
    
    circle.addEventListener(MouseEvent.MOUSE_DOWN, mouseDown)
    
    function mouseDown(event:MouseEvent):void {
        circle.startDrag();
    }
    
    circle.addEventListener(MouseEvent.MOUSE_UP, mouseReleased);
    
    function mouseReleased(event:MouseEvent):void {
        circle.stopDrag();
        trace(circle.dropTarget.name);
    }

    If you try to compile that, you’ll get an error like this:

    Error: A file found in a source-path must have an externally visible definition. If a definition in the file is meant to be externally visible, please put the definition in a package.

    Can you tell what that means? It’s about the way AS 3 code needs to be in a package. So first step, add the package code, like this:

    package{
        // all that code up there}

    And compile again. Next error looks like this:
    Error: A file found in a source-path can not have more than one externally visible definition. circle;target1;target2;mouseDown;mouseReleased

    Hmmmm. Not sure what that tells us, but we need to put this all into a class anyway, so let’s do that now. So right after the import statements we’ll make a class called DropTargetTest, like this;

    package{
    
        import flash.display.Sprite;
        import flash.events.MouseEvent;
            class DropTargetTest{
                // the rest of the code that comes after the import statements
    
        }
    
    }

    OK, compile again… This time there’s a pile of errors about accessing undefined properties, like this:
    Error: Access of undefined property circle.

    circle.graphics.beginFill(0xFFCC00);
    ^
    Same for target1 and target2. Plus there’s a couple errors about possibly undefined methods, but we’ll get to that in a sec. First, let’s try something. Let’s separate out the declarations of objects and methods from where we actually use those objects and methods. What we need here is a constructor, the method that creates an instance of a DropTargetTest object. In the constructor we can then do things with the sprites and things we’re creating in this class.

    So we’ll declare the variables and methods outside the constructor, giving them an access modifier of private. Then we’ll create a constructor where we’ll move all the code that actually makes things happen with the variables and methods.

    Here’s what it looks like:

    package{
        import flash.display.Sprite;
    	import flash.events.MouseEvent;
    
    	class DropTargetTest{
    
                    // declare circle and co.
    		private var circle:Sprite = new Sprite();
    		private var target1:Sprite = new Sprite();
    		private var target2:Sprite = new Sprite();
    
    		// constructor, where we'll actually do things
    		public function DropTargetTest(){
    		    circle.graphics.beginFill(0xFFCC00);
    			circle.graphics.drawCircle(0, 0, 40);
    
    			target1.graphics.beginFill(0xCCFF00);
    			target1.graphics.drawRect(0, 0, 100, 100);
    			target1.name = "target1";
    
    			target2.graphics.beginFill(0xCCFF00);
    			target2.graphics.drawRect(0, 200, 100, 100);
    			target2.name = "target2";
    
                           	addChild(target1);
    		        addChild(target2);
    		        addChild(circle);
    
    		        circle.addEventListener(MouseEvent.MOUSE_DOWN, mouseDown) ;
    		        circle.addEventListener(MouseEvent.MOUSE_UP, mouseReleased);
    		}
    
                    // other methods, in this case callback methods for the circle
    		private function mouseDown(event:MouseEvent):void {
    		    circle.startDrag();
    		}
    
    		private function mouseReleased(event:MouseEvent):void {
    		    circle.stopDrag();
    		    trace(circle.dropTarget.name);
    		}
    	}
    }

    Now compile again. Whew, less than 20 errors, cool. The error now tells us about a possibly undefined method:
    Error: Call to a possibly undefined method addChild.
    addChild(target1);
    ^

    But wait a minute! Do we have to define addChild?! Yikes, no, that’s a “standard” method that we use to add display objects to the display list. So why doesn’t the compiler let us use that method? Hmmm. It’s not part of our class, that’s for sure. DropTargetTest only defines those 2 callback methods. Aha!

    Our class needs to use the methods available to any class using display objects, in this case Sprite. So we’ll have to extend our class, ie make it a subclass of Sprite, so we can use all its handy methods like addChild. Let’s try that.

    One the line where we declare our class, we’ll add the code to extend the Sprite class:

        class DropTargetTest extends Sprite {

    And now we compile again… Bring on those errors!

    Aha, no errors, but a few warnings. And they’re saying something about where the class and some methods will be scoped to:

    Warning: class ‘DropTargetTest’ will be scoped to the default namespace: internal. It will not be visible outside of this package.

    Same warning for the methods mouseDown and mouseRelease. Scope, hmmm. Sounds like we need to specify more explicitly what kind of access we want the class and these functions to have. Less make them public, like this, adding public to each declaration:

        public class DropTargetTest extends Sprite {
    
        public function mouseDown(event:MouseEvent):void {
    
        public function mouseDown(event:MouseEvent):void {

    See what the compiler thinks of that…

    Bingo! We got a swf compiled from the class file. If only we could add flash file to wordpress hosted blogs so you could see what it looks like. You’ll just have to do the conversion yourself.

    So to sum up what we need to do to move from timeline code from livedoc samples to class files:

    1. Add package code.
    2. Add a class declaration. Make sure the class extends Sprite (or MovieClip, if necessary).
    3. Create a constructor.
    4. Separate out variable and method declarations from code that uses them…
    5. …put the code that does stuff with the variables and methods into the constructor.
    6. Make variables private. Make the class and its methods public.

    Did I miss anything? Of course it waaaay quicker if you just grab that sample code from the docs and throw it on a timeline frame. But if you’re wanting to work with classes anyway, why not start playing with AS 3 classes?