A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: [Disc] Share your AS code here !

  1. #1
    Member
    Join Date
    Jul 2010
    Posts
    61

    Post [Disc] Share your AS code here !

    Share your own AS code here ! - "Only about the game"

    Rules :


    1. Your Action Script code should be about the game (Move , options , menu , etc)

    2. The code should be your own and only you can send a code from others with write the source - for example : "Wrote from F.Bayan (+)"

    3. You can't ask or request anything here , only you can look for find your AS code .

    4. Don't send HTML , Java , PHP and other . Only Action Script .

    5. Attach a FLA or SWF file to show how your code works . (optional)

    ---------

    The rules will be fuller in future .

    Share your AS code now !
    Professional WebDesigner_HTML, CSS, JS, PHP

  2. #2
    Senior Member
    Join Date
    Apr 2009
    Posts
    138
    Could I see something you have?

  3. #3
    Member
    Join Date
    Jul 2010
    Posts
    61
    Yes , It's a password box for use in games , flash websites and etc flash works . I use this code for a test game . "lp9sc" wrote this code for me , but FLA , SWF , and JPG guide files made by me .

    Password box :

    Attached : FLA Source , SWF file , JPG guide

    on(release, keyPress "<Enter>"){
    if(password=="example"){
    gotoAndStop(2)
    }
    }


    Show your AS codes now !
    Attached Files Attached Files
    Last edited by farzadbayan; 12-20-2010 at 08:06 AM.
    Professional WebDesigner_HTML, CSS, JS, PHP

  4. #4
    Senior Member
    Join Date
    Apr 2009
    Posts
    138
    Actionscript Code:
    //Temporary database setup for the items attributes, the current items, and empty item (going to remove this and put it into the item database later)
    _level0.itemdatabase = [slot1=["rod", "rod1", 0, 0, 0, 80, 0, 1, 1, "", 0, " a aa"], slot2=["tadpoles", "food", 0.3, 3, 3, 3, 1, 0, 1, "eat", 0, "The delicious tadpoles healed you by 3hp!"], slot3=["frog", "frog1", 0.5, 3.5, 4, 5, 1, 0, 1, "eat", 1, "Baby Frog: + 1 Mana, + 4 Health"], slot4=["seaweed", "food", 0.2, 2.8, -6, 0, 1, 0, 1, "eat", 3, "The seaweed is disgusting: +3 Mana, -6 Health!! - YUCK"]];
    _level0.currentitem = [slot1=["", "", 0, 0, 0, 0, 0, 0, 0, "", 0, ""]];
    _level0.playerpackempty = [slot1=["", "", 0, 0, 0, 0, 0, 0, 0, "", 0, ""]];
    _level0.playerpack = [slot1=["", "", 0, 0, 0, 0, 0, 0, 0, "", 0, ""], slot2=["", "", 0, 0, 0, 0, 0, 0, 0, "", 0, ""], slot3=["", "", 0, 0, 0, 0, 0, 0, 0, "", 0, ""], slot4=["", "", 0, 0, 0, 0, 0, 0, 0, "", 0, ""], slot5=["", "", 0, 0, 0, 0, 0, 0, 0, "", 0, ""], slot6=["", "", 0, 0, 0, 0, 0, 0, 0, "", 0, ""], slot7=["", "", 0, 0, 0, 0, 0, 0, 0, "", 0, ""], slot8=["", "", 0, 0, 0, 0, 0, 0, 0, "", 0, ""], slot9=["", "", 0, 0, 0, 0, 0, 0, 0, "", 0, ""], slot10=["", "", 0, 0, 0, 0, 0, 0, 0, "", 0, ""], slot11=["", "", 0, 0, 0, 0, 0, 0, 0, "", 0, ""], slot12=["", "", 0, 0, 0, 0, 0, 0, 0, "", 0, ""], slot13=["", "", 0, 0, 0, 0, 0, 0, 0, "", 0, ""], slot14=["", "", 0, 0, 0, 0, 0, 0, 0, "", 0, ""]];
    _level0.playerpack[0] = _level0.itemdatabase[0];
    _level0.playerpack[1] = _level0.itemdatabase[2];
    trace(_level0.playerpack[1][9]);

    /*
    Things that need to be carried over into the mainplayer5 to control the gui information.

    gui.mahpxp.manacurrent.text = manacurrentvar+" / "+manatotalvar;
    gui.mahpxp.healthcurrent.text = healthcurrentvar+" / "+healthtotalvar;
    gui.mahpxp.expcurrent.text = expcurrentvar+" / "+exptotalvar;

    //These variables are for the players status, and should be changed
    //to match the variables in all the swf files. Level0 will be needed
    */

    var currentmanavar:Number = 10;
    var totalmanavar:Number = 20;
    var currenthealthvar:Number = 250;
    var totalhealthvar:Number = 300;
    var currentexpvar:Number = 72;
    var totalexpvar:Number = 350;
    //This function creates the gui;
    function guiInt() {
        //Creates movieclip that holds the GUI.
        createEmptyMovieClip("gui", 10000, {_x:0, _y:0});
        //This creates all the empty movie clips, then the code will fill it in.
        gui.createEmptyMovieClip("mahpxp", 1, {_x:0, _y:0});
        var mc = gui.mahpxp;
        gui.createEmptyMovieClip("itemdatabase", 2, {_x:0, _y:0});
        var idb = gui.itemdatabase;
        idb._x = 433;
        idb._y = 9;
        //Attaches the health, mana and exp bar at the top right (Grey potential bar)
        mc.attachMovie("stats_gfx6", "stats_gfx6", 1, {_x:10, _y:50, _width:210, _height:9.2});
        mc.attachMovie("stats_gfx5", "stats_gfx5", 2, {_x:10, _y:35, _width:210, _height:9.2});
        mc.attachMovie("stats_gfx7", "stats_gfx7", 3, {_x:10, _y:20, _width:210, _height:9.2});
        //This transforms the potential bars colour to "myColourTransform"
        //this sets the colour of the grey bar in the background. (used for the amount of potential stat you can have
        var myColorTransform:Object = new Object();
        var myColorTransform:Object = {ra:35, rb:102, ga:35, gb:102, ba:35, bb:102, aa:100, ab:86};
        BarColourA = new Color(mc.stats_gfx6);
        BarColourB = new Color(mc.stats_gfx5);
        BarColourC = new Color(mc.stats_gfx7);
        BarColourA.setTransform(myColorTransform);
        BarColourB.setTransform(myColorTransform);
        BarColourC.setTransform(myColorTransform);
        //This creates the stat bars that show current amount of stat.
        mc.attachMovie("stats_gfx6", "exp_bar", 4, {_x:10, _y:50, _width:210, _height:9.2});
        mc.attachMovie("stats_gfx5", "health_bar", 5, {_x:10, _y:35, _width:210, _height:9.2});
        mc.attachMovie("stats_gfx7", "mana_bar", 6, {_x:10, _y:20, _width:210, _height:9.2});
        //This sets a glow filter for the current amount of stat bars
        import flash.filters.GlowFilter;
        var myGlowFilter = new GlowFilter(0x333333, 100, 1, 1, 10, 3, false, false);
        mc.health_bar.filters = [myGlowFilter];
        mc.mana_bar.filters = [myGlowFilter];
        mc.exp_bar.filters = [myGlowFilter];
       
        //Creates new text formats.
        var healthcurrent_fmt:TextFormat = new TextFormat();
        var expcurrent_fmt:TextFormat = new TextFormat();
        var mana_fmt:TextFormat = new TextFormat();
        var health_fmt:TextFormat = new TextFormat();
        var exp_fmt:TextFormat = new TextFormat();
        var idbinfo_fmt:TextFormat = new TextFormat();
            var manacurrent_fmt:TextFormat = new TextFormat();
           
        idbinfo_fmt.align = "center";
        //Creates new text fields.
        var manacurrent:TextField = mc.createTextField("manacurrent", 2001, 10, 6, 100, 20);
        var healthcurrent:TextField = mc.createTextField("healthcurrent", 2002, 10, 21, 100, 20);
        var expcurrent:TextField = mc.createTextField("expcurrent", 2003, 10, 36, 100, 20);
        var mana:TextField = mc.createTextField("mana", 2004, 187, 8, 100, 20);
        var health:TextField = mc.createTextField("health", 2005, 180, 23, 100, 20);
        var exp1:TextField = mc.createTextField("exp1", 2006, 195, 38, 100, 20);
        var idbinfo:TextField = idb.createTextField("idbinfo", 2007, 0, 45, 200, 40);
        //Sets the type of text field; Static, Dynamic, Input.
       
        _level0.looptmp = [slot1=[mana,"static",mana_fmt,"Comic-12",false,"advanced",200,-100,true,10,true],slot2=[manacurrent,"dynamic",manacurrent_fmt,null,false,"advanced",200,-100,false,null,false],slot3=[healthcurrent,"dynamic",healthcurrent_fmt,null,false,"advanced",200,-100,false,null,false],slot4=[expcurrent,"dynamic",expcurrent_fmt,null,false,"advanced",200,-100,false,null,false],slot5=[health,"static",health_fmt,"Comic-12",false,"advanced",200,-100,true,10,true],slot6=[exp1,"static", exp_fmt,"Comic-12",false,"advanced",200,-100,true,10,true],slot7=[idbinfo,"dynamic",idbinfo_fmt,"Comic-12",false,"advanced",200,-100,false,null,false]];
    //mana  manacurrent healthcurrent expcurrent health exp1 idbinfo
    //name, type, fmt name, font, selectable, alias, thickness, sharpness, embedded fonts, size, bold
        for (var v = 0; v<7;) {
        _level0.looptmp[v][0].type = _level0.looptmp[v][1];
        _level0.looptmp[v][2].font = _level0.looptmp[v][3];
        _level0.looptmp[v][0].selectable = _level0.looptmp[v][4];
        _level0.looptmp[v][0].antiAliasType = _level0.looptmp[v][5];
        _level0.looptmp[v][0].thickness = _level0.looptmp[v][6];
        _level0.looptmp[v][0].sharpness = _level0.looptmp[v][7];
        _level0.looptmp[v][0].embedFonts = q_level0.looptmp[v][8];
        _level0.looptmp[v][2].size = _level0.looptmp[v][9];
        _level0.looptmp[v][2].bold = _level0.looptmp[v][10];
        v++
        }

            //Sets the text to a specific value or variable.
        mana.text = "Mana";
        manacurrent.text = "";
        healthcurrent.text = "";
        expcurrent.text = "";
        health.text = "Health";
        exp1.text = "Exp";
        idb.idbinfo.text = "Welcome to GUI beta";
        //This applys the formats to the text fields.
        mana.setTextFormat(mana_fmt);
        manacurrent.setTextFormat(manacurrent_fmt);
        healthcurrent.setTextFormat(healthcurrent_fmt);
        expcurrent.setTextFormat(expcurrent_fmt);
        health.setTextFormat(health_fmt);
        exp1.setTextFormat(exp_fmt);
        idbinfo.setTextFormat(idbinfo_fmt);
        //This creates the text under the item database for information on examine, use, drop and what ever else.
        //This creates the Item database background image.
        idb.attachMovie("itemdb_bg", "idb_bg", 1, {_x:0, _y:0});
        //This creates the 14 item slots and moves them into position
        for (var z = 0; z<9; z++) {
        idb.createEmptyMovieClip("is0"+(z+1), (z+2));
        }
        for (var w = 9; w<14; w++) {
        idb.createEmptyMovieClip("is"+(w+1), (w+2));
        }
       
                idb.is02._x = 30;
        idb.is03._x = 60;
        idb.is04._x = 90;
        idb.is05._x = 120;
        idb.is06._x = 150;
        idb.is07._x = 180;
        idb.is08._y = 23;
        idb.is09._x = 30;
        idb.is09._y = 23;
        idb.is10._x = 60;
        idb.is10._y = 23;
        idb.is11._x = 90;
        idb.is11._y = 23;
        idb.is12._x = 120;
        idb.is12._y = 23;
        idb.is13._x = 150;
        idb.is13._y = 23;
        idb.is14._x = 180;
        idb.is14._y = 23;
        runonce2242 = true;
       

       
        //this creates the item action buttons and moves into position
        idb.attachMovie("item_wear", "item_wear", 16, {_x:0, _y:0});
        idb.item_wear._x = -66;
        idb.item_wear._y = 15;
        idb.attachMovie("item_use", "item_use", 17, {_x:0, _y:0});
        idb.item_use._x = -25;
        idb.item_use._y = 15;
        idb.attachMovie("item_inspect", "item_inspect", 18, {_x:0, _y:0});
        idb.item_inspect._x = -65;
        idb.item_inspect._y = 30;
        idb.attachMovie("item_drop", "item_drop", 19, {_x:0, _y:0});
        idb.item_drop._x = -25;
        idb.item_drop._y = 30;
        idb.attachMovie("item_combine", "item_combine", 20, {_x:0, _y:0});
        idb.item_combine._x = -65;
        idb.item_combine._y = 45;
       
        //this creates a marker to show the current item action selected
        idb.attachMovie("item_selector", "item_selector", 21, {_x:0, _y:0});
       
        //this code turns the highlighter invisible to start with.
        idb.item_selector._alpha = 23;
        idb.item_selector.blendMode = 9;
        idb.item_selector._visible = false;
        //Causes a run once function
        clearInterval(guiint);
    }
    //Runs guiInt
    guiint = setInterval(function () {
        guiInt();
    }, 1);
    function maUpdater() {
        //Short form for the level0 player stats array;
        var l = _level0;
        /*this code updates the mana so that the current mana is never more than the total mana.
        A preventive measure.
       
        _level0.currentmanavar is the current mana points
        _level0.totalmanavar mana total points
        */

        if (l.currentmanavar>l.totalmanavar) {
            l.currentmanavar = l.totalmanavar;
        }
        x1 = 1513*(l.currentmanavar/l.totalmanavar);
        gui.mahpxp.mana_bar._xscale = x1;
        gui.mahpxp.manacurrent.text = l.currentmanavar+" / "+l.totalmanavar;
        trace(x1);
        clearInterval(maupdater);
    }
    function hpUpdater() {
        //Short form for the level0 player stats array;
        var l = _level0;
        /*this code updates the mana so that the current health is never more than the total health.
        A preventive measure.
       
        _level0.currenthealthvar is the current health points
        _level0.totalhealthvar health total points
        */

        if (l.currenthealthvar>l.totalhealthvar) {
            l.currenthealthvar = l.totalhealthvar;
        }
        x1 = 1513*(l.currenthealthvar/l.totalhealthvar);
        gui.mahpxp.health_bar._xscale = x1;
        gui.mahpxp.healthcurrent.text = l.currenthealthvar+" / "+l.totalhealthvar;
        trace(x1);
        clearInterval(hpupdater);
    }
    function xpUpdater() {
        //Short form for the level0 player stats array;
        var l = _level0;
        /*this code updates the mana so that the current experience is never more than the total experience.
        A preventive measure.
       
        _level0.currentexpvar is the current experience points
        _level0.totalexpvar experience total points
        */

        if (l.currentexpvar>l.totalexpvar) {
            l.currentexpvar = l.totalexpvar;
        }
        x1 = 1513*(l.currentexpvar/l.totalexpvar);
        gui.mahpxp.exp_bar._xscale = x1;
        gui.mahpxp.expcurrent.text = l.currentexpvar+" / "+l.totalexpvar;
        trace(x1);
        clearInterval(xpupdater);
    }
    function itemUpdaterAndPressFunc() {
        trace("Item Updater");
        for (var z = 0; z<14; z++) {
            trace("For: z: "+z);
            if (_level0.playerpack[z][0] != "") {
                if (z < 10){
                    e="0";
                }else{
                    e="";
                }
                trace("is"+e+(z+1));
                gui.itemdatabase["is"+e+(z+1)].attachMovie(_level0.playerpack[z][1], _level0.playerpack[z][1], 1, {_x:0, _y:0});
                gui.itemdatabase["is"+e+(z+1)].qty.text = _level0.playerpack[z][8];
                var itemcount:TextField = gui.itemdatabase["is"+e+(z+1)].createTextField("itemcount", 2, 10, 6, 20, 20);
                gui.itemdatabase["is"+e+(z+1)].itemcount.type = dy;
                gui.itemdatabase["is"+e+(z+1)].itemcount.text = _level0.playerpack[z][8];
                gui.itemdatabase["is"+e+(z+1)].itemcount.selectable = false;
                var itemcount_fmt:TextFormat = new TextFormat();
                itemcount_fmt.color = 0xffffff;
                itemcount_fmt.align = "right";
                gui.itemdatabase["is"+e+(z+1)].itemcount.setTextFormat(itemcount_fmt);
               
                gui.itemdatabase["is"+e+(z+1)][_level0.playerpack[z][1]].onPress = function() {
                    var i:String = this;
        var slot_str:String = new String(i);
        var slotSubstring:String = new String(slot_str.substring(27,29));
        var z2:Number = new Number(parseInt(slotSubstring));
                    z2 -= 1;
                    if (gui.itemdatabase.selector_stat == "use") {
                        trace(this);
                       
                        if (_level0.playerpack[z2][9] == "eat") {
                            trace("eat")
                            if (_level0.playerpack[z2][8] == 1) {
                                gui.itemdatabase["is"+e+(z2+1)].itemcount.setTextFormat(itemcount_fmt);
                            } else {
                                _level0.playerpack[z2][8] = _level0.playerpack[z2][8]-1;
                            }
                            _level0.currenthealthvar += _level0.playerpack[z2][4];
                            _level0.currentmanavar += _level0.playerpack[z2][10];
                            maupdater = setInterval(function () {
                                maUpdater();
                            }, 1);
                            hpupdater = setInterval(function () {
                                hpUpdater();
                            }, 1);
                        }
                    }
                };
            }
            clearInterval(itemupdater);
        }
        //this code starts the click events for the item actions
        if (runonce0293 != true) {
            runonce0293 = true;
            gui.itemdatabase.item_wear.onPress = function() {
                gui.itemdatabase.selector_stat = "wear";
                gui.itemdatabase.item_selector._x = -66;
                gui.itemdatabase.item_selector._y = 15;
                gui.itemdatabase.item_selector._width = 38.1;
                gui.itemdatabase.item_selector._visible = true;
            };
            gui.itemdatabase.item_use.onPress = function() {
                gui.itemdatabase.selector_stat = "use";
                gui.itemdatabase.item_selector._x = -25;
                gui.itemdatabase.item_selector._y = 15;
                gui.itemdatabase.item_selector._width = 38.1;
                gui.itemdatabase.item_selector._visible = true;
            };
            gui.itemdatabase.item_inspect.onPress = function() {
                gui.itemdatabase.selector_stat = "inspect";
                gui.itemdatabase.item_selector._x = -65;
                gui.itemdatabase.item_selector._y = 30;
                gui.itemdatabase.item_selector._width = 38.1;
                gui.itemdatabase.item_selector._visible = true;
            };
            gui.itemdatabase.item_drop.onPress = function() {
                gui.itemdatabase.selector_stat = "drop";
                gui.itemdatabase.item_selector._x = -25;
                gui.itemdatabase.item_selector._y = 30;
                gui.itemdatabase.item_selector._width = 38.1;
                gui.itemdatabase.item_selector._visible = true;
            };
            gui.itemdatabase.item_combine.onPress = function() {
                gui.itemdatabase.selector_stat = "combine";
                gui.itemdatabase.item_selector._x = -45;
                gui.itemdatabase.item_selector._y = 45;
                gui.itemdatabase.item_selector._width = 79;
                gui.itemdatabase.item_selector._visible = true;
            };
        }
    }
    //this is to be called only as needed.
    maupdater = setInterval(function () {
        maUpdater();
    }, 1);
    hpupdater = setInterval(function () {
        hpUpdater();
    }, 1);
    xpupdater = setInterval(function () {
        xpUpdater();
    }, 1);
    itemupdater = setInterval(function () {
        itemUpdaterAndPressFunc();
    }, 1);


    I think there is more than enough explanation with this code.

  5. #5
    Senior Member
    Join Date
    Apr 2009
    Posts
    138
    by the way the code isn't more than 18% done..

    and i added an output to the code (not in the above).

    Basically this is what it does

    Arrays being created...
    Arrays: CREATED
    Setting up initial variables
    Variables: Initilized
    Creatinng Gui main function
    Gui main function: CREATED
    Creating Mana Uploader
    Mana Uploader: Created
    Creating hp Uploader
    Hp Uploader: Created
    Creating Xp Uploader
    Xp Uploader: Created
    Creating: Item Updater
    Item Updater: Created
    Run Gui function
    Run maUpdater function
    Run hpUpdater function
    Run xpUpdater function
    Run itemUpdater function
    Creating gui movieclip
    creating stats movieclip
    creating itemdatabase movieclip
    creating stat bars
    creating text fields
    Creating item database slots (movie clips)
    creating item action buttons
    Creating item action highlighter
    updating mana on call
    updating health on call
    updating xp on call
    updating database on call
    ataching item to a slot
    ataching item to a slot
    creating item action onPress functions
    Last edited by brickhouse420; 12-20-2010 at 02:48 PM.

  6. #6
    Member
    Join Date
    Jul 2010
    Posts
    61
    Quote Originally Posted by brickhouse420 View Post
    by the way the code isn't more than 18% done..
    Please test your codes and delete the parts you think they are wrong .

    Thanks a lot .
    Professional WebDesigner_HTML, CSS, JS, PHP

  7. #7
    Senior Member
    Join Date
    Apr 2009
    Posts
    138
    ugh... ?

    The code works perfect, and is exactly how i want it to work. its great!
    But, it's only 18% becaus i have like 50 other features i need to add to it, but where it stands it works fine. And I think it's optimized well

  8. #8
    Member
    Join Date
    Jul 2010
    Posts
    61
    Quote Originally Posted by brickhouse420 View Post
    ugh... ?

    The code works perfect, and is exactly how i want it to work. its great!
    But, it's only 18% becaus i have like 50 other features i need to add to it, but where it stands it works fine. And I think it's optimized well
    Sorry ! I didn't understand your purpose about 18% . Now all is OK !
    Thanks a lot ,

    To others : Send your AS codes now !
    Professional WebDesigner_HTML, CSS, JS, PHP

Tags for this Thread

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center