DESIGN CORTEX DEV BLOG

Developer Blog of Nicholas Dunbar
code tid bits, graphics and other things I'm working on at www.designcortex.com

Tuesday, March 13, 2007

I've started adding textures to reflective objects inorder to give them a feeling of being dirty or in this case burned at the bottom. 3-D does reflections too perfectly and so I find that applying a post-filter blur upon the reflections in addition to adding some tarnishing with gaussian blured textures will create a much more realistic representation.

3D winter landscapes using displacement maps

I've been working with displacement maps in Photoshop to create snow effects along with layering in procedural bumpmaps. I can also use the snow displacement map to mask outparts of the proceduralyou can see this where the snow ends and the new textures begin.

Customizing Flash Paper 2 with Actionscript

recently I set out to customize flash papers using actionscript. There is a lot of info on the web the best pages being http://www.adobe.com/support/documentation/en/flashpaper/2/flashpaper_api/
But they don't include very many examples of how to use the API. Here are a few things I figured out how to do.
First things first you need to properly load the flash paper into your parent swf:

function loadFlashPaper(path_s, dest_mc) {
 var intervalID = 0;
 var loadFunc = function () {
  dest_mc._visible = false;
  var fp = dest_mc.getIFlashPaper();
  if (!fp) { 
   //what ever was loaded is not a flash paper and does not contain a valid flash paper API
   return;
  }
  dest_mc._visible = true;
  clearInterval(intervalID);
 };
 intervalID = setInterval(loadFunc, 100);
 dest_mc.loadMovie(path_s);
}

once its loaded you can do a variety of things.

Use a listner to use my own font for the zoom percentage text:

var fp = holder_mc.getIFlashPaper();
var zoomNotifier:Object = new Object();
zoomNotifier.onZoomChanged = function(percent:Number):Void {
 percent = Math.round(percent);
 zoom_mc.zoom_txt.text = percent+"%";
};
fp.addListener(zoomNotifier);

zoom_mc is my own custom movie that is controlled by the flash paper API listner, you can use the available listners to customize most any part of the UI.

Remove that flash paper logo that links to adobes web site:

holder_mc.toolbar_mc.brandClip_mc._visible = false;

Remove the tool bar completely so that you can rebuild it in your own image:

holder_mc.toolbar_mc._visible = false;

or disable different parts of the tool bar:

fp.showUIElement("Tool", false);
fp.showUIElement("Find", false);
fp.showUIElement("Pop", false);
fp.showUIElement("Overflow", false);

if you are having focus issues when using multiple flash papers in the same window you can use code like this in each flash paper container and just trigger focused to true or false when one is clicked or rolled over. The lastScrollValue var is to keep the enableScrolling from being called every loop. You could use an interval here but I like using movies because they unload themselves once they are moved off stage.

this.createEmptyMovieClip("looper_mc", this.getNextHighestDepth());
focused_bl = true;
lastScrollValue_bl = true;
looper_mc.onEnterFrame = function() {
 if (!focused_bl && lastScrollValue_bl) {
  fp.enableScrolling(false);
  lastScrollValue_bl = false;
 } else if (focused_bl && !lastScrollValue_bl) {
  fp.enableScrolling(true);
  lastScrollValue_bl = true;
 }
};

Controlling the scroll bars and the viewable area inside the flash paper.
If have a document that you want to make zoom in on a certain area using actionscript you need to use the getVisibleArea() object.

here is an example:

visArea_obj = new Object();
visArea_obj = fp.getVisibleArea();
//fnExtractObjVars(visArea_obj);
visArea_obj.x = 97.37;
visArea_obj.y = 82.677;
visArea_obj.w = 620.47;
visArea_obj.h = 285.03;
visArea_obj.s = 0;
fp.setVisibleArea(visArea_obj);

Now you might ask what is this commented out fnExtractObjVars?
In the white papers for the flash paper 2 API they don't really cover the ins and outs of the returned object so did an object dump to determine what is inside so that I could manipulate the variable. My advice is to load the flash paper with its working tool bar and everything and zoom to the location you want and position the page how you want by hand then have fnExtractObjVars tied to a button and trace out all the values you need then go back and put them into actionscript. The function fnExtractObjVars goes like the following:

function fnExtractObjVars(theObj:Object) {
 for (var i in theObj) {
  fnErrorMessage(i+" : "+theObj[i]);
 }
}

Finally something I found that I couldn't do. You might want to know about using action script to load things into the actual tool bar. This is somewhat of a mystery for me because I spent many hours trying to go in and load movies in dynamically. I used code like this:

holder_mc.toolbar_mc.createEmptyMovieClip("coverholder_mc",holder_mc.toolbar_mc.getNextHighestDepth());
this.holder_mc.toolbar_mc.attachMovie("Fcover", "brandClip_mc",this.holder_mc.toolbar_mc.brandClip_mc.getDepth());

so if you are attempting such things and finding your objects not being created inside of the flash paper document hierarchy then you are not alone. If you have found a way to do this than please do share with us. but when I would run debug they never showed up. They loaded fine anywhere outside of the flash paper but it was as if Macromedia had locked everything from being messed with.