English 中文(简体)
行动说明 仅对一只电影的控制?
原标题:Actionscript Mouse control on ONE movieclip only?

在闪闪电/行动2中,是否有可能捕捉 mo花、 but子和 down,但只能在一个电影节中捕获?

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...

我曾尝试过大事,但要么根本不听,要么听不到整个阶段。

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;

http://www.un.org。

///////////////////////////////////////////////////////
// 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:  	"+"<b>x</b>:"+content._x+"	"+"<b>y</b>:"+content._y+newline;
table_str += "Current mouse position:  	"+"<b>x</b>:"+_xmouse+"	"+"<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();
......
最佳回答

这里可以为你工作的一种方式:你不使用听众,而是可以界定“<>onPress和为你的电影剪辑举办的活动,例如:

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());
}

  • 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.
问题回答

暂无回答




相关问题
Disable button tooltip in AS3

I want to disable the tooltip on certain buttons. The tooltip manager seems to be an all or nothing solution. Is it possible to disable the tooltip for just one or two buttons?

Sorting twodimensional Array in AS3

So, i have a two-dimensional Array of ID s and vote count - voteArray[i][0] = ID, voteArray[i][1] = vote count I want the top 3 voted items to be displayed in different colors, so i have a 2nd Array -...

Virtual Tour using sketch up, ajax, flash technologies

I want to know if there are existing technology that make your 3d models in sketch into virtual tours, using either Ajax or Flash for web presentation. If there s none, which will be a good approach ...

AS3 try/catch out of memory

I m loading a few huge images on my flex/as3 app, but I can t manage to catch the error when the flash player runs out of memory. Here is the what I was thinking might work (I use ???? because i dont ...

Red5 Security Tutorial

I am looking for a step by step tutorial on securing Red5 from intrusion. This seems to be a question that comes up alot in a google search, but is never really answered in a way that makes sense to ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

visible property of DisplayObject

For example I have a hierarchy of movie clips. mc1 is a child of mc, and mc2 is a child of mc1. Turns out that when I set mc1.visible = false; mc2.visible stays true. Is that supposed to happen?...

热门标签