How to get local symbol coordinates from actionscript?
I have a symbol originally created at [-100,-100] coordinate (left top corner). Now I put an instance of this symbol on a stage at [0,0] stage coordinates (by dragging it with a mouse in IDE). Having this instance can I still determine original [-100,-100] position from actionscript somehow? (myInstance.x
returns stage coordinate).
What I do:
- create a new symbol in a library located at -100,-100 coordinates du开发者_如何学编程ring its creation
- put an instance of this symbol on the stage at some different coordinates
- in actionscript try to get original -100 value from instance object, like:
this.myInstance.x
(only this returns stage coordinates)
Why I am doing this:
I am trying to put this movieclip into a BitmapData:
var myClip:MovieClip = this.myInstance;
var bmp:BitmapData = new BitmapData(myClip.width, myClip.height);
bmp.draw(myClip);
The problem is BitmapData looks like taking only part of a clip that lies in positive coordinates. To overcome this I would need to provide transform matrix with corresponding offsets:
var m:Matrix = new Matrix();
m.tx = 100;
m.ty = 100;
bmp.draw(myClip, m);
I would be able to calculate this offset if I knew original symbol coordinates before it was dropped on a stage.
Hopefully this makes sense.
// get bounds including strokes
// traces (x=-105, y=-105, w=110, h=110)
trace(myInstance.getBounds(myInstance));
// get bounds excluding strokes
// traces (x=-100, y=-100, w=100, h=100)
trace(myInstance.getRect(myInstance));
I think I see what you're saying. If you have a name object inside of your symbol I think you can achieve this. For instance, if you have a symbol that has an image named myImage in it at (x, y). I believe you could use mySymbol.myImage.x or mySymbol.myImage.y. Is that what you mean?
Your object could store its position at the time it is added to the stage before it is moved by listening to the Event.ADDED_TO_STAGE in a Point object.
Thanks for the clarification, makes a lot more sense now!
What you're asking is how to find the coordinates of the graphics inside of the MovieClip correct? To do this, You have to store the graphics in another symbol. So, simply double click the symbol and select all of the graphics inside of it. hit F8 to make it another symbol and give it an instance name to your liking (bar for example). Essentially what you're doing is making a MovieClip in a MovieClip.
Now when you add an instance of the symbol to the stage (say its name is foo), just do foo.bar.x or foo.bar.y and you'll see the graphics location.
精彩评论