Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 707751
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T04:18:49+00:00 2026-05-14T04:18:49+00:00

i’ve been working on a problem for a while now, which involves targeting the

  • 0

i’ve been working on a problem for a while now, which involves targeting the closest movieClip in relation to the x y coords of the mouse, I’ve attached a nice little acompanying graphic.

Each mc added to the stage has it’s own sub-class (HotSpots) which uses Pythag to measure distance from mouse. At this stage i can determine the closest value from my Main class but can’t figure out how to reference it back to the movieclip… hope this makes sense. Below are the two Classes.

alt text http://design.camoconnell.com/images/example.jpg

My Main Class which attachs the mcs, and monitors mouse movement and traces closest value

package {
    import flash.display.*;
    import flash.text.*;
    import flash.events.*;

    public class Main extends MovieClip
    {
        var pos:Number = 50;
        var nodeArray:Array;

        public function Main(){

            nodeArray = [];

            for(var i:int = 0; i < 4; i++)
            {

                var hotSpot_mc:HotSpots = new HotSpots;
                hotSpot_mc.x += pos;
                hotSpot_mc.y += pos;
                addChild(hotSpot_mc);

                nodeArray.push(hotSpot_mc);

                // set some pos
                pos += 70;
            }

            stage.addEventListener(MouseEvent.MOUSE_MOVE,updateProxmity)
        }

        public function updateProxmity(e:MouseEvent):void
        {
            var tempArray:Array = new Array();

            for(var i:int = 0; i < 4; i++)
            {
                this['tf'+[i]].text = String(nodeArray[i].dist);


                tempArray.push(nodeArray[i].dist);

            }

            tempArray.sort(Array.NUMERIC);
            var minValue:int = tempArray[0];
            trace(minValue)
        }
    }
}

My HotSpots Class

package {
    import flash.display.MovieClip;
    import flash.events.Event;
    import flash.text.TextField;

    public class HotSpots extends MovieClip
    {
        public var XSide:Number;
        public var YSide:Number;
        public var dist:Number = 0;

        public function HotSpots()
        {
            addEventListener(Event.ENTER_FRAME, textUp);
        }

        public function textUp(event:Event):void
        {
            XSide = this.x - MovieClip(root).mouseX;
            YSide = this.y - MovieClip(root).mouseY;
            dist = Math.round((Math.sqrt(XSide*XSide + YSide*YSide)));
        }   
    }
} 

thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T04:18:49+00:00Added an answer on May 14, 2026 at 4:18 am

    Seems to be straight forward …

    Add a method to into the HotSpots so you can externally set its state :

    public function set isClosest(value:Boolean):void
    {
        // do something here, example :
        alpha = (value) ? 1 : .5;
    }
    

    Each time you’ve updated the distances you can now use the newly created method to make the HotSpots ‘aware’ of their respective position :

    for(var i:int = 0; i < 4; i++)
    {
       // sets the first hotspot to isClosest = true and the others to false ...
       (nodeArray[i] as HotSpots).isClosest = (i == 0);
    }
    

    EDIT : Following your second answer, …

    Quickly to find the closest without using Array.sortOn you can proceed like following. But now I think the whole code is a bit of the wrong way around (why would you have to calculate the distance from within the object, etc.).

    // For iteration only 
    var hotSpot:HotSpots;
    
    // Keeps track of the so far closest hotSpot
    var closestHotSpot:HotSpots;
    
    // Stores the so far closest distance (to avoid recalculating each time)
    var closestDistance:Number; 
    
    // Finds out the closest
    for each(hotSpot in nodeArray)
    {
        if(closestHotSpot == null ||  nodeArray[i].dist < closestDistance)
        {
           closestHotSpot = hotSpot;
           closestDistance = hotSpot.dist; 
        }
    }
    
    // Applies the right state to each of the hotSpots
    for each(hotSpot in nodeArray)
    {
        hotSpot.isClosest = (hotSpot == closestHotSpot);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 421k
  • Answers 421k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer std::string::find() has an optional argument to indicate where to begin… May 15, 2026 at 10:50 am
  • Editorial Team
    Editorial Team added an answer http://dev.mysql.com/doc/refman/5.0/en/create-index.html "A UNIQUE index creates a constraint such that all… May 15, 2026 at 10:50 am
  • Editorial Team
    Editorial Team added an answer cos is expensive, especially 4 in a row. You appear… May 15, 2026 at 10:50 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.