0

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!

  • Welcome, but I'm afraid you didn't ask the question very well yet. It should be as specific as possible and share the details. Ideally include the relevant part of your code and best is when you can have it running somewhere on the web so that people can try and see what the problem is. You say you've 'gotten close but nothing works' -- in that case you should show what that is so people have a chance to help fixing it. – antont May 03 '14 at 00:24
  • I found a place to upload my file for user interaction, here is the link: – user3598003 May 03 '14 at 01:58
  • http://yellownotebook.weebly.com/other-work.html – user3598003 May 03 '14 at 01:58

1 Answers1

0

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:

  1. Manage a collection of the clothes that are put on
  2. Make clothes objects that have a property, cloth.weared = true or false
  3. 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

antont
  • 2,676
  • 1
  • 19
  • 21
  • BTW option 2 is quite straightforward as your objects are already AS3 sprites or something it is straightforward to add custom properties to them; you can just say: `mctop.weared = true;` . Then instead of the list of weared clothes as in option 1 you can just use that as the data for your condition. – antont May 04 '14 at 10:00