[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[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!

8.9

Need help creating a mask using ActionScript 3.0

Asked by dyarosh in ActionScript, Adobe Flash, Web Development, Web Development, Web Development Software

I am new to Flash and am trying to do something that I think should be simple.  I am loading pictures from an XML file using AS3.  What I want to do is to put an irregular border around the picture and show only the part of the picture that is within the border.  

When I was testing this I started by putting a picture on the stage on a layer and then putting the border on another layer and setting the layer as a mask.  The picture displayed the way I wanted.

Now I'm loading the picture dynamically onto the stage and want to apply the mask but I can't figure out how to do it.  Any help would be greatly appreciated.

In the code below, picMask is a movieclip on the stage that has the border in it.
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:
import fl.transitions.Tween;
import fl.transitions.easing.*;
 
var imageX:XML;
var imageList:XMLList;
var preload:preloader = new preloader();
var sortArray:Array = new Array();
var zSpacing:Number = 0;
var currentImage:Number;
var currentMaskee:MovieClip;
var currentMask:MovieClip;
 
var picTimer:Timer = new Timer(5000);
picTimer.addEventListener(TimerEvent.TIMER, nextPic);
 
var images_mc:MovieClip = new MovieClip();
images_mc.visible = false;
addChild(images_mc);
var req:URLRequest = new URLRequest("images.xml");
var imageLoader:URLLoader = new URLLoader();
imageLoader.addEventListener(Event.COMPLETE, onComplete);
imageLoader.load(req);
root.transform.perspectiveProjection.projectionCenter = new Point(0,0);
 
function onComplete(e:Event):void
{
	imageX = new XML(imageLoader.data);
	imageList = new XMLList(imageX.image);
	for (var i:uint=0; i < imageList.length(); i++)
	{
		var pic:Picture = new Picture(imageList[i].url);
		pic.x = 0;
		pic.y = 0;
		pic.z = i * zSpacing;
		images_mc.addChild(pic);
		sortArray.push(pic);
	}
	
	sortArray.sortOn("z", Array.NUMERIC | Array.DESCENDING);
	for (var j:uint = 0; j<sortArray.length; j++)
	{
		images_mc.setChildIndex(sortArray[j],j);
	}
	currentImage = sortArray.length - 1;
	preload.x = stage.stageWidth/2 - preload.width/2;
	preload.y = stage.stageHeight/2 - preload.height/2;
	preload.bar_mc.scaleX = 0;
	addChild(preload);
	preload.addEventListener(Event.ENTER_FRAME, preloading);
}
 
function preloading(e:Event):void
{
	var totalPct:Number = 0;
	for (var i:uint = 0; i < sortArray.length; i++)
	{
		totalPct += sortArray[i].pctLoaded;
	}
	var avg:Number = totalPct / sortArray.length;
	preload.bar_mc.scaleX = avg;
	
	if (avg >= 1)
	{
		images_mc.visible = true;
		images_mc.mask(picMask);
		preload.removeEventListener(Event.ENTER_FRAME, preloading);
		removeChild(preload);
	
		// Change pictures every 5 seconds
		picTimer.start();
		
	}
}
 
function maskPicture(e:Event):void
{
	images_mc.mask(picMask);
	
}
 
function nextPic(e:TimerEvent):void
{
	for (var i:uint=0; i<sortArray.length; i++)
	{
		if (i == currentImage)
		{
			sortArray[i].z = (sortArray.length-1)*zSpacing;
			images_mc.setChildIndex(sortArray[i],0);
		}
		else
		{
			var startZ:Number = sortArray[i].z;
			var endZ:Number = startZ - zSpacing;
			new Tween(sortArray[i],"z",Regular.easeOut,startZ,endZ,12,false);
		}
	}
	if (currentImage > 0)
	{
		currentImage--;
	}
	else
	{
		currentImage = sortArray.length - 1;
	}
}
 
function onTick(event:TimerEvent):void 
{
	// displays the tick count so far
    // The target of this event is the Timer instance itself.
    trace("tick " + event.target.currentCount);
}
 
Related Solutions
Keywords: Need help creating a mask using Actio…
 
Loading Advertisement...
 
[+][-]10/20/09 11:29 PM, ID: 25621175Accepted Solution

View this solution now by starting your 30-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, Adobe Flash, Web Development, Web Development, Web Development Software
Sign Up Now!
Solution Provided By: blue-genie
Participating Experts: 1
Solution Grade: A
 
[+][-]10/05/09 03:57 AM, ID: 25494026Administrative Comment

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 30-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]10/05/09 03:58 AM, ID: 25494028Administrative Comment

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 30-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]10/06/09 07:17 AM, ID: 25505286Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10/06/09 10:20 AM, ID: 25507430Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10/19/09 01:17 AM, ID: 25603335Administrative Comment

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 30-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]10/19/09 10:38 PM, ID: 25611261Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10/20/09 09:52 AM, ID: 25616042Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10/21/09 05:57 AM, ID: 25623412Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10/21/09 10:42 PM, ID: 25631099Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-92 - Hierarchy / EE_QW_3_20080625