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

  • Home
  • SEARCH
  • 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 580659
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:29:46+00:00 2026-05-13T14:29:46+00:00

In Flash/ActionScript2, is it possible to capture the mousemove, buttonup and down event but

  • 0

In Flash/ActionScript2, is it possible to capture the mousemove, buttonup and down event but only within one MovieClip?

At present, i can capture mousemove etc. via a listener, but only for the entire stage…
I need to draw a rectangle for selecten, and then press a save button. The problem is i save the coordinates on mousedown and up, but when I press on the save button, it saves the coordinates of when you pressed on the save button…

I’ve tried mc.onXY, but that either listened not at all or to the entire stage…

Edit: Code as requested
mc.onMouseDown
should be
mcImageToCrop.onMouseDown
I did change it back to mc when mcImageToCrop didn’t work…

`

    import flash.geom.Rectangle;


// Create a container by calling the setUpContainer functie wich will return a movieclip with a needed propeties set.
var container:MovieClip = setUpContainer();

// Create rectangle named window to create our gradient in it.
var window:Rectangle = new Rectangle(400, 230, 265, 240);

// Set our created window rectangle as a scrollRect property to the container movieclip.
// Rectangle constructor params are x, y, width, height
//container.scrollRect = window;




//this.opaqueBackground = 0xFF0000;//0xCCCCCC;


var mcImageToCrop:MovieClip ;
var mc:MovieClip;
var mcControls:MovieClip ;
//all drawing,positioning and coloring will be set in this function:
function setUpContainer():MovieClip 
{
    mc = this.createEmptyMovieClip("mc", this.getNextHighestDepth());
    mc._x = 0;
    mc._y = 0;
    mc.opaqueBackground = 0xF0F0F0;//0xCCCCCC;



mcImageToCrop = mc.createEmptyMovieClip("mcImageToCrop", mc.getNextHighestDepth());
var mcLoader:MovieClipLoader = new MovieClipLoader();
mcLoader.addListener(this);
mcLoader.loadClip("Test.swf", mcImageToCrop); //load the tower movie clip


mcImageToCrop.onKeyDown=function()
{
    trace("KeyDown");
}

///////////////////////// Button //////////////////////////////////
mcControls=this.createEmptyMovieClip("mcControls", 500);//this.getNextHighestDepth());  // 2=  restrect depth
mcControls._x = 0;
mcControls._y = 480;
//mcControls.opaqueBackground = 0x00FF00;//0xCCCCCC;

mcControls.onPress=function()
{
    trace("Save coord");
}

mcControls.lineStyle(1,0x000000,100);

var startX=0;
var startY=00;
var rwidth=100;
var rheight=30;

mcControls._alpha = 80;
mcControls.beginFill(0x000000);
mcControls.moveTo(startX,startY); // oben links
mcControls.lineTo(startX+rwidth,startY);
mcControls.lineTo(startX+rwidth,startY+rheight);// unten rechts
mcControls.lineTo(startX,startY+rheight);
mcControls.lineTo(startX,startY); // I think this isn't needed anyway
mcControls.endFill();
//public createTextField(instanceName:String, depth:Number, x:Number, y:Number, width:Number, height:Number) : TextField
//  this.createTextField("button_text", 5, x, y, 100, 50);
this.createTextField("button_text", 501, 25, 485, 100, 5);
var bntTxtFmt:TextFormat = new TextFormat();
bntTxtFmt.color=(0xFFFFFF);
bntTxtFmt.bold=true;

button_text.html = true;
button_text.wordWrap = true;
button_text.border = false;
button_text.autoSize = true;
button_text.selectable = false;
button_text.textColor = (0xFFFFFF);
//button_text.backgroundColor=0xD1D6FC;
//button_text.setTextFormat(bntTxtFmt);
button_text.htmlText = "Speichern";
///////////////////////// End Button //////////////////////////////////



this.onLoadInit = function (target_mc:MovieClip)
{
    trace("Onloadinit:target_mc width: " + target_mc._width + " target_mc height: " + target_mc._height);
    trace("Onloadinit Stage width: " + Stage.width + " Stage height: " + Stage.height);
    trace("Onloadinit mcImageToCrop width: " + mcImageToCrop._width + " mcImageToCrop height: " + mcImageToCrop._height);
    /*
    width: 1024 
    height: 768
    Stage: Height X :640 Height Y: 480
    loadinit Stage height: 480 - This height: 768
    */
    var percentW = Stage.width*100 / mcImageToCrop._width;
    var percentH = Stage.height*100 / mcImageToCrop._height;

    mcImageToCrop._xscale = percentW;
    mcImageToCrop._yscale = percentH;



    window.x = 249; // 400
    window.y = 143; // 230
    window.width=163; // 265
    window.height=149; // 240

    var UnscaledX=249*100/percentW;
    var UnscaledY=143*100/percentH;
    var UnscaledW=163*100/percentW;
    var UnscaledH=149*100/percentH;

    container.scrollRect = window;

    // Zurückskalieren des Ausschnitts auf Originalgrösse
    container._xscale = 10000/percentW; // =100* 100* 1/(percentW/100)
    container._yscale = 10000/percentH;

    trace("Onloadinit Scale X :" + mcImageToCrop._xscale + " Scale Y: " +   mcImageToCrop._yscale );
}



//mcLoader.loadClip("Test3.swf", mcControls);
return mc;

enter code here}

///////////////////////////////////////////////////////
// Text field for mouse position
this.createTextField("mouse_info", 999, 5, 5, 250, 80);
mouse_info.html = true;
mouse_info.wordWrap = true;
mouse_info.border = false;
mouse_info.autoSize = true;
mouse_info.selectable = false;
///////////////////////////////////////////////////////




var mouseListener:Object = new Object();


var rectStartX;
var rectStartY;

var rectStopX;
var rectStopY;

var bMouseIsDown:Boolean=false;

mc.onMouseDown = function() 
{
    bMouseIsDown=true;
    rectStartX=_xmouse;
    rectStartY=_ymouse;
    trace("Clicked at x: " + _xmouse + " y: " +_ymouse);
}




mc.onMouseUp = function()
{
    bMouseIsDown=false;
    trace("Released at x: " + _xmouse + " y: " +_ymouse);
    rectStopX=_xmouse;
    rectStopY=_ymouse;
}




mc.onMouseMove = function() 
{
    if(!bMouseIsDown)
    {
        //Line.removeMovieClip();
        return;
    }


    ////////////////////////////////////////////

    rectangles2.removeMovieClip();

    //var rectangles2:MovieClip = createEmptyMovieClip("rectangles2", 1);
    var rectangles2:MovieClip = createEmptyMovieClip("rectangles2", mc.getNextHighestDepth());
    rectangles2.lineStyle(1,0x000000,100);

    var startX=rectStartX;
    var startY=rectStartY;
    var rwidth=_xmouse-rectStartX;
    var rheight=_ymouse-rectStartY;

    rectangles2._alpha = 80;
    rectangles2.beginFill(0xF5F5F5);

    rectangles2.moveTo(startX,startY); // oben links
    rectangles2.lineTo(startX+rwidth,startY);
    rectangles2.lineTo(startX+rwidth,startY+rheight);// unten rechts
    rectangles2.lineTo(startX,startY+rheight);
    rectangles2.lineTo(startX,startY); // I think this isn't needed anyway
    rectangles2.endFill();




    ///////////////////////////////////////////////

var table_str:String = "";


//table_str += "Current content position:  \t"+"<b>x</b>:"+content._x+"\t"+"<b>y</b>:"+content._y+newline;
table_str += "Current mouse position:  \t"+"<b>x</b>:"+_xmouse+"\t"+"<b>y</b>:"+_ymouse+newline;
table_str += "";
mouse_info.htmlText = table_str;
};


// Mouseaction listener
//Mouse.addListener(mouseListener);




Stage.align = "TL";
Stage.scaleMode = "noScale";
//Stage.scaleMode = "exactFit";


// STAGE RESIZE LISTENER
var stageListener:Object = {
    onResize: resizeHandler
};

Stage.addListener( stageListener );


// STAGE RESIZE HANDLER
function resizeHandler():Void
{
    var w:Number = Stage.width;
    var h:Number = Stage.height;

    // mc, mcImageToCrop
    //_root.mc._height = 400;
    //_root.mc._width = 400;

    //trace("Resized to w: "+ w +" and h: " + h);
}


resizeHandler();
`
  • 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-13T14:29:46+00:00Added an answer on May 13, 2026 at 2:29 pm

    Here’s one way that might work for you: instead of using a listener, you can define onPress and onRelease events for your movieClip, like this:

    import flash.geom.Point;// you'll need this if you want to store your coordinates as Point objects
    
    var startPoint:Point = new Point();
    var endPoint:Point = new Point(); 
    
    myClip.onPress= function() {
        startPoint.x=this._xmouse; //gives x-coord relative to myClip...
        startPoint.y=this._ymouse; // ...for coords relative to stage, omit "this."
        trace("start: "+startPoint.toString());
    }
    
    myClip.onRelease= function() {
        endPoint.x=this._xmouse;
        endPoint.y=this._ymouse;
        trace("end: "+endPoint.toString());
    }
    
    myButton.onRelease= function() {
        trace("saved coordinates: "+startPoint.toString()+endPoint.toString());
    }
    

    Note the difference between

    • onMouseUp = function() {} Invoked when the mouse button is pressed. (anywhere)
    • onPress = function() {} Invoked when the user clicks the mouse while the pointer is over a movie clip.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 451k
  • Answers 451k
  • 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 You shouldn't have to impersonate the service account. The service… May 15, 2026 at 8:57 pm
  • Editorial Team
    Editorial Team added an answer Firstly, I'm assuming the line: Dim c As pluto =… May 15, 2026 at 8:57 pm
  • Editorial Team
    Editorial Team added an answer Here is a complete walkthrough http://msdn.microsoft.com/en-us/library/cc716679.aspx May 15, 2026 at 8:57 pm

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.