It sounds like you don't have a correct understanding of object references. A lot of different variables can contain references to (or "point" to) the same object instance. A Container instance has a reference to an EdgeMetrics instance. When you execute

 

    var v:EdgeMetrics = super.viewMetrics;

 

your local variable v now contains a reference to the SAME EdgeMetrics instance that the Container is using; v and some var in the Container instance are "sharing" the same object. When you then assign

 

    v.left =  ...

 

you are modifying the shared EdgeMetrics instance.

 

Here''s a simple example of this using Arrays:

 

    var a1:Array = [ "foo" ];

    var a2 = a1;

    a2[0] = "bar";

    trace(a1[0]); // traces "bar", not "foo", because a1 and a2 are two references to the same Array object

 

In AS3 as in most languages, Arrays, Objects, and all subclasses of them are passed and returned "by reference", not "by value", because they are potentially large and it is much more efficient to pass just a 4-byte address of an object in memory rather than copying all the data inside the object. If you need your own copy, you have to make a copy. That's what a method like clone() is for. We could have implemented the viewMetrics property to make a copy, but we chose not to for performance reasons. The documentation probably isn't always clear about whether an API returns a copy or a reference to the original object.

 

- Gordon

 


From: [email protected] [mailto:[email protected]] On Behalf Of Michael Schmalle
Sent: Thursday, May 18, 2006 2:28 PM
To: [email protected]
Subject: Re: [flexcoders] Flex2B3 :: viewMtrics - borderMetrics :: What changed

 

> you shouldn't be modifying it.

Gordon, this is the delema, I'm not modifing it. I am 'getting' it. I am 'modifying' viewmetrics to add the heights of added bars into the Window.

Oh well, sounds like it's something that I have backasswarded, I will figure it out.

Thanks for your time peoplz

Peace, Mike

On 5/18/06, Gordon Smith <[EMAIL PROTECTED]> wrote:

I don't think we changed anything... properties that return an
EdgeMetrics all return a reference to the actual EdgeMetrics object used
by the container, you shouldn't be modifying it. EdgeMetrics has a
clone() method for making your own copy.

- Gordon




-----Original Message-----
From: [email protected] [mailto: [email protected]] On
Behalf Of Manish Jethani
Sent: Thursday, May 18, 2006 8:33 AM
To: [email protected]
Subject: Re: [flexcoders] Flex2B3 :: viewMtrics - borderMetrics :: What
changed

On 5/18/06, Michael Schmalle <[EMAIL PROTECTED]> wrote:

> Please refer to this post for more information.
>
> Flex2B3 :: Container subclass :: viewMetrics - borderMetrics

Okay, this one:

    override public function get viewMetrics():EdgeMetrics
    {
         var v:EdgeMetrics = super.viewMetrics;
         var b:EdgeMetrics = borderMetrics;

         trace("viewMetrics", v.left)
         trace("borderMetrics", b.left)

        if (dragEnabled) {
             if (direction == "horizontal") {
                 v.left = draggerButton.width;
             } else {
                 v.top = draggerButton.height;
             }
         }
         return v;
    }


> There is something that is fishy. I am NOT changing border metrics
but, when I go to qeury it after viewMetrics has run, it holds the
actual viewMetrics values not the simple values of 1 or 2 for solid,
outset etc...

Not sure why that's happening (don't have access to source at the
moment), but could you try making a *copy* of viewMetrics instead of
modifying the value returned by super.viewMetrics?



--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives:
http://www.mail-archive.com/flexcoders%40yahoogroups.com

Yahoo! Groups Links











--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com



SPONSORED LINKS

Web site design development

Computer software development

Software design and development

Macromedia flex

Software development best practice

 

 


YAHOO! GROUPS LINKS

 

 





--
What goes up, does come down.


--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com




SPONSORED LINKS
Web site design development Computer software development Software design and development
Macromedia flex Software development best practice


YAHOO! GROUPS LINKS




Reply via email to