views:

38

answers:

4

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

A: 

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?

Aaron Hathaway
Sorry if I am not clear, I am good with flash. When I double click on the symbol in a library I see that it is located at [-100,-100]. But it's instance on the stage is located at completely different coordinates. I am trying to get those original coordinates from an instance.
serg
I am pretty sure I understand what you're saying. Why are you trying to do this? Can you provide a better example? That may help solve it.
Aaron Hathaway
@Aaron Please see the updated question.
serg
A: 

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.

Tegeril
Sorry, I meant I manually put it on the stage, just by dragging it on a stage.
serg
A: 

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.

Fox
+5  A: 
// 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));
Claus Wahlers
Looks like that's what I need, thanks :)
serg
Never thought of that...very clever! +1
Fox