Archive for the 'Actionscript' Category

16
Aug
11

Textfield scaling issue

Thought I’d post about this issue unless anyone else comes across something similar and needs a fix.

On a recent site I worked on (www.sky.com/bintm) i’m scaling the content when the user goes into FullScreen mode to make use of slightly higher res photo assets available.

This knocks the double column text article page out of whack. Essentially scaling a movieclip with a dynamic textfield in it results in a different textHeight and numLines being traced for the same textfield dependent on whether you’re in FullScreen mode or not.

After a bit of hunting I came up with the following fix - setting the gridFitType property of the textfield to GridFitType.SUBPIXEL . I tried GridFitType.PIXEL but that still gave different results dependent on the users screen mode.

08
Jul
11

FullScreen Flash mask gotcha

Long time between posts… but thought I’d document this so that anyone else coming across the issue can get a quicker fix than I found.

The problem I was having was with a masked area that wasn’t resizing along with the rest of the content when stage.displayState = StageDisplayState.FULL_SCREEN

The fix for this was to ensure that the mask was actually added to the stage before being applied to the DisplayObject you wanted to mask. Here’s some code:

var __mask:Shape = new Shape();
__mask.graphics.beginFill(0xffcc00, 1);
__mask.graphics.drawRect(GRAPH_X, GRAPH_Y - 40, GRAPH_WIDTH, GRAPH_HEIGHT+39);
__mask.graphics.endFill();
addChild(__mask);
_barsHolder.mask = __mask;

The fix wasn’t entirely obvious as masks don’t generally need to be added to the DisplayList to function properly. Obviously when you’re having the Flash go fullscreen you do.

Hopefully that helps someone else avoid the issue I was having.

16
Jun
10

FileReference.load() - keep it in scope!

Just a quick note (possibly to self) that when dealing with FileReference you need to ensure that the scope of the FileReference is maintained. This was mentioned in the Actionscript documentation, but it took me a while to figure out that that could be the problem for my code failing silently. Originally I thought it was because I wasn’t using the right playerglobal.swc from within Flex, or that I couldn’t export using Flex SDK 3.2 (as this method is a Flash Player 10 one). It took me a while to reread the documentation for the load method and comprehend that perhaps I needed to declare some instance variables instead of local ones. Some code will hopefully illustrate what I mean:

public function uploadImage():void
{
	var __imageTypes:FileFilter = new FileFilter("Images (*.jpg, *.jpeg, *.gif, *.png)", "*.jpg; *.jpeg; *.gif; *.png");
	var __fileRef:FileReference = new FileReference();
	try	{
		__fileRef.addEventListener(Event.SELECT, onFileSelect);
		__fileRef.addEventListener(Event.COMPLETE, onFileOpen);
		__fileRef.browse([__imageTypes]);
	} catch (error:Error) {
		trace("Unable to browse for files.");
	}
}

private function onFileSelect(event:Event):void
{
	trace("onFileSelect called");
	var fileRef:FileReference = event.target as FileReference;
	fileRef.load();
}

private function onFileOpen(event:Event):void
{
	trace("onFileOpen called");
	var fileRef:FileReference = event.target as FileReference;
	var data:ByteArray = fileRef.data as ByteArray;
	var encoder:Base64Encoder = new Base64Encoder();
	encoder.encodeBytes(data);
	trace(encoder.toString())
}

The problem with that code is that the original __fileRef variable is only available within the uploadImage function. As soon as onFileSelect is triggered (which works fine), fileRef (a new local variable within this function) trys to call load(). This was failing silently for me.

So instead of declaring the original __fileRef variable as a local one, I’ve declared it as a private variable in the class. That way it’s always in scope!




Categories

Recent Comments

Posts this month

February 2012
M T W T F S S
« Nov    
 12345
6789101112
13141516171819
20212223242526
272829  

Archives