Advertisement

09.07.2008 at 11:31AM PDT, ID: 23710428
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

6.4

Flash AS3 Loaded images getting very distorted

Asked by MikeSven in ActionScript, Scripting Languages

Tags: , ,

Hey everyone,

I am working on a little personal project with AS3 and have run into some problems.  I am dynamicly loading some images from an XML file to be used as thumbnails on a little photography site that I am making.  Everything seems to be working perfect except for the fact that when I try to position the "container(sprite)" that is holding all of the thumbnails, the images seem to get very streaky and almost look more like complicated gradients.  I was wondering if anyone had come across something like this before?  I also find it very strange because i am using the loaded image to create a snapshot in order to make the a reflection, and the reflections seems to look perfect, even though the thumbnail is distorted.  I have a current working sample of the error up at http://www.mikesvendsen.net.  Any help that can be provided would be greatly appreciated.  I will also include below the code i am using for my image class.

Thanks

Michael Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
package net.mikesvendsen.photography {
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.DisplayObject;
	import flash.display.GradientType;
	import flash.display.Loader;
	import flash.display.Shape;
	import flash.display.SpreadMethod;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.events.ProgressEvent;
	import flash.filters.BlurFilter;
	import flash.geom.Matrix;
	import flash.net.URLRequest;		
 
	public class Thumbnail extends Sprite {
		
		internal var   container:Sprite;
		internal var   imageContainer:Sprite;
		internal var   reflectionBMPRef:DisplayObject;
		internal var   fileName:String;
		internal var   imageLoader:Loader;
		internal var   imageRequest:URLRequest;
		
		internal var   background:Shape;
		internal var   progBar:Shape;
		
		internal const thumbWidth:Number  = 75;
		internal const thumbHeight:Number = 50;
		
		public   static const THUMB_CLICK:String = "this thumbnail has been clicked";
 
		public function Thumbnail(fileToUse:String) {
			
			fileName = fileToUse;
			
			createInitialClip();
			
		}
		
		private function createInitialClip():void{
			
			container = new Sprite;
			
			imageContainer = new Sprite;
			
			background = new Shape();
			background.graphics.beginFill(0x000000, .45);
			background.graphics.drawRect(0, 0, thumbWidth, thumbHeight);
			background.graphics.endFill();
			
			progBar = new Shape();
			progBar.graphics.beginFill(0x000000, .45);
			progBar.graphics.drawRect(0, 0, thumbWidth, 10);
			progBar.graphics.endFill();
			
			imageContainer.addChild(background);
			imageContainer.addChild(progBar);
			container.addChild(imageContainer);
			addChild(container);
			
			imageRequest = new URLRequest("images/" + fileName);
			imageLoader = new Loader();
			imageLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, handleLoadProgress);
			imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, handleImageComplete);
			imageLoader.load(imageRequest);
		}
		
		private function handleImageComplete(e:Event):void{
			imageContainer.addChild(imageLoader.content);
			imageLoader.content.width = thumbWidth;
			imageLoader.content.height = thumbHeight;
			addFunction();
			createReflection();
		}
		
		private function addFunction():void{
			imageContainer.addEventListener(MouseEvent.CLICK, handleClick);
		}
		
		private function handleClick(e:MouseEvent):void{
			 dispatchEvent(new Event(THUMB_CLICK));
		}
 
		private function handleLoadProgress(e:ProgressEvent):void{
			progBar.scaleX = e.bytesLoaded / e.bytesTotal;
		}
		
		private function createReflection():void{
			var refContainer:Sprite = new Sprite();
			var refBMP:BitmapData = new BitmapData(thumbWidth, thumbHeight, true, 0x000000);
			refBMP.draw(imageContainer);
			var reflectionBMP:Bitmap = new Bitmap(refBMP);
			reflectionBMPRef = refContainer.addChild(reflectionBMP);
			
			container.addChild(reflectionBMPRef);
			reflectionBMPRef.scaleY = -1;
			reflectionBMPRef.y = thumbHeight * 2;
			
			blurReflection();
		}
		
		private function blurReflection():void{
			
			var blurFilter:BlurFilter = new BlurFilter(3, 3, 5);
			reflectionBMPRef.filters = [blurFilter];
			addMask();
		}
		
		private function addMask() : void {
			var thumbMask:Sprite = new Sprite();
			thumbMask.x = reflectionBMPRef.x;
			thumbMask.y = reflectionBMPRef.y / 2;
			
			var fillType:String = GradientType.LINEAR;
			var colors:Array = [0x000000, 0x000000];
			var alphas:Array =[100, 0];
			var ratios:Array = [10, 225];
			var gradMat:Matrix = new Matrix();
			gradMat.createGradientBox(10, 10, Math.PI / 2, 0, 10);
			var spreadMethod:String = SpreadMethod.PAD;
			thumbMask.graphics.beginGradientFill(fillType, colors, alphas, ratios, gradMat, spreadMethod);
			thumbMask.graphics.drawRect(0, -30, thumbWidth, thumbHeight);
			thumbMask.graphics.endFill();
			container.addChild(thumbMask);
			reflectionBMPRef.mask = thumbMask;
			reflectionBMPRef.alpha = .5;
		}
	}
}
[+][-]09.08.2008 at 05:37AM PDT, ID: 22416631

View this solution now by starting your 14-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: ActionScript, Scripting Languages
Tags: Action Script 3.0, any, http://www.mikesvendsen.net
Sign Up Now!
Solution Provided By: MikeSven
Participating Experts: 0
Solution Grade: A
 
 
 
Loading Advertisement...
20081112-EE-VQP-43 / EE_QW_2_20070628