AS3 Collision Detection Arrays - actionscript-3

I've been trying to figure out an easier way to code this for a simple RPG I have been working on, it works perfectly if the item that is unable to pass through is added individually. When I've tried to work with arrays, it throws off a bunch of evil errors. Granted I am new to AS3 but I have tried to find a solution to this, with no luck.
if(heroMC.hitTestObject(block1)) {
hitObj = true;
heroMC.x = gX;
heroMC.y = gY;
} else if(heroMC.hitTestObject(bridgeBlock2)) {
hitObj = true;
heroMC.x = gX;
heroMC.y = gY;
} if(heroMC.hitTestObject(bridgeBlock3)) {
hitObj = true;
heroMC.x = gX;
heroMC.y = gY;
} else {
hitObj = false;
gX = heroMC.x;
gY = heroMC.y;
}
I then add every individual entry, to my list. If heroMC does intersect the object, then it changes the value of hitObj to true. If nothing is colliding, the hitObj will return as false. What solutions could I use to make this easier and cleaner.
Thanks in advance guys.

Insert your blocks MovieClips into an array
var blocksArray: Arry = new Array(block1, bridgeBlock2, bridgeBlock3);
Add Enter frame handler event for catch the changes
this.addEventListener(Event.ENTER_FRAME, onEnterFramehandler);
function onEnterFramehandler(e: Event): void {
//initially set it to false
hitObj = false;
for (var i: uint = 0; i < blocksArray.length; i++) {
//If hit the object set it to true;
if (heroMC.hitTestobject(blocksArray[i])) {
hitObj = true;
//set the position of the heroMc if true
heroMC.x = gX;
heroMC.y = gY;
break;
}
}
//get the position of the heroMc if false
gX = heroMC.x;
gY = heroMC.y;
}

Related

Actionscript 3 drag and drop multiple objects to target with well done

The drag and drop works, however, I have no idea how to create an if statement that goes to the next scene when all movieclips have been placed on the target.
I've tried placing the instance names in an if statement with the hittestobject however, no luck.
import flash.events.TouchEvent;
import flash.ui.Multitouch;
import flash.ui.MultitouchInputMode;
import flash.display.MovieClip;
/* Touch and Drag Event
Allows the object to be moved by holding and dragging the object.
*/
var objectoriginalX:Number;
var objectoriginalY:Number;
Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT;
var lemons:Array = [lemon1_mc, lemon2_mc, lemon3_mc, lemon4_mc, lemon5_mc];
for each(var lemonMC:MovieClip in lemons)
{
lemonMC.buttonMode = true;
lemonMC.addEventListener(TouchEvent.TOUCH_BEGIN, pickobject);
lemonMC.addEventListener(TouchEvent.TOUCH_END, dropobject);
lemonMC.startX = lemonMC.x;
lemonMC.startY = lemonMC.y;
}
var fl_DragBounds:Rectangle = new Rectangle(0, 0, stage.stageWidth, stage.stageHeight);
function pickobject(event:TouchEvent):void
{
event.target.startTouchDrag(event.touchPointID, false, fl_DragBounds);
event.target.parent.addChild(event.target);
objectoriginalX = event.target.x;
objectoriginalY = event.target.y;
}
function dropobject(event:TouchEvent):void
{
if(event.target.hitTestObject(target_mc)){
event.target.buttonMode = false;
event.target.x = target_mc.x;
event.target.y = target_mc.y;
event.target.visible = false;
} else {
event.target.x = event.target.startX;
event.target.y = event.target.startY;
event.target.buttonMode = true;
}
}
var melons:Array = [melon1_mc, melon2_mc, melon3_mc, melon4_mc, melon5_mc, melon6_mc, melon7_mc];
for each(var melonMC:MovieClip in melons)
{
melonMC.buttonMode = true;
melonMC.addEventListener(TouchEvent.TOUCH_BEGIN, pickobject2);
melonMC.addEventListener(TouchEvent.TOUCH_END, dropobject2);
melonMC.startX = melonMC.x;
melonMC.startY = melonMC.y;
}
var fl_DragBounds2:Rectangle = new Rectangle(0, 0, stage.stageWidth, stage.stageHeight);
function pickobject2(event:TouchEvent):void
{
event.target.startTouchDrag(event.touchPointID, false, fl_DragBounds2);
event.target.parent.addChild(event.target);
objectoriginalX = event.target.x;
objectoriginalY = event.target.y;
}
function dropobject2(event:TouchEvent):void
{
if(event.target.hitTestObject(target_null)){
event.target.buttonMode = false;
event.target.x = target_mc.x;
event.target.y = target_mc.y;
event.target.visible = false;
} else {
event.target.x = event.target.startX;
event.target.y = event.target.startY;
event.target.buttonMode = true;
}
}
How about adding a counter that is equal to number of objects to drag, then every time you drop object (and detect if it was on target) you decrements the counter and at the end of the function you check if it's 0?
An easy way to do this would be to remove your lemons/melons from their arrays when they pass the hit test. Then check if each array is empty and continue to the next scene should that be the case.
You can actually reduce redundant code and use the same function (dropobject) for both lemons and melons.
function dropobject(event:TouchEvent):void {
//Figure out which array this belongs to (is it a lemon or a melon)
var array:Array; //the array the dropped item belongs to
var hitMC:MovieClip; //the hit object for the lemon or melon
if(lemons.indexOf(event.currentTarget) > -1){ //if the lemon array contains the currentTarget
array = lemons;
hitMC = target_mc;
}else{
array = melons;
hitMC = target_null;
}
if(event.currentTarget.hitTestObject(hitMC)){
event.currentTarget.buttonMode = false;
event.currentTarget.x = hitMC.x;
event.currentTarget.y = hitMC.y;
event.currentTarget.visible = false;
//remove the item from it's array
array.removeAt(array.indexOf(event.currentTarget));
//check if there are any items left
if(lemons.length < 1 && melons.length < 1){
//both arrays are empty, so move on
play(); //or however you want to move on
}
}
}
Getting more advanced, a better way to do this would be to make a base class for your lemons, melons and anything else you want to drag in the future. Then you can add the dragging functionality into that base class and add properties for the hit target and an event for when it's hit it's target. This would give you one code base that can be easily applied to any library object.

Objects on the stage are not read when jumping to their frame

I am working on an Air desktop application. At some point when the user presses a button, it will jump to a specific frame, the problem is after going to that frame some Movieclips on the stage at that frame are not read though they were read from the very beginning.
The following error occurs.
Error #1009: Cannot access a property or method of a null object
reference.
I do not know why he can not read what is already on the stage, I guess it is something related to the arrangement of the layers. I noticed that sometimes though I do not find it logical, It is supposed to read ALL that is in the same frame as long as it is stopped on it, right?
The project is as follows:
1) At the very beginning an intro is played and then it goes to the first frame of the course.
2) At first frame the user chooses one of 5 buttons to click, based on each one it goes to different frame.
3) When the user is at any frame it should return to the main frame if he clicked a back button, this button command is gotoAndStop(1) and some conditional removeChild() to clean the stage from any objects generated by code depending on the frame the function was called from.
4) The problem arises when this back button is clicked, one or more of the very first 5 buttons suddenly disappears and an error generated as - for some unknown reason - it can not be read by the program any more, it can not read any events for it and generates the above error.
My code is as follows:
var myLettersLoader:URLLoader= new URLLoader();
mainMenu.addEventListener(MouseEvent.CLICK,gotomainMenu);
letters.addEventListener(MouseEvent.CLICK,showLetters);
lessons.addEventListener(MouseEvent.CLICK,showLessons);
revision.addEventListener(MouseEvent.CLICK,showRevision);
myLettersLoader.load(new URLRequest("data/letters/letters.xml"));
myLettersLoader.addEventListener(Event.COMPLETE,loadXML);
function showLetters(e:MouseEvent)
{
//gotoAndStop(2)
//aaaaa.alpha=1;
//aaaaa.visible=true;
Tweener.addTween(e.currentTarget, {width:originalWidth,height:originalHeight, time:0.25, transition:"linear"});
myPlace.visible = true;
myPlace2.visible = false;
myPlace3.visible = false;
jewels.visible = false;
mainContainer.visible=false;
close.visible=false;
studentBook.visible = false;
mainButton = e.currentTarget.name;
Tweener.addTween(myPlace, {alpha:1, transition:"linear"});
lettersContainer.visible=true;
Tweener.addTween(letterContainerText, {alpha:1, transition:"linear"});
for (var i=1; i<29; i++)
{
var letter = "L" + i;
myPlace[letter].id = i;
myPlace[letter].alpha = 1;
myPlace[letter].addEventListener(MouseEvent.CLICK,gotoLetterFrame);
myPlace[letter].buttonMode = true;
}
}
function showLessons(e:MouseEvent)
{
Tweener.addTween(e.currentTarget, {width:originalWidth,height:originalHeight, time:0.25, transition:"linear"});
myPlace.visible= false;
myPlace2.visible = true;
myPlace3.visible = false;
jewels.visible = false;
mainContainer.visible=false;
close.visible=false;
studentBook.visible = false;
lettersContainer.visible=true;
mainButton = e.currentTarget.name;
Tweener.addTween(myPlace2, {alpha:1, transition:"linear"});
studentBook.alpha = 0;
for (var i=0; i<5; i++)
{
var lesson = "Lesson" + i;
myPlace2[lesson].id = i;
myPlace2[lesson].alpha = 1;
myPlace2[lesson].addEventListener(MouseEvent.CLICK,gotolessonFrame);
myPlace2[lesson].buttonMode = true;
}
}
//=======================Revision functions==================================
function showRevision(e:MouseEvent)
{
Tweener.addTween(e.currentTarget, {width:originalWidth,height:originalHeight, time:0.25, transition:"linear"});
myPlace.visible= false;
myPlace2.visible = false;
myPlace3.visible = true;
jewels.visible = false;
mainContainer.visible=false;
close.visible=false;
studentBook.visible = false;
lettersContainer.visible=true;
mainButton = e.currentTarget.name;
Tweener.addTween(myPlace3, {alpha:1, transition:"linear"});
studentBook.alpha = 0;
for (var i=0; i<7; i++)
{
var revision = "Revision" + i;
myPlace3[revision].id = i;
myPlace3[revision].alpha = 1;
myPlace3[revision].addEventListener(MouseEvent.CLICK,gotoRevisionFrame);
myPlace3[revision].buttonMode = true;
}
}
//========================================================
function gotoLetterFrame(e:MouseEvent)
{
reloadButton.visible=true;
mainMenu.visible=true;
myClose.visible=true;
reloadButton.visible=true;
myNext.visible=true;
currentTarget=(e.currentTarget.id-1);
currentName = arrOfLetters[currentTarget];
xmlListOfClass=new XMLList(myxml.letter.(#id==currentName).children());
gotoAndStop(xmlListOfClass[counter].localName());
abc.visible=abcd.visible=true;
mainMenu.buttonMode=true;
}
function gotolessonFrame(e:MouseEvent)
{
reloadButton.visible=true;
mainMenu.visible=true;
myClose.visible=true;
reloadButton.visible=true;
myNext.visible=true;
currentTarget=(e.currentTarget.id);
xmlListOfClass = new XMLList(lessonsArr[currentTarget].lesson.children());
gotoAndStop(xmlListOfClass[counter].localName());
abc.visible=abcd.visible=true;
mainMenu.buttonMode=true;
}
function gotoRevisionFrame(e:MouseEvent)
{
reloadButton.visible=true;
mainMenu.visible=true;
myClose.visible=true;
reloadButton.visible=true;
myNext.visible=true;
currentTarget=(e.currentTarget.id);
myRevisionLoader.load(new URLRequest("data/revisions/"+currentTarget+"/revision.xml"));
myRevisionLoader.addEventListener(Event.COMPLETE,loadRevisionXML);
}
//=====================================
function loadLessonXML(e:Event)
{
lessonsArr[xx] = new XML(e.target.data);
xx++;
}
//==============================For revision==================================
function loadRevisionXML(e:Event)
{
revisionArr = new XML(e.target.data);
xmlListOfClass = new XMLList(revisionArr.revision.children());
gotoAndStop(xmlListOfClass[counter].localName());
abc.visible=abcd.visible=true;
mainMenu.buttonMode=true;
}
function loadXML(e:Event)
{
myxml = new XML(e.target.data);
}
//====================================
function gotomainMenu(e:MouseEvent)
{
gotoAndPlay(1);
}
This code is in the first frame, and in the second frame the button mainButton
is the button responsible for going back to frame 1
The buttons lessons,letters,revision disappears when returning to frame 1, or one of them sometimes with no logical reason
I solved it.It was all about the arrangement of layers.
All what I did is that I put the layer which contains the 5 buttons under the other layers. This surprisingly solved the problem. I do not know the reason till this moment but all what I know is that for some reason the caller of some event must be under the other layers containing some other objects or at least at the same layer.

Adobe air application quits when i try to print after a function called "show bill"?

I am trying to create an air application using flash profession cc. I have functions called show bill and print bill in it. When i print directly with out showing the bill adobe air application works correctly. But when i try to use the show bill function and then try to print the bill it show the print dialog box and when i give a print command an"Adobe Air Application Stop working window shows up" . Here is the code of show bill function
public function ShowBill(e: MouseEvent): void {
total();
Merge();
bswap();
billing.x = 450;
billing.y = 100;
billing.height = 300 ;
billing.width = 500 ;
addChild(billing);
billing.close_btn1.addEventListener(MouseEvent.CLICK, rmvBilling);
billing.close_btn1.visible = true;
if(billing._item.item1.text != "")
{
billing._item.visible = true;
billing._item.close_btn1.visible = true;
}
if(item2.item1.text != "")
{
item2.close_btn1.visible = true;
}
if(item3.item1.text != "")
{
item3.close_btn1.visible = true;
}
if(item4.item1.text != "")
{
item4.close_btn1.visible = true;
}
if(item5.item1.text != "")
{
item5.close_btn1.visible = true;
}
if(item6.item1.text != "")
{
item6.close_btn1.visible = true;
}
if(item7.item1.text != "")
{
item7.close_btn1.visible = true;
}
if(item8.item1.text != "")
{
item8.close_btn1.visible = true;
}
if(item9.item1.text != "")
{
item9.close_btn1.visible = true;
}
if(item10.item1.text != "")
{
item10.close_btn1.visible = true;
}
total();
}
Here is the code for print bill
public function printContent(e: MouseEvent) {
update1();
billing.close_btn1.visible = false;
billing._item.close_btn1.visible = false;
item2.close_btn1.visible = false;
item3.close_btn1.visible = false;
item4.close_btn1.visible = false;
item5.close_btn1.visible = false;
item6.close_btn1.visible = false;
item7.close_btn1.visible = false;
item8.close_btn1.visible = false;
item9.close_btn1.visible = false;
item10.close_btn1.visible = false;
var printJob: PrintJob = new PrintJob();
if (printJob.start()) {
if (billing.width < printJob.pageWidth) {
billing.width = printJob.pageWidth;
billing.scaleY = billing.scaleX;
}
printJob.addPage(billing);
printJob.send();
clear();
}
}
public function update1():void{
var phpVars:URLVariables = new URLVariables();
var phpFileRequest:URLRequest = new URLRequest("http://localhost/icyspicy/update.php");
phpFileRequest.method = URLRequestMethod.POST;
phpFileRequest.data = phpVars;
var phpLoader:URLLoader = new URLLoader();
phpLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
phpVars.systemCall="update";
phpVars.table = String(tabNbill1.getDubTblNo.text);
phpVars.date = String(billing.the_date.text);
phpVars.items = String(billing._item.item1.text+","+item2.item1.text+","+item3.item1.text+","+item4.item1.text+","+item5.item1.text+","+item6.item1.text+","+item7.item1.text+","+item8.item1.text+","+item9.item1.text+","+item10.item1.text );
phpVars.quantity = String(billing._item.q2.text+","+item2.q2.text+","+item3.q2.text+","+item4.q2.text+","+item5.q2.text+","+item6.q2.text+","+item7.q2.text+","+item8.q2.text+","+item9.q2.text+","+item10.q2.text);
phpVars.total =String( billing.total.text);
phpLoader.load(phpFileRequest);
postData(mypath, getResponse);
}
Every function is working correctly but the conflict between printbill and show bill i could not solve ..Please guys need suggestion and help..Thank You
Sometimes spooling display objects with text and shapes can crash the application. While I can't comment on the why, I can share what I've done in the past to work around this problem.
Printing the page as a bitmap can sometimes fix this crashing problem. In your case that would like this:
var printOptions:PrintJobOptions = new PrintJobOptions();
printOptions.printAsBitmap = true;
printJob.addPage(billing,null,printOptions);
OR for a shorter inline way:
printJob.addPage(billing, null, new PrintJobOptions(true));
Do note, that sometimes doing this makes text not as crisp looking, as FlashPlayer is basically drawing the object to pixel data before sending it to the spooler.

Actionscript 3: How to detect when a button isn't pressed in time?

Okay, this is another question for the game I am making. I am putting together a second level, where you need to press a long series of keys at the right time. Pressing them too early or too late results in failure. What I need to know is how to detect when a key ISN'T pressed, when it should have been. This is what I have so far:
var count3:Number = 23;
var myTimer3:Timer = new Timer(1000, count3);
var timeLeft3:Number = count3;
var buttonPressed:Boolean = false;
var btnCounter:Number = 2;
var btnTimer:Timer = new Timer(1000, btnCounter);
myTimer3.addEventListener(TimerEvent.TIMER, countdown3);
myTimer3.start();
btnTimer.addEventListener(TimerEvent.TIMER, btnCountdown);
btn1.addEventListener(MouseEvent.CLICK, buttonPress);
btn1.visible = false;
btn2.visible = false;
btn3.visible = false;
btn4.visible = false;
btn5.visible = false;
btn6.visible = false;
btn7.visible = false;
btn8.visible = false;
btn9.visible = false;
function countdown3(event:TimerEvent): void {
if (((count3)-myTimer3.currentCount)==20) {
btn1.visible = true;
btnTimer.start();
} else if (((count3)-myTimer3.currentCount)==19) {
btn1.visible = true;
} else {
btn1.visible = false;
}
}
function btnCountdown(event:TimerEvent):void {
if (((btnCounter)-btnTimer.currentCount)==0) {
if (buttonPressed = true) {
btnTimer.stop();
} else {
gotoAndStop(2);
}
}
}
function buttonPress (event:MouseEvent): void {
buttonPressed = true;
}
For some reason, it won't do anything when btnCounter hits 0. If someone could help me sort this out, that would be awesome. Thanks.
N.B. This is a personal project, I am just learning actionscript
Start a timer for the time duration when the button is supposed to be pressed (for example, if the button must be pressed within 2 seconds, set the timer's interval to 2 seconds).
Then create a global Boolean variable (or class member variable, however your scene is set up) and set it to false initially. When the button is pressed, set this variable to true and disable the timer.
If the timer fires and this variable is false, it means that it hasn't been disabled by the button so the user didn't click the button within 2 seconds.
Don't use terribly short times - timers are not very accurate and processor speed may have an effect on their duration. (Human reaction times aside.)

Customizing Clothes on Character in Game User Personalization

I could use help with customization in Flash games! I am pretty new to AS3 and have a game I am building where the user can dress the character based on a few options and a color picker, then move on to a race. I cannot get the clothes that are chosen to stay, and the ones excluded leave, without all of them staying or leaving. I've tried variables, if/else conditions and switch statements, but nothing is working. I have a feeling it's a condition, but I don't know how to write it and can't find anyone in a similar boat.
I have been scouring my books (Flash CS6 Missing Manual and ActionScript 3.0 Cookbook), and I've gotten very close, but nothing works. I really could use a lot of help with this, it's a final project and the stress might be hiding the answer, but I surely don't have it.
Not sure if I did this right, I've never used this site before. Thank you in advance!
UPDATE
Here is a link to where the .swf file is currently uploaded for your input.
http://yellownotebook.weebly.com/other-work.html
Please ignore the DONE button at the beginning, I am working on that still. I need the clothes to be invisible on the start up, and the remaining unselected clothes after that to be discarded? Invisible? I still don't understand which way is best for this situation. I started reading something about Display Lists?
I'm also not sure what part of the code would be most helpful, so here it is.
var mcdress2 = mcdress2
var mcpants = mcpants
var mcshirt = mcshirt
var mctop = mctop
var clothes = mctop + mcpants + mcshirt + mcdress2
var fairy = clothes + mcwings + mcfay
mcfay.visible = false;
mctop.visible = false;
mcshirt.visible = false;
mcpants.visible = false;
mcdress2.visible = false;
mcwings.visible = false;
cpClothes.visible = false;
import fl.events.ColorPickerEvent;
fairybg.btnplay.addEventListener(MouseEvent.CLICK,clickPlayListener);
btndone.addEventListener(MouseEvent.CLICK,clickDoneListener);
fairybg.gotoAndStop("Game Start");
function clickPlayListener(evt:MouseEvent):void
{
fairybg.gotoAndStop("Background Start")
mcfay.visible = true;
mctop.visible = true;
mcshirt.visible = true;
mcpants.visible = true;
mcdress2.visible = true;
mcwings.visible = true;
cpClothes.visible = true;
}
//fairy.scaleY = fairy.scaleX
function clickDoneListener(evt:MouseEvent):void
{
fairybg.gotoAndStop("Background Fly")
fairybg.gotoAndStop("Background Fly")
//fairy.width = 1/2
//fairy.height = 1/2;
//if it was this way, she would be bare when she flies, needs "if" condition?
//mctop.visible = false;
//mcshirt.visible = false;
//mcpants.visible = false;
//mcdress2.visible = false;
cpClothes.visible = false;
btndone.visible = false;
}
//fairy.scaleY = fairy.scaleX
mcdress2.gotoAndStop(1);
mcdress2.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownListener);
function mouseDownListener (event:MouseEvent):void
{
mcdress2.gotoAndStop("Dress End");
mctop.gotoAndStop("Top Start");
mcpants.gotoAndStop("Pants Start");
mcshirt.gotoAndStop("Shirt Start");
}
mcshirt.gotoAndStop(1);
mcshirt.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownListener2);
function mouseDownListener2 (event:MouseEvent):void
{
mcshirt.gotoAndStop("Shirt End");
mcdress2.gotoAndStop("Dress Start");
mctop.gotoAndStop("Top Start");
}
mcpants.gotoAndStop(1);
mcpants.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownListener3);
function mouseDownListener3 (event:MouseEvent):void
{
mcpants.gotoAndStop("Pants End");
mcdress2.gotoAndStop("Dress Start");
}
mctop.gotoAndStop(1);
mctop.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownListener4);
function mouseDownListener4 (event:MouseEvent):void
{
mctop.gotoAndStop("Top End");
mcshirt.gotoAndStop("Shirt Start");
mcdress2.gotoAndStop("Dress Start");
}
//use color picker to change clothing color (all items same color)
cpClothes.addEventListener(ColorPickerEvent.CHANGE,changeColorPicker);
function changeColorPicker(evt:ColorPickerEvent):void
{
var myColorTransform = new ColorTransform ();
myColorTransform.color = evt.color;
mcdress2.transform.colorTransform = myColorTransform;
mctop.transform.colorTransform = myColorTransform;
mcshirt.transform.colorTransform = myColorTransform;
mcpants.transform.colorTransform = myColorTransform;
//trace ("color changed")
//trace (evt.color)
//trace (mcdress.color)
//opaqueBackground = evt.color;
}
cpClothes.colors =
[0xF7977A,0xFFF79A,0x6ECFF6,0xF49AC2];
switch (clothes) {
case "Dress End" :
mcshirt.visible = false;
mctop.visible = false;
mcpants.visible = false;
break;
case "Top End" :
mcshirt.visible = false;
mcdress2.visible = false;
mcpants.visible = false;
break;
case "Shirt End" :
mctop.visible = false;
mcdress2.visible = false;
mcpants.visible = false;
break;
default :
//mcdress2.gotoAndStop("Dress Start")
//mctop.gotoAndStop("Top Start")
//mcshirt.gotoAndStop("Shirt Start")
//mcpants.gotoAndStop("Pants Start")
mcdress2.visible = true;
mctop.visible = true;
mcshirt.visible = true;
mcpants.visible = true;
}
/*if (clickDoneListener==true) {
fairy.width = .5
fairy.height = .5;
}*/
//trace ("it works!")
//var _mcpants:mcpants;
//function newmcpants(e:MouseEvent):void
//{
//if (_mcpants)
// return
//_mcpants = new mcpants();
//_mcpants.x = 263.35;
//_mcpants.y = 270.40;
//addChild(_mcpants);
//}
//function deletemcpants(e:MouseEvent):void;
//{
//if (_mcpants && contains(_mcpants))
//removeChild(_mcpants);
//_mcpants = null;
//displayText("Deleted mcpants successfully!");
//}
As you can see, I have a lot of code commented out, I have been trying everything I can find for it to work. I also am trying to scale her down 50% after the DONE button is clicked and the game is started, but I have not figured out a way for that one either. Thank you so so much for any help!
You must add information to your system about which clothes have been selected. You are right that it is about conditionals but your conditional will need the information to base the selection on. I think there are 3 alternatives:
Manage a collection of the clothes that are put on
Make clothes objects that have a property, cloth.weared = true or false
Have slots for your clothes: upperbody, lowerbody etc. and assign the selected clothes there: upperbody = somecloth;
I made 1. as a bare bones example for you. Hopefully you can understand it! May not be the most elegant solution but does work, is quite simple and I think the logic is quite close to what you already have: http://jsfiddle.net/n37qx/
var selected = [];
var SHIRT = "shirt";
var DRESS = "dress";
var TROUSERS = "trousers";
var all = [SHIRT, DRESS, TROUSERS];
//logic
function putOn(cloth) {
if (arraycontains(selected, cloth)) {
return;
}
//replace check
if (cloth === SHIRT) {
removeIfContains(selected, DRESS);
} else if (cloth === DRESS) {
removeIfContains(selected, SHIRT);
removeIfContains(selected, TROUSERS);
}
selected.push(cloth);
}
function hideNotSelected() {
for (var i=0; i < all.length; i++) {
var cloth = all[i];
if (arraycontains(selected, cloth)) {
log("wearing - not hiding: " + cloth)
} else {
log("hide: " + cloth);
}
}
}
//test flow - code instead of UI actions
log("1. Put on shirt + trousers, dress should get hidden:");
putOn(SHIRT)
putOn(TROUSERS);
hideNotSelected();
log("---");
log("2. Put on dress - trousers and shirt should get hidden:");
putOn(DRESS);
hideNotSelected();
//utilities
...
That is Javascript. Actionscript is basically Javascript (ECMAScript) with extensions. You have nice array helpers there already so don't need the ones I added to the bottom there. http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/collections/ArrayList.html