Drag and drop game sort items to three targets - actionscript-3

Please I need some help. I have spent 2 weeks trying to make a drag and drop game In cs4 actionscript 3.0 and am about to give up. I have gotten help so far, but the best suggestion I got was try and start from scratch instead of decompiling someone else's work. so here it is
I have an array that looks like this
var answername:Array = new Array();
var answerdest:Array = new Array();
answername[0] = "gravel";
answerdest[0] = "1";
answername[1] = "Nuts and boltsl";
answerdest[1] = "1";
answername[2] = "water";
answerdest[2] = "2";
answername[3] = "gold";
answerdest[3] = "3";
answername[4] = "Iron";
answerdest[4] = "3";
I need three targets,
and the ability to place the name of the item in my array (this is just a short piece of it) on the screen, if it is dropped on the target matching the answerdest number tor that item it is placed in a column, and the next item my array appears. If not it returns to its starting position. This seems like it should be easy to do but I am not a computer teacher I am a science teacher that is trying to make something for my student to use. I have basic coding skills for cs4.
This is as far as i have gotten but can not Figure out how to get the drag and drop part to check if it is in the correct spot. And get to to create a new drag-able if the answer is correct.
I have created an answer target named "Answer1",
var objectoriginalX:Number;
var objectoriginalY:Number;
Atom.buttonMode = true;
Atom.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
Atom.addEventListener(MouseEvent.MOUSE_UP, dropObject);
Matter.buttonMode = true;
Matter.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
Matter.addEventListener(MouseEvent.MOUSE_UP, dropObject);
function pickupObject(event:MouseEvent):void {
event.target.startDrag();
event.target.parent.addChild(event.target);
}
var dropCount:int = 0;
var dbCount:int=0;
var dbutton0;
function dropObject (event:MouseEvent):void
{
{
event.target.stopDrag();
var targetName = Answer1;
trace (targetName);
var matchingTarget:DisplayObject = getChildByName(targetName);
if (event.target.dropTarget != null && event.target.dropTarget.parent == answerdest[1])
{
event.target.removeEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
event.target.removeEventListener(MouseEvent.MOUSE_UP, dropObject);
event.target.buttonMode = false;
alpha = .8
dropCount ++;
event.target.x = 10
event.target.y = (Number(dropCount) * 100);
trace ("hit");
trace (dropCount);
} else
{
event.target.x = 100;
event.target.y = 111;
trace ("miss");
}
}
}
var answername:Array = new Array();
var answerdest:Array = new Array();
answername[0] = "gravel";
answerdest[0] = "1";
answername[1] = "Nuts and boltsl";
answerdest[1] = "Answer1";
answername[2] = "water";
answerdest[2] = "2";
answername[3] = "gold";
answerdest[3] = "3";
answername[4] = "Iron";
answerdest[4] = "3";
text3
text3.text = answername[1];
var myText:TextField = new TextField();
Atom.addChild(myText);
myText.text = answername[1] ;
Thanks for your help. I do not know if I am even on the correct track to do what I need it to do.

partial answer
var answername:Array = new Array();
var answerdest:Array = new Array();
answername[0] = "gravel";
answerdest[0] = "1";
answername[1] = "Nuts and boltsl";
answerdest[1] = "Answer1";
answername[2] = "water";
answerdest[2] = "2";
answername[3] = "gold";
answerdest[3] = "3";
answername[4] = "Iron";
answerdest[4] = "3";
text3
text3.text = answername[1];
This is pretty messy. I'm going to show a slightly better way. Even my method here isn't the best, but it's similar enough to what you are doing to not be hard to adopt.
var answer:Array = [
{_name:"gravel",dest:"1"},
{_name:"Nuts and bolts",dest:"Answer1"},
{_name:"water",dest:"2"},
{_name:"gold",dest:"3"},
{_name:"Iron",dest:"4"}
];
text3 // what is this supposed to do? I didn't get rid of it. But just a string sitting in the middle of your code should be throwing an error. I'd get rid of it.
//text3.text = answername[1]; // now we have a better way!
text3.text = answer[1]._name;
I know this doesn't directly help solve your problem but let's clean up your code and eventually we will figure it out. I just couldn't explain this in just a comment.
var objectoriginalX:Number;
var objectoriginalY:Number;
Atom.buttonMode = true;
Atom.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
Atom.addEventListener(MouseEvent.MOUSE_UP, dropObject);
Matter.buttonMode = true;
Matter.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
Matter.addEventListener(MouseEvent.MOUSE_UP, dropObject);
function pickupObject(event:MouseEvent):void {
event.target.startDrag();
event.target.parent.addChild(event.target);
}
var dropCount:int = 0;
var dbCount:int=0;
var dbutton0;
function dropObject (event:MouseEvent):void
{
event.target.stopDrag();
var targetName = Answer1;
trace (targetName);
var matchingTarget:DisplayObject = getChildByName(targetName);
if (event.target.dropTarget != null && event.target.dropTarget.parent == answer[1].dest) // red flag here!
//dest is a String and .parent is a MovieClip.
//They can never be equal. This block of code would never run like this.
{
event.target.removeEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
event.target.removeEventListener(MouseEvent.MOUSE_UP, dropObject);
event.target.buttonMode = false;
alpha = .8
dropCount ++;
event.target.x = 10
event.target.y = (Number(dropCount) * 100);
trace ("hit");
trace (dropCount);
} else
{
event.target.x = 100;
event.target.y = 111;
trace ("miss");
}
}
var answer:Array = [
{_name:"gravel",dest:"1"},
{_name:"Nuts and bolts",dest:"Answer1"},
{_name:"water",dest:"2"},
{_name:"gold",dest:"3"},
{_name:"Iron",dest:"4"}
];
text3.text = answer[1]._name;
var myText:TextField = new TextField();
Atom.addChild(myText);
myText.text = answer[1]._name;

Related

AS3 set (maximum-)height of movieclip without scaling content

I am trying to set a maximum height of a Textfield, after which the Text will only be displayed if you scroll.
I know, that you cannot set the height of a textfield as it is protected. Therefore I put the Textfield inside a movieclip and wanted to set a height for that. However, if I do so, it rescales the text. Depending on the amount of text it not only gets ugly, but plainly unreadable.
function createInfoBox():void
{
for (var i:uint = 0; i < level_200_menu_NEW.numChildren; i++)
{
var button200 = level_200_menu_NEW.getChildAt(i);
button200.addEventListener(MouseEvent.CLICK, goBack);
}
while (infobox_MC.numChildren)
{
infobox_MC.removeChildAt(0);
}
// Create a new instance of the _agilita_str symbol from the document's library.
var myFont:Font = new HelveticaNeueLight();
var nextSprite:MovieClip = new MovieClip();
var prevSprite:MovieClip = new MovieClip();
var infobox_title:TextField = new TextField();
var infobox_text:TextField = new TextField();
var infobox_facts:TextField = new TextField();
var infobox_next:TextField = new TextField();
var infobox_prev:TextField = new TextField();
var format_title:TextFormat = new TextFormat();
format_title.font = myFont.fontName;
format_title.size = 26;
format_title.color = 0x2d4275;
var format_text:TextFormat = new TextFormat();
format_text.font = myFont.fontName;
format_text.size = 20;
format_text.color = 0x000000;
format_text.leading = 6;
format_text.indent = - 17;
format_text.blockIndent = 17;
var format_bullet:TextFormat = new TextFormat();
format_bullet.font = myFont.fontName;
format_bullet.size = 20;
format_bullet.color = 0x000000;
format_bullet.indent = - 17;
format_bullet.blockIndent = 17;
format_bullet.leading = 6;
format_bullet.kerning = true;
var format_btn:TextFormat = new TextFormat();
format_btn.font = myFont.fontName;
format_btn.size = 12;
format_btn.color = 0x2d4275;
var thisItem = xml.item.(#LEVEL == activeLevel);
var nextItem = xml.item.(#LEVEL == thisItem.NEXT_LEVEL);
var prevItem = xml.item.(#LEVEL == thisItem.PREV_LEVEL);
infobox_prev.text = prevItem.NAME;
infobox_prev.autoSize = TextFieldAutoSize.LEFT;
infobox_prev.selectable = false;
infobox_prev.embedFonts = true; // very important to set
infobox_prev.setTextFormat(format_btn);
prevSprite.x = 50;
prevSprite.y = 720-50;
prevSprite.buttonMode = true;
prevSprite.mouseChildren = false;
prevSprite.addEventListener(MouseEvent.CLICK, infoboxPrev);
prevSprite.addChild(infobox_prev);
infobox_next.text = nextItem.NAME;
infobox_next.multiline = false;
infobox_next.autoSize = TextFieldAutoSize.RIGHT;
infobox_next.selectable = false;
infobox_next.embedFonts = true; // very important to set
infobox_next.setTextFormat(format_btn);
nextSprite.x = 250;
nextSprite.y = 720-50;
nextSprite.buttonMode = true;
nextSprite.mouseChildren = false;
nextSprite.addEventListener(MouseEvent.CLICK, infoboxNext);
nextSprite.addChild(infobox_next);
var line:Shape = new Shape();
var line2:Shape = new Shape();
var box:Shape = new Shape();
box.name = "box";
infobox_MC.addChild(box);
infobox_MC.setChildIndex(box,0);
infobox_title.text = xml.item.(#LEVEL == activeLevel).NAME;
infobox_title.autoSize = "left";
infobox_title.selectable = false;
infobox_title.embedFonts = true; // very important to set
infobox_text.name = "infobox_text";
infobox_text.autoSize = TextFieldAutoSize.LEFT;
infobox_text.multiline = false;
infobox_text.selectable = false;
infobox_text.wordWrap = false;
infobox_text.embedFonts = true; // very important to set
infobox_text.text = xml.item.(#LEVEL == activeLevel).INFOTEXT;
//infobox_text.mouseWheelEnabled = false;
//infobox_text.appendText("\n aus de.wikipedia.org");
var temp:String = xml.item.(#LEVEL == activeLevel).FACTS;
var FACTS = temp.split("| ").join("\n");
infobox_facts.name = ("infobox_facts")
infobox_facts.multiline = true;
infobox_facts.selectable = false;
infobox_facts.embedFonts = true; // very important to set
infobox_facts.autoSize = TextFieldAutoSize.LEFT;
//infobox_facts.multiline = false;
infobox_facts.wordWrap = false;
infobox_facts.text = FACTS;
infobox_facts.mouseWheelEnabled = false;
infobox_title.defaultTextFormat = format_title;
infobox_text.defaultTextFormat = format_text;
infobox_facts.defaultTextFormat = format_bullet;
infobox_title.setTextFormat(format_title);
infobox_text.setTextFormat(format_text);
infobox_facts.setTextFormat(format_bullet);
//infobox_text.styleSheet = style_text;
box.graphics.beginFill(0xFFFFFF); // choosing the colour for the fill, here it is red
box.graphics.drawRect(0, 0, 400,720); // (x spacing, y spacing, width, height)
box.graphics.endFill(); // not always needed but I like to put it in to end the fill
box.alpha = .85;
infobox_title.x = 30;
infobox_title.y = 50;
infobox_text.x = (1280-700);
infobox_text.y = infobox_title.y + infobox_title.height + 10;
infobox_text.alpha = 0;
var maxWidthFacts:Number = 300;
var maxWidthText:Number = 600;
if (infobox_text.width > maxWidthText)
{
infobox_text.multiline = true;
infobox_text.wordWrap = true;
infobox_text.width = maxWidthText;
}
infobox_facts.x = 50;
infobox_facts.y = infobox_title.y + infobox_title.height + 10;
if (infobox_facts.width > maxWidthFacts)
{
infobox_facts.multiline = true;
infobox_facts.wordWrap = true;
infobox_facts.width = maxWidthFacts;
}
line.graphics.lineStyle(2.5, 0x3F3F3F, 1);
line.graphics.moveTo(infobox_title.x, infobox_title.y + infobox_title.height -2);
line.graphics.lineTo(box.width - infobox_title.x, infobox_title.y + infobox_title.height-2);
line2.graphics.lineStyle(1, 0x3F3F3F, 1);
line2.graphics.moveTo(infobox_text.x, infobox_text.y + infobox_text.height);
line2.graphics.lineTo(box.width - infobox_title.x, infobox_text.y + infobox_text.height);
var back_BTN = new Back_BTN();
back_BTN.addEventListener(MouseEvent.CLICK, playBackwards);
back_BTN.x = 1150;
back_BTN.y = 25;
back_BTN.name = "back_BTN";
for each(var item in xml.item.(#LEVEL == activeLevel))
{
if(item.REFERENZ != "NONE")
{
var testSprite:MovieClip = new MovieClip();
var infobox_more:TextField = new TextField();
var moreSprite:MovieClip = new MovieClip();
testSprite.name = "REFERENZ";
testSprite.x = 50;
testSprite.y = infobox_facts.y + infobox_facts.height + 25;
imageLoad(item.REFERENZ,testSprite);
moreSprite.addChild(infobox_more);
infobox_MC.addChild(testSprite);
infobox_MC.addChild(moreSprite);
moreSprite.x = testSprite.x;
moreSprite.y = testSprite.y;
moreSprite.buttonMode = true;
moreSprite.mouseChildren = false;
moreSprite.name = "infobox_more";
infobox_more.text = "Referenzbeispiele";
infobox_more.multiline = false;
infobox_more.autoSize = TextFieldAutoSize.RIGHT;
infobox_more.selectable = false;
infobox_more.embedFonts = true; // very important to set
infobox_more.setTextFormat(format_btn);
//var image = testSprite.getChildAt(0);
var spriteWidth = testSprite.width * .035;
var spriteHeight = testSprite.height * .035;
testSprite.alpha = 0;
/*
testSprite.buttonMode = true;
testSprite.mouseChildren = true;
testSprite.addEventListener(MouseEvent.ROLL_OVER, iconHover);
testSprite.addEventListener(MouseEvent.ROLL_OUT, iconOut);
testSprite.addEventListener(MouseEvent.CLICK, iconBig);
*/
//moreSprite.buttonMode = true;
//moreSprite.mouseChildren = true;
moreSprite.addEventListener(MouseEvent.CLICK, iconBig);
infobox_MC.setChildIndex(testSprite,infobox_MC.numChildren-1);
infobox_MC.addChild(moreSprite);
}
}
var infobox_text_MC:MovieClip = new MovieClip();
infobox_text_MC.name = "infobox_text_MC";
infobox_text_MC.addChild(infobox_text);
infobox_MC.addChild(infobox_text_MC);
infobox_text_MC.scaleMode = StageScaleMode.NO_SCALE;
infobox_text_MC.height = 600;
trace(infobox_text_MC.x);
trace(infobox_text_MC.y);
trace(infobox_text_MC.width);
trace(infobox_text_MC.height);
infobox_text_MC.visible = true;
infobox_facts.text = FACTS;
infobox_MC.addChild(infobox_title);
infobox_MC.addChild(infobox_facts);
//infobox_MC.addChild(nextSprite);
//infobox_MC.addChild(prevSprite);
infobox_MC.addChild(back_BTN);
einblenden(infobox_MC);
}
With some other function the alpha of the textfields is toogled to one. So once I execute the right function it is visible but it's squished.
Any help would be appreciated
Chris
You should be using numLines to determine the number of lines in your textfield.
var maxlines:Number = 5;
if( infobox_facts.numlines > maxLines )
{
// scroll it
}
okay, so I found where I was going wrong.
the line "*infobox_text.autoSize = TextFieldAutoSize.LEFT;*" prevents me from setting the width and hight of a textField. Turning that off will let you then specify height as well as width and the texfield doesn't need to be nested within a movieclip.
Sometimes one doesn't see the wood for the trees...

AS3 object inexplicably disappears after 1.5 - 2 minutes

I'm new to as3 but have been learning as I go.
I am creating a container which appears with text field inputs so the user can create a 'post'. This is triggered to occur when an animation is removed from the stage which it does automatically when it has completed.
However after about 1.5-2 minutes the container inexplicably disappears. This is a problem as a user may well want to take more than 2 minutes to make a post.
I cannot for the life of me figure out why this is happening, could it possible be a garbage collection issue?
Any help is greatly appreciated thank you,
Dan
var titleText:Title = new Title();
var titleInput:TextField = new TextField();
var categoryText:Category = new Category();
var categoryInput:TextField = new TextField();
var postText:Text = new Text();
var postInput:TextField = new TextField();
//setup text formats to be used
var postCreationTextFormat:TextFormat = new TextFormat();
postCreationTextFormat.font = "arial";
postCreationTextFormat.size = 20;
postCreationTextFormat.align = "left";
postCreationTextFormat.leftMargin = 2;
//Fade In Post Creation Box after Seed to Bud Animation.
seedToBud.addEventListener(Event.REMOVED_FROM_STAGE, createPostInput);
//Some variables to declare for the createPostInput function.
var postCreationContainer:PostCreationContainer = new PostCreationContainer;
var contentWindow:ContentWindow = new ContentWindow;
var postCreationInputBoxes:PostCreationInputBoxes = new PostCreationInputBoxes;
var thumb:Thumb = new Thumb;
var track:Track = new Track;
var scrollDownArrow:ScrollDownArrow = new ScrollDownArrow;
var scrollUpArrow:ScrollUpArrow = new ScrollUpArrow;
function createPostInput(event:Event)
{
addChild(postCreationContainer);
postCreationContainer.x = 230;
postCreationContainer.y = 400;
postCreationContainer.addChild(track);
track.x = 428;
track.y = 25;
postCreationContainer.addChild(thumb);
thumb.x = 418;
thumb.y = 25;
postCreationContainer.addChild(scrollDownArrow);
scrollDownArrow.x = 418;
scrollDownArrow.y = 269;
postCreationContainer.addChild(scrollUpArrow);
scrollUpArrow.x = 418;
scrollUpArrow.y = 6;
postCreationContainer.addChild(contentWindow);
contentWindow.x = 6;
contentWindow.y = 6;
postCreationContainer.addChild(postCreationInputBoxes);
postCreationInputBoxes.x = 6;
postCreationInputBoxes.y = 6;
postCreationContainer.alpha = 0;
postCreationContainer.addEventListener(Event.ENTER_FRAME, fadeInCreatePostInput);
postCreationInputBoxes.addChild(titleText);
titleText.x = 0;
titleText.y = 0;
postCreationInputBoxes.addChild(titleInput);
postCreationInputBoxes.addChild(categoryText);
categoryText.x = 0;
categoryText.y = 60;
postCreationInputBoxes.addChild(categoryInput);
postCreationInputBoxes.addChild(postText);
postText.x = 0;
postText.y = 124;
postCreationInputBoxes.addChild(postInput);
titleInput.defaultTextFormat = postCreationTextFormat;
titleInput.type = "input";
titleInput.multiline = false;
titleInput.wordWrap = false;
titleInput.maxChars = 150;
titleInput.border = true;
titleInput.width = 403;
titleInput.height = 30;
titleInput.x = 0;
titleInput.y = 32;
titleInput.background = true;
titleInput.backgroundColor = 0xFFFFFF;
categoryInput.defaultTextFormat = postCreationTextFormat;
categoryInput.type = "input";
categoryInput.multiline = false;
categoryInput.wordWrap = false;
categoryInput.maxChars = 150;
categoryInput.border = true;
categoryInput.width = 403;
categoryInput.height = 30;
categoryInput.x = 0;
categoryInput.y = 96;
categoryInput.background = true;
categoryInput.backgroundColor = 0xFFFFFF;
postInput.defaultTextFormat = postCreationTextFormat;
postInput.type = "input";
postInput.multiline = true;
postInput.wordWrap = true;
postInput.maxChars = 500;
postInput.border = true;
postInput.width = 403;
postInput.height = 361.5;
postInput.x = 0;
postInput.y = 156;
postInput.background = true;
postInput.backgroundColor = 0xFFFFFF;
stage.focus = titleInput;
seedToBud.removeEventListener(Event.REMOVED_FROM_STAGE, createPostInput);
}
function fadeInCreatePostInput(event:Event):void
{
postCreationContainer.alpha += 0.05;
if (postCreationContainer.alpha == 1)
{
postCreationContainer.removeEventListener(Event.ENTER_FRAME, fadeInCreatePostInput);
}
}
Do you know for a fact that there are no rounding issues with your alpha incrementer? I'd be checking the integer value of alpha and not the real, floating point value. Or, do a fuzz comparison (alpha >= 1-FUZZ && alpha <= 1+FUZZ) for some small value of FUZZ.

Two colors in one text field using Actionscript 3

Is it possible to have two text colors in one text field using Actionscript 3.0?
ex: how can i make like the first string black and the second string red?
Here is my code when using a single color:
public function logs(txt)
{
if (txt == '')
{
textLog.text = "Let's Open up our treasure boxes !!!";
}
else
{
textLog.text = '' + txt + '';
}
textLog.x = 38.60;
textLog.y = 60.45;
textLog.width = 354.50;
textLog.height = 31.35;
textLog.selectable = false;
textLog.border = false;
var format:TextFormat = new TextFormat();
var myFont:Font = new Font1();
format.color = 0x000000;
format.font = myFont.fontName;
format.size = 18;
format.align = TextFormatAlign.CENTER;
format.bold = false;
textLog.embedFonts = true;
textLog.setTextFormat(format);
this.addChild(textLog);
}
In setTextFormat you can specify start index and end index. You can also render text as html using textLog.htmlText.
First set the text
var t:TextField = new TextField();
t.text = "BLUEGREEN";
addChild(t);
Then method 1
var format1:TextFormat = t.getTextFormat(0, 4);
format1.color = 0x0000ff;
t.setTextFormat(format1, 0, 4);
var format2:TextFormat = t.getTextFormat(5, t.length);
format2.color = 0x00ff00;
t.setTextFormat(format2, 5, t.length);
Or method 2
t.htmlText = '<font color="#0000ff">BLUE</font><font color="#00ff00">GREEN</font>';
If you want to do like that, you need create a function to control. charAt(DEFINE INDEX OF STRING HERE).
var format2:TextFormat = textbox.defaultTextFormat;
format2.color = 0x000000;
textbox.defaultTextFormat = format2;
if((textbox.text.charAt(3) == "d") && ( textbox.text.charAt(4) == "i")){
var format1:TextFormat = textbox.defaultTextFormat;
format1.color = 0xFF0000;
textbox.setTextFormat(format1, 3, 5);}
else{
textbox.setTextFormat(textbox.defaultTextFormat);}

How to get dynamic TextInput field values in Actionscript 3

Hi creating dynamic TextInput fields in a function. Need to get the values of those fields in another function. Can anyone throw some light on this.
for(var i:int=0;i<answers.length;i++)
{
txtbox = new spark.components.TextInput();
var lblBox:spark.components.Label = new spark.components.Label();
lblBox.id = "lbl"+i.toString();
lblBox.text = String(answersLabel.getItemAt(i) );
lblBox.width = 10
lblBox.x = xPos-15;
lblBox.y = yPos;
QuestionAnswer.addElement(lblBox);
txtbox.id = "text"+i.toString();
txtbox.x = xPos;
txtbox.y = yPos;
QuestionAnswer.addElement(txtbox);
xPos += 200;
}
var txt:TextField;
var i:uint;
var ary:Array = new Array();
function txtCreation ():void {
for( i=0;i<5;i++)
{
txt = new TextField();
txt.text = "txt"+i;
addChild(txt);
txt.x = 50 + txt.width *i;
txt.y = 20;
ary.push(txt);
}
}
txtCreation();
for(i=0;i<ary.length;i++)
{
trace("array values : " +ary[i].text);
}
Just look at the text variable for the textfield.
var textFromField : String = myInputText.text;

AS3 Showing image after load is finish

So i'm loading picture from xml, and adding them into a movieclip called cv which has a holder called cHolder. Right now the problem is that while the preloader shows it is loading, the cv(s) appeared already. Is there anyway to show all the cv only after the images have finish loading?
Thanks.
for each (var projectName:XML in projectAttributes)
{
//trace(projectName);
var projectDP:XMLList = projectInput.project.(#name == projectName).displayP;
//trace(projectDP);
var cv:MovieClip = new cView();
catNo += 1;
cv.name = "cv" + catNo;
cv.buttonMode = true;
if(catNo % 5 == 0)
{
catY += 137;
catX = -170;
cv.x = catX;
cv.y = catY;
}
else
{
cv.x = catX;
cv.y = catY;
catX += 112;
}
var imageLoader = new Loader();
imageLoader.load(new URLRequest(projectDP));
TweenLite.to(cv.cHolder, 1, {colorTransform:{tint:0x000000, tintAmount:0.8}});
cv.cHolder.addChild(imageLoader);
cv.ct.text = projectName;
projName.push(projectName);
this.addChild(cv);
imageLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, imageProg);
function imageProg(e:ProgressEvent):void
{
loader.visible = true;
var imageLoaded:Number = e.bytesLoaded/e.bytesTotal*100;
loader.scaleX = imageLoaded/100;
}
imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoad);
function imageLoad(e:Event):void
{
loader.visible = false;
}
First, don't put a function inside another function, this won't help for anything and is a bad habit :)
Declare two private variables:
var nImages:uint;
var loadedImages:uint;
Before the loop:
nImages = projectAttributes.length();
loadedImages = 0;
cv.visible = false;
and in the Event.COMPLETE listener:
function imageLoad(e:Event):void
{
loader.visible = false;
loadedImages++;
if (loadedImages == nImages)
{
cv.visible = true;
}
}
var count:int = 0;
var totalClips:int = 0;
cv.visible = false;
for each (var projectName:XML in projectAttributes)
{
++totalClips;
//trace(projectName);
var projectDP:XMLList = projectInput.project.(#name == projectName).displayP;
//trace(projectDP);
var cv:MovieClip = new cView();
catNo += 1;
cv.name = "cv" + catNo;
cv.buttonMode = true;
if(catNo % 5 == 0)
{
catY += 137;
catX = -170;
cv.x = catX;
cv.y = catY;
}
else
{
cv.x = catX;
cv.y = catY;
catX += 112;
}
var imageLoader = new Loader();
imageLoader.load(new URLRequest(projectDP));
TweenLite.to(cv.cHolder, 1, {colorTransform:{tint:0x000000, tintAmount:0.8}});
cv.cHolder.addChild(imageLoader);
cv.ct.text = projectName;
projName.push(projectName);
this.addChild(cv);
imageLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, imageProg);
function imageProg(e:ProgressEvent):void
{
loader.visible = true;
var imageLoaded:Number = e.bytesLoaded/e.bytesTotal*100;
loader.scaleX = imageLoaded/100;
}
imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoad);
function imageLoad(e:Event):void
{
++count;
if(count == totalClips){
cv.visible = true;
}
loader.visible = false;
}
}
So you might want to adapt things a little, in case I'm counting in the wrong spots etc for your implementation but as you can see the solution is simple, you count the total number of clips being processed for loading from the XML, then as the images are loaded and call the OnComplete callback, you increment another count until you've seen that you've loaded all processed images, and set the container to visible.