Jump to content
Search Community

Adding a mask when loading via getContent?

mspanish test
Moderator Tag

Recommended Posts

I know this has something to do with .content vs .rawContent, but I can't seem to get a mask working on a loaded image! Since these thumbs are in a grid that the user uses to drag onto another object, I need the mask to load onto the thumb itself - but I'd rather mask whats INSIDE the thumb and not the thumb itself... anybody see the error here? Thanks in advance!

 

Here is my code:

 

var thumb:ContentDisplay = LoaderMax.getContent(thumbnailBigArray);

thumb.scaleMode = "proportionalInside"

 

grid_holder.addChild(thumb);

 

thumb.width = thumbWidth;

thumb.height = thumbHeight;

thumb.x = (i % thumbCols) * (thumbWidth + padding) + 10;

thumb.y = int(i / thumbCols) * (thumbHeight + padding) + 0;

 

if (needsMask == "yes") {

 

var loader3 = new SWFLoader($.subject + '/' + windowType + '_mask' + '.swf', {x:5, y:5,height:thumbHeight-35,width:thumbWidth-35});

thumb.addChild(loader3.content); //add the ContentDisplay to the display list even before raw content is loaded.

thumb.mask = loader3.content;

loader3.load();

}

thumbArray.push(thumb);

Link to comment
Share on other sites

Hey Stacey,

 

nothing jumped out at me as being wrong with your code.

i made a very simple example very similar to what you provided:

 

import com.greensock.*;
import com.greensock.loading.*;
import com.greensock.events.LoaderEvent;
import com.greensock.loading.display.ContentDisplay;

var image:ImageLoader = new ImageLoader("f.jpg");
image.load();



var thumb:ContentDisplay = image.content;
addChild(thumb);

var circleMask:SWFLoader = new SWFLoader("circleMask.swf");

TweenMax.to(thumb, 2, {x:300, repeat:-1, yoyo:true});

thumb.addChild(circleMask.content);
thumb.mask = circleMask.content;

circleMask.load();

 

didn't have any problems.

 

i attached the files if you want to see it in action.

 

-c

  • Like 1
Link to comment
Share on other sites

Hey Carl - thanks for that - hope you are doing great over there in the big city :)

 

I actually figured out the problem was trying to use just 1 mask loaded as a SWF for a whole array of thumbs. This is probably as UNelegant as it gets, but here was my solution:

I call this after all the thumbs are loaded - and it's working pretty sweet now.

 

var loader3

 

function addThumbMasks():void {

trace('thumbMask function thumbArray = ' + thumbArray.length);

for (var i:int = 0; i < thumbArray.length; i++) {

loader3 = new SWFLoader($.subject + '/' + windowType + '_mask' + '.swf', {x:5, y:5,height:thumbHeight-35,width:thumbWidth-35,scaleMode:"proportionalInside"});

loader3.load();

maskLoadersArray.push(loader3);

}

TweenMax.delayedCall(.1,onLoadSWF);

}

 

var mcArray:Array = [];

 

function onLoadSWF():void {

 

for (var i:int = 0; i < thumbArray.length; i++) {

var mc:MovieClip;

mc = maskLoadersArray.rawContent; //the root of the child swf

mcArray.push(mc)

}

TweenMax.delayedCall(.1,addMasksNow)

trace('mcArray check ' + mcArray)

}

 

function addMasksNow():void {

for (var i:int = 0; i < thumbArray.length; i++) {

if (thumbArray!= null && mcArray != null) {

thumbArray.addChild(mcArray); //add the ContentDisplay to the display list even before raw content is loaded.

thumbArray.mask = mcArray

thumbArray.visible = true;

}

}

}

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...