A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: for loop and hittest

  1. #1
    Member
    Join Date
    Feb 2008
    Location
    Turkey...Istanbul
    Posts
    83

    for loop and hittest

    Hi,
    I use arrow keys to collect five apples . I used hittest to make the collected apples invisible but there is a simple problem I can not fix..
    thanks for any help



    PHP Code:
    for(gi=0;gi<=5;gi++)
        {
        if(
    this.kare.hitTest(this.apple+gi)){
    this.apple+gi._visible=false;
        } 

  2. #2
    trace("AKA: Biro Barna");
    Join Date
    Oct 2007
    Location
    RO.Timişoara
    Posts
    1,403
    I have no idea what are trying to do with that code.



    | Windows MSN: birobarna [at] hotmail [dot] com | Skype: barna.biro |
    WebLog: http://blog.wisebisoft.com/ |
    | Software Developer / Flash & Flex Developer | Student ( Computer Science ) | Interested in: Sharing Knowledge |
    |
    Romanian Adobe Flash, Flex, AIR Forum: http://www.flashforum.ro/
    | By perseverance the snail reached the ark. |


  3. #3
    Senior Member
    Join Date
    Sep 2007
    Location
    USA................. Posts: 87,683
    Posts
    337
    I may be completely wrong but you might need to change... it into this:

    for(gi=0;gi<=5;gi++)
    {
    if(this.hitTest(this.apple+[gi])){
    this.apple+[gi]._visible=false;
    }


    What i did was remove "kare" and change "gi" to "[gi]".

    If you have only five apples you can hitTest each one rather than using the extra variables, just a suggestion but if you want to use
    "for(gi=0;gi<=5;gi++) " then its fine but it'll be slightly complicated.

  4. #4
    Senior Member
    Join Date
    Sep 2007
    Location
    USA................. Posts: 87,683
    Posts
    337
    Oh whoops, maybe you might want to change this.apple + [gi] to [ this.apple + gi ]

    My code is similar to that...I also am having hitTest problems in my game.

  5. #5
    Member
    Join Date
    Feb 2008
    Location
    Turkey...Istanbul
    Posts
    83
    Anyother suggetion please help..
    for(gi=0;gi<=5;gi++)
    {
    if(this.kare.hitTest(this.apple+gi)){
    this.apple+gi._visible=false;
    }
    }
    my Hittest is supposed to work for more objects of same name...
    Is there a method like ..getElementById().. flash..?
    may be that way I can make it work ?
    thanks

  6. #6
    http://www.in3d.eu Kostas Zotos's Avatar
    Join Date
    Jul 2007
    Location
    Athens - Greece
    Posts
    408
    Hi,

    Just if this the case: want to access multiple objects with names "apple0", "apple1", etc.. If yes, then try something like this:

    (AS):
    PHP Code:
    for(gi=0;gi<=5;gi++) { 
           var 
    mc=this["apple"+gi]
        
           if(
    this.kare.hitTest(mc)){ 
               
    mc._visible=false
           }

    Kostas
    K. Zotos online portfolio: http://www.in3d.eu

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