Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    New Coder
    Join Date
    Jun 2008
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    switch statement query

    I'm an actionscript newbie but I'm having problems with this script on my fantasy football flash team management swf which I think is a switch statement problem. I have this piece of code:

    function creatPoleShirt() {
    for (var i = 0; i<18; i++) {
    this.positionShirts.Push(this['sh'+i]);
    switch (i) {
    case 0 :
    case 11 :

    this["sh"+i].typePl = this.playerTypes[0];
    break;

    case 1 :
    case 2 :
    case 3 :
    case 4 :
    case 12 :
    case 13 :
    this["sh"+i].typePl = this.playerTypes[1];
    break;

    case 5 :
    case 6 :
    case 7 :
    case 14 :
    case 15 :
    this["sh"+i].typePl = this.playerTypes[2]
    break;

    case 8 :
    case 9 :
    case 10 :
    case 16 :
    case 17 :
    this["sh"+i].typePl = this.playerTypes[3];
    break;

    }


    Where it states cases 5 to 15, I want these to accept either this.playerTypes[2] OR this.playerTypes[3]. At the moment 5 to 15 will only allow player types 2, but I want them to accept types 3 as well if the user so chooses

    can this be easily done??? I've tried using this.playerTypes[2 and 3]; in the statement, and also using commas between the two numbers to try to link them but it doesn't work

    I'd be grateful for any advice

    cheers

    Mickey

  • #2
    New Coder
    Join Date
    Jun 2008
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I was directed to this site by someone who said there were action script experts on here who'd be able to give me some guidance. Obviously my coding problem is too complicated.

    Can anyone one here recommend a flash site where I might find an answer to this? I'm willing to pay for this code fix so I'd be grateful for any sites anyone might like to pass on.

    cheers

    mickey

  • #3
    Senior Coder gnomeontherun's Avatar
    Join Date
    Sep 2007
    Location
    Houston
    Posts
    2,846
    Thanks
    10
    Thanked 238 Times in 229 Posts
    I read this thread the other day and didn't have time to answer, but my question is can you be more clear about what you are doing?

    Do you want it to ask the user in cases 5-15 for 2 or 3, or do you just want the program to pick one randomly? I don't really understand what your question was, and that might be why nobody really was able to tackle the issue, so if you clarify I might be able to help.

    Also, there are tons of resources out there, most notably actionscript.org.

  • #4
    New Coder
    Join Date
    Jun 2008
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi Jeremy

    thanks for replying. here goes with the better (I hope) explanation


    basically take this example in the script I posted

    case 5 :
    case 6 :
    case 7 :
    case 14 :
    case 15 :
    this["sh"+i].typePl = this.playerTypes[2]
    break;


    what happens is that my flash football pitch has empty shirt objects on it labelled sh0, sh5, sh6, sh7 etc in the flash code which correspond to the case numbers in the script

    on the side of the pitch is a list of players

    type 0 are goalkeepers
    type 1 are defenders
    type 2 are midfielders
    type 3 are attackers

    the user drags players' shirts from this list and drops them into the empty shirts on the pitch

    so if he is dragging a goalkeeper onto the pitch (type 0 player) he pulls it across and drops it in the case0 empty shirt (or into the case 11 substitute golakeeper's position)

    When he picks his defenders he drags type 1 players from the list into slots on the pitch governed by

    case 5 :
    case 6 :
    case 7 :
    case 14 :
    case 15 :


    but say if he tried to drag a goalkeeper (type 0) into any of these defenders (type 1) slots he wouldn't be allowed to do it and the shirt he was dragging would not drop into the slots


    what I want to do is get the cases in the midfield section of the team

    case 5 :
    case 6 :
    case 7 :
    case 14 :
    case 15 :
    this["sh"+i].typePl = this.playerTypes[2]
    break;

    to let the user drop not just playerTypes[2] into those slots but also type 3 players which are attackers

    so what I'm looking for is a section of code that would do something like this

    case 5 :
    case 6 :
    case 7 :
    case 14 :
    case 15 :
    this["sh"+i].typePl = this.playerTypes[2] AND this.playerTypes[3]
    break;

    I'm afraid I can't make it any clearer because I don't know enough technical stuff to be able to communicate more clearly

    I could let you have urls to the flash movie if that would help

    I'm desperate to get this to work before the new football season

    cheers

    Mickey
    Last edited by mickeyb; 06-04-2008 at 10:52 PM.

  • #5
    Senior Coder gnomeontherun's Avatar
    Join Date
    Sep 2007
    Location
    Houston
    Posts
    2,846
    Thanks
    10
    Thanked 238 Times in 229 Posts
    Alright that helps a lot to clear up what you want to do.

    I've never seen switch statements written like that before, does it work? I guess I've never needed so many conditions with the same case before.

    Well you can't set it up like the AND situation, because then you would be requiring your condition to contain BOTH 2 and 3, which in no case would happen. My question now is how or what variable is available to tell what type of player the user has selected? You want it so that if I drag an attacker into 5-15 it will become an attacker? If they are dragging the attacker onto 5-15, the case as setup only filters out the position, so you would need another layer of conditional statements to figure out if it should be an attacker or midfielder. At least this is how I understand things to be working.

  • #6
    New Coder
    Join Date
    Jun 2008
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi Jeremy

    It's a script I inherited and yes, it does work.


    "You want it so that if I drag an attacker into 5-15 it will become an attacker?"

    what I mean is that from a list of midfielders and attackers (types 2 and 3)

    I can drag a midfielder into say, case 5. But if I wanted I could drag an attacker into case 5 too

    perhaps the best way to visualise it is to let you see the flash pitch. click on this http://www.thebusyhouse.co.uk/fltest/ and login as

    user: bob
    pass: smith

    then in the Welcome panel click 'here'

    The pitch comes up with the empty case shirts and on the left are listed Goalkeepers, Defenders, Midfielders and Attackers to drag onto the shirt slots


    If you look at the three shirts along the centre line, these are designated midfielder case slots taking only type 2 players (midfielders) from the list on the left. You cannot drag players from any of the other columns (goalkeeper, defenders etc) into those slots

    At the moment the user drags his strikers into the three forward positions

    I want the team manager to be able to drag players from the strikers column into those midfield slots too if he wants - so he could have a striker playing in midfield and in effect have four strikers

    I also want the script to work so that midfielders could be dragged into the strikers positions too


    what I want basically is a flexibility for the midfield and striker positions to be able to accept either one or the other. that way managers could field different formations like five midfielders and only one striker, or maybe 4 midfielders and two strikers when they select their team

    the empty shirts underneath are substitute positions which accounts for the 17 cases in all

    the league works with a cron capturing the case number players on everybody's pitch just before kick-off on Saturday, feeding it to a database and then me inputting the points scored by all the players before the script calculates each team's total points and builds a league table.

    hope this makes sense

    mickey

  • #7
    Senior Coder gnomeontherun's Avatar
    Join Date
    Sep 2007
    Location
    Houston
    Posts
    2,846
    Thanks
    10
    Thanked 238 Times in 229 Posts
    Makes enough sense to me. When a user clicks on the shirt, you need to set a variable (I'm going to call it selectedShirt here) which should be the number of the type (attackers are 3 for instance). If you already have the ability to track this, then just put that variable in here:

    Code:
    case 5 :
    case 6 :
    case 7 :
    case 14 :
    case 15 :
    this["sh"+i].typePl = this.playerTypes[selectedShirt]
    break;
    Honestly its very hard to troubleshoot actionscript because it is such a visual language. So if I'm just completely wrong, I'm sorry but this is how I understand it. I also know nothing about soccer, or football as you call it.

  • #8
    New Coder
    Join Date
    Jun 2008
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi Jeremy

    I'm not sure how to set a variable but I'll look around actionscript tutorials. Thanks very much anyway for taking the time to try to help me. I'll try your solution out when I get back home this weekend

    Cheers

    Mickey

  • #9
    New Coder
    Join Date
    Jun 2008
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    er.....

    have just rechecked that and what you suggested:

    case 5 :
    case 6 :
    case 7 :
    case 14 :
    case 15 :
    this["sh"+i].typePl = this.playerTypes[selectedShirt]
    break;

    with selectedShirt being the number of the type (midfielders are 2 for instance) is what the script already does


    case 5 :
    case 6 :
    case 7 :
    case 14 :
    case 15 :
    this["sh"+i].typePl = this.playerTypes[2]
    break;



    what I want is for the script to select from types 2 AND 3


    would setting a variable like 4 which included both 2 and 3 work do you think?

  • #10
    Senior Coder gnomeontherun's Avatar
    Join Date
    Sep 2007
    Location
    Houston
    Posts
    2,846
    Thanks
    10
    Thanked 238 Times in 229 Posts
    Can you post the FLA? I think I would understand then.

  • #11
    New Coder
    Join Date
    Jun 2008
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi Jeremy

    it all relates to this variable I think

    var playerTypes = Array("GK", "DF", "MD", "AT");

    the GK, DF etc relates to the goalkeeper, defender positions etc

    It seems to know that they are players types 0, 1, 2, 3 lower down in the code

    is there any way I can group MD and AT together in that statement so that it sees those two as playerTypes3

    I've tried

    var playerTypes = Array("GK", "DF", "MD + AT");

    but that doesn't work

    is there a way of doing this in variables?

    cheers

    Mickey

  • #12
    New Coder
    Join Date
    Jun 2008
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

  • #13
    Senior Coder gnomeontherun's Avatar
    Join Date
    Sep 2007
    Location
    Houston
    Posts
    2,846
    Thanks
    10
    Thanked 238 Times in 229 Posts
    The code we are working on is not in this file?

  • #14
    New Coder
    Join Date
    Jun 2008
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    sorry Jeremy

    It's a separate action script file in the same folder as the menage.fla on my desktop that seems to get pulled up onto the server when i upload the swf

    it's called Shirts11.as and this is its content complete with ukranian comments!


    class ShirtList extends MovieClip {
    //шаблоны для футболок
    var positionShirts:Array;
    var playerTypes = Array("GK", "DF", "MD", "AT");
    //сами футболки на поле
    var shirts_array:Array;
    var owner:MovieClip;
    var shirtsOnPole:Array;
    var nn = true;
    function ShirtList() {
    this.shirts_array = new Array();
    creatPoleShirt();
    }
    function simplifyTransfer() {
    for (var i in _global.transfers) {
    var t = _global.transfers[_global.transfers[i].pl];
    var t2 = _global.transfers[i].pl;
    if (t != undefined) {
    _global.transfers[i].pl = t.pl;
    delete _global.transfers[t2];
    }
    }
    for (var i in _global.transfersA) {
    var t = _global.transfersA[_global.transfersA[i].pl];
    var t2 = _global.transfersA[i].pl;
    if (t != undefined) {
    _global.transfersA[i].pl = t.pl;
    delete _global.transfersA[t2];
    }
    }
    }
    function makePlayerTransfer() {
    for (var i in _global.transfersA) {
    this._parent.player_array.getPlayerById(i).transid = _global.transfersA[i].pl;
    }
    }
    function makeTransfer(from:Player, to:Player) {
    from.transid = to.transid=undefined;
    if (_global.transfersA[from.id] == undefined) {
    _global.transfers[from.id] = new Object({pl:to.id});
    _global.transfersA[to.id] = new Object({pl:from.id});
    } else {
    var t = _global.transfersA[from.id].pl;
    _global.transfers[t].pl = to.id;
    delete _global.transfersA[from.id];
    _global.transfersA[to.id] = new Object({pl:t});
    }
    this.simplifyTransfer();
    this.makePlayerTransfer();
    }
    function savePlayers():Array {
    var tmp = new Array();
    for (var i = 0; i<18; i++) {
    if (this['shOnP'+i].player.choosen) {
    tmp.push(this['shOnP'+i].player.id);
    } else {
    tmp.push(-1);
    }
    }
    return tmp;
    }
    // vse ok v ney
    function creatPoleShirt() {
    // места для футболок, задаем их свойства и заносим в массив (они уже есть на поле)
    for (var i = 0; i<18; i++) {
    this.positionShirts.Push(this['sh'+i]);
    switch (i) {
    case 0 :
    case 11 :

    this["sh"+i].typePl = this.playerTypes[0];
    break;

    case 1 :
    case 2 :
    case 3 :
    case 4 :
    case 12 :
    case 13 :
    this["sh"+i].typePl = this.playerTypes[1];
    break;

    case 5 :
    case 6 :
    case 7 :
    case 14 :
    case 15 :
    this["sh"+i].typePl = this.playerTypes[2];
    break;

    case 8 :
    case 9 :
    case 10 :
    case 16 :
    case 17 :
    this["sh"+i].typePl = this.playerTypes[3];
    break;

    }
    // клипы для поля создаем новые клипы
    var _mc = this.attachMovie("shirt", "shOnP"+i, 300+i);
    _mc._visible = false;
    _mc.player = new Player();
    _mc._x = this['sh'+i]._x;
    _mc._y = this['sh'+i]._y;
    _mc.x = _mc._x;
    _mc.y = _mc._y;
    this.shirts_array.push(_mc);
    // описываем обработчики дейстий пользователя
    _mc.btn.onPress = function() {
    var papa = this._parent;
    papa.swapDepths(999);
    papa.startDrag();
    //**************
    this.onRelease = function() {
    var papa = this._parent;
    papa.stopDrag();
    this.onMouseMove = undefined;
    if ((papa._x<330) && !_global.inLife) {
    papa._visible = false;
    papa.player.choosen = false;
    papa.player = new Player();
    papa._parent.owner._refresh();
    } else {
    var tmp = papa._parent;
    for (var i = 0; i<18; i++) {
    if (papa._name == ('shOnP'+i)) {
    continue;
    }
    if (papa.player.type == tmp['sh'+i].typePl) {
    if (((papa._x+20)>tmp['sh'+i]._x) && ((papa._x-20)<tmp['sh'+i]._x) && ((papa._y+20)>tmp['sh'+i]._y) && ((papa._y-20)<tmp['sh'+i]._y)) {
    papa._x = papa.x;
    papa._y = papa.y;
    if (tmp.shirts_array[i].player.choosen) {
    //papa._parent.makeTransfer(tmp.shirts_array[i].player, papa.player);
    var ttt = tmp.shirts_array[i].player;
    tmp.shirts_array[i].player = papa.player;
    papa.player = ttt;
    } else {
    papa._parent.makeTransfer(tmp.shirts_array[i].player, papa.player);
    tmp.shirts_array[i].player.choosen = false;
    tmp.shirts_array[i].player = papa.player;
    tmp.shirts_array[i].player.choosen = true;
    tmp.shirts_array[i]._visible = true;
    tmp.owner._refresh();
    papa._visible = false;
    papa.player = new Player();
    }
    }
    }
    }
    }
    for (var i = 0; i<18; i++) {
    papa._parent['sh'+i].gotoAndStop('free');
    }
    papa._x = papa.x;
    papa._y = papa.y;
    };
    // end onMouseMove
    //**************
    this.onMouseMove = function() {
    var papa = this._parent;
    var tmp = papa._parent;
    for (var i = 0; i<18; i++) {
    if (papa.player.type == tmp['sh'+i].typePl) {
    if (((papa._x+20)>tmp['sh'+i]._x) && ((papa._x-20)<tmp['sh'+i]._x) && ((papa._y+20)>tmp['sh'+i]._y) && ((papa._y-20)<tmp['sh'+i]._y)) {
    tmp['sh'+i].gotoAndStop('roll');
    } else {
    tmp['sh'+i].gotoAndStop('rolltype');
    }
    } else {
    tmp['sh'+i].gotoAndStop('free');
    }
    }
    updateAfterEvent();
    };
    // end onMouseMove
    };
    // end onPress
    _mc = undefined;
    }
    }
    //end ok
    function loadFromArray(ar) {
    this.clearAll();
    for (var i = 0; i<18; i++) {
    if (ar[i] != undefined) {
    ar[i].choosen = true;
    this.shirts_array[i].player = ar[i];
    this.shirts_array[i].pname._visible = this.shirts_array[i]._visible=ar[i].choosen;
    }
    }
    }
    function construct() {
    if (this.nn) {
    this.loadFromArray(_global.myTeam);
    this.nn = false;
    }
    //удаляем все что было!!!
    for (var i = 0; i<50; i++) {
    this["shl"+i].removeMovieClip();
    }
    for (var i = 0; i<this.owner.cLIFV; i++) {
    var _mc = this.attachMovie("shirt", "shl"+i, 400+i);
    _mc.pname._visible = false;
    _mc.player = this.owner.ldata[(i+this.owner.startPos)];
    _mc._x = _mc.x=this.owner['c'+i].bl._x+this.owner['c'+i]._x;
    _mc._y = _mc.y=this.owner['c'+i].bl._y+this.owner['c'+i]._y+1.5;
    _mc.btn.onPress = function() {var papa = this._parent;
    if (!papa.player.active) {
    return;
    }
    //this.pname.text = this.player.name;
    papa.pname._visible = true;
    papa.startDrag();
    papa.dph = papa.getDepth();
    papa.swapDepths(999);
    //ПЕРЕдвигаем футболку из списка по полю
    this.onMouseMove = function() {
    var papa = this._parent;
    for (var i = 0; i<18; i++) {
    if (papa.player.type == papa._parent['sh'+i].typePl) {
    if (((papa._x+20)>papa._parent['sh'+i]._x) && ((papa._x-20)<papa._parent['sh'+i]._x) && ((papa._y+20)>papa._parent['sh'+i]._y) && ((papa._y-20)<papa._parent['sh'+i]._y)) {
    papa._parent['sh'+i].gotoAndStop('roll');
    } else {
    papa._parent['sh'+i].gotoAndStop('rolltype');
    }
    } else {
    papa._parent['sh'+i].gotoAndStop('free');
    }
    }
    updateAfterEvent();
    };
    //отпустили футболку из списка
    this.onRelease = function() {
    papa.stopDrag();
    papa.swapDepths(papa.dph);
    this.onMouseMove = undefined;
    for (var i = 0; i<18; i++) {
    if (((papa._x+20)>papa._parent['sh'+i]._x) && ((papa._x-20)<papa._parent['sh'+i]._x) && ((papa._y+20)>papa._parent['sh'+i]._y) && ((papa._y-20)<papa._parent['sh'+i]._y)) {
    if (papa.player.type == papa._parent['sh'+i].typePl) {
    papa._parent.makeTransfer(papa._parent.shirts_array[i].player, papa.player);
    papa._x = papa.x;
    papa._y = papa.y;
    papa._parent.shirts_array[i].player.choosen = false;
    papa._parent.shirts_array[i]._visible = true;
    papa.player.choosen = true;
    papa._parent.shirts_array[i].player = papa.player;
    papa._visible = false;
    papa._parent.owner._refresh();
    papa.pname._visible = false;
    //papa.player = new Player();
    }
    }
    papa._parent['sh'+i].gotoAndStop('free');
    }
    papa.pname._visible = false;
    papa._x = papa.x;
    papa._y = papa.y;
    };
    };
    }
    _mc = undefined;
    }
    function get getBudget() {
    var m = 0;
    for (var i = 0; i<this.shirts_array.length; i++) {
    if ((this.shirts_array[i].player.cost != undefined) && (this.shirts_array[i].player.choosen)) {
    m += Number(this.shirts_array[i].player.cost);
    }
    }
    return m;
    }
    function _refresh(re) {
    for (var i = 0; i<this.owner.cLIFV; i++) {
    this['shl'+i].reload = re;
    this['shl'+i].player = this.owner.ldata[(i+this.owner.startPos)];
    this['shl'+i]._visible = not this['shl'+i].player.choosen;
    }
    _root.showStatus();
    }
    ////////////////////////////////////////***********************************
    function clearAll() {
    for (var i = 0; i<18; i++) {
    this["shOnP"+i].player.choosen = false;
    this["shOnP"+i].player = undefined;
    this["shOnP"+i]._visible = false;
    this.owner._refresh();
    }
    }
    }

  • #15
    Senior Coder gnomeontherun's Avatar
    Join Date
    Sep 2007
    Location
    Houston
    Posts
    2,846
    Thanks
    10
    Thanked 238 Times in 229 Posts
    I'm sorry, help me figure this out. I don't have hours to sift through especially without comments I can read. I couldn't get your game to work on my computer because it pulls several files which I don't have (loads variables and stuff).

    How much AS do you know? You still need to set up a conditional somewhere, not sure exactly with this code mess, so that you can check if the selected shirt is type 2 or 3, and then run the switch you have written. You probably will write a new switch for types 2 or 3, and revise the switch you already have to only be fore types 0 and 1.

    I don't think I can write it for you because of the lack of ability to really see what the heck is going on with all of this code. So if you don't understand my suggestion, then perhaps this code is all too far above us both.


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •