localToGlobal method
A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: localToGlobal method

  1. #1
    Junior Member
    Join Date
    Feb 2013
    Posts
    3

    localToGlobal method

    Hello, people!
    First off, I'm rather green when it comes to programming in actionscript so please forgive me any embarrassing mistakes in my code - trust me Im trying hard to get it done correctly.
    So, I'm having this problem that haunts me for 3 days now. I guess I can honestly admit now that I just dont know how to use this method properly.
    My stage contains two movie clips where each of them got another movie clip inside:
    forth.forths
    codes.codess
    My goal is to hitTest "forths" and "codess".

    Apparently I cant just hitTest these two normally so its where "localToGlobal" is supposed to do the trick.
    Just as shown in various tutorials, I added code to the frame in the main stage:
    Code:
    var point:Object = {x:codes.codess._x, y:codes.codess._y};
    codes.localToGlobal(point);
    What it is supposed to do is to create a point with "codess" local coordinates that later are converted into global coordinates (of the _root stage)

    So, afterwards I went to the "forths" MC and scripted it with:
    Code:
    onClipEvent(load) {
    	if(hitTest(point.x, point.y)==true) {
    		stop();
    	}
    }
    Thats it, its still not detecting any collision between these two. I've changed this code several times, added "_root" at the beggining of patchs to make sure it goes correctly to the main stage (even tho it wasnt done in tutorials).
    Hopefully someone here will be able to help me and point out that nasty mistake I made, so I can learn from it and improve my "skills".
    For any help attempts - thanks !

  2. #2
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    969
    Hi,

    Try
    PHP Code:
    onClipEvent (load) {
        if (
    this.forths.hitTest(_parent.point.x_parent.point.y))
        {
            
    trace("Hit");
        }

    you might want to use onClipEvent(enterFrame)!!!

  3. #3
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    969
    Hi,

    Or if you wish to remove the code off of the forth movie clip and put this on the timeline instead
    PHP Code:
    onEnterFrame = function ()
    {
        if (
    forth.forths.hitTest(point.xpoint.y))
        {
            
    trace("Hit");
            
    stop();
            
    delete onEnterFrame;
        }
    }; 

  4. #4
    Junior Member
    Join Date
    Feb 2013
    Posts
    3
    Thanks for a respond. Interesting way to solve the problem but unfortunately it didn't work. I think to give a better picture of whats going on in my game I'll just send my .fla so you can check it out. What Im trying to do there is to make MC "codess" (that is moving inside MC "codes") to hit "forths" (that is the MC localted in 5th frame inside "forth" MC).

    If you or someone checking it out notice anything that is done incorretly or in a unnecessary way - please let me know. It'll be a great help to me.

    Games.fla

    I had to delete some images but it should give a clue about what's the point of this game (hit that moving guy on chair with a random formula that shots off from the other characters sleeve.. its supposed to be a teacher that tries to put some knowledge inside students head, lol)

    Anyway, thanks for your efforts.

  5. #5
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    969
    Hi,

    Maybe this will give you some idea how to do it more efficiently, it still needs some work though.

    So does the student

    Its CS5 Attachment 74095

  6. #6
    Junior Member
    Join Date
    Feb 2013
    Posts
    3
    Thanks! and sorry for not being able to respond sooner, had some hardware difficulties. As for script I just checked it out and well, this seems complex but I guess I can learn some things from it.
    Thanks once again, fruitbeard!

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

Poll by Flashkit.com