A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: Tips & Tricks & Optimization & professionalism

  1. #1
    Junior Member
    Join Date
    Dec 2009
    Posts
    7

    Arrow Tips & Tricks & Optimization & professionalism

    Hi everyone. I am new in flash AS3 and I have made a little game. I want you to make corrections, optimize script, give advices how to make something easier. Also, in left down corner, there is score text and try this: take 100 score, than hit enemy, than take 200 score and hit enemy again. you will get error. I tried everything and can't get rid of this error. upload_score.php is working fine:
    Code:
    <?php
    
    $db = mysql_connect('localhost', 'root', 'vertrigo');
    mysql_select_db('test', $db);
    $n = 1;
    $echo = '';
    if(!isset($_POST['hash']))	{
    $q = mysql_query("SELECT * FROM  flash ORDER BY score DESC LIMIT 10");
    while($r = mysql_fetch_array($q))	{
    $echo.= 'name'.$n.'='.$r['name'].'&score'.$n.'='.$r['score'].'&';
    $n++;
    }
    
    echo substr($echo, 0, strlen($echo)-1);
    
    }	else	{
    mysql_query("INSERT INTO flash (name, score) VALUES ('".mysql_escape_string($_POST['saxeli'])."', '".mysql_escape_string($_POST['qula'])."')");
    }
    
    ?>
    waiting for corrections and advices. thank you tooo much and sorry for my bad English . and also upload_score.php gives me that: name1=JaKo&score1=560&name2=JaKo&score2=320&name3= JaKo&score3=240&name4=Player&score4=220&name5=Play er&score5=200&name6=Player&score6=200&name7=Player &score7=200&name8=Player&score8=200&name9=Player&s core9=200&name10=Player&score10=160


    I Attached files
    Attached Files Attached Files
    Last edited by zhaniko93; 12-17-2009 at 04:23 PM.

  2. #2
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    A cursory google search reveals that mysql_escape_string is deprecated in favor of mysql_real_escape_string. The latter respects the connection character set, while the former does not. You should definitely change that.

    I haven't looked at your actionscript code, you should post specific questions about it or specific questions about the architecture design if you have them.

    Edit: Rapidshare won't let me get your file. If it's small enough, attach it to a post here. If it's too big for that, I doubt anyone will bother looking through it for you anyway.
    Last edited by 5TonsOfFlax; 12-17-2009 at 04:12 PM.

  3. #3
    Junior Member
    Join Date
    Dec 2009
    Posts
    7
    5TonsOfFlax
    Thank you, I Attached files

  4. #4
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    I don't have Flash here at work, so I can't look at the FLA. Here's some feedback about your classes.

    Bullet.as:
    • if bullet has no frames or frame script (I don't see why it would), have it extend Sprite rather than MovieClip
    • unless speed is modified externally, it could be a constant, and private.
    • use ADDED_TO_STAGE rather than ADDED. ADDED could be triggered by adding it to something which is not itself on the displayList, causing the root access to fail.
    • save the root reference as a variable of type MovieClip so that you don't have to cast it every frame.
    • add the ENTER_FRAME listener within the added function to make sure that it does not happen before the root variable is set.
    • You don't need to put "this." before x and y, but it is fine to do so.
    • If you dispatched an event from ef instead of calling removeObject directly, that would reduce the amount of coupling between Bullet and the main game. Obviously, you'd need a listener for that event in the Document class
    • avoid reaching up the hierarchy at all. Instead of keying off of root, you could have a reference to the main class and use that. Then Bullet won't have to change if you change your display structure (or load it into a new swf).

    Enemy.as:
    • again, speed could be private if it's not manipulated outside of the class
    • same points about listeners and about referencing the root.
    • same point about Sprite vs MovieClip
    • this is very similar to Bullet, structurally. You could have them extend a common superclass, but that's up to you.
    • again, avoid referencing the display hierarchy when not necessary. Pass in references to the Main class if you need to, but don't directly use root or stage if you don't have to. Those can change depending on the context you are loading your swf into.
    • Game logic, such as collision detection between enemies and bullets should be in a controller class, not in Enemy. Enemy should NOT have to know about Bullets, or scores.

  5. #5
    Junior Member
    Join Date
    Dec 2009
    Posts
    7
    5TonsOfFlax
    thank you very much for help, can you explain those lines better?:
    -add the ENTER_FRAME listener within the added function to make sure that it does not happen before the root variable is set.
    -If you dispatched an event from ef instead of calling removeObject directly, that would reduce the amount of coupling between Bullet and the main game. Obviously, you'd need a listener for that event in the Document class
    -void reaching up the hierarchy at all. Instead of keying off of root, you could have a reference to the main class and use that. Then Bullet won't have to change if you change your display structure (or load it into a new swf).

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