4 Replies Latest reply: May 5, 2012 9:03 AM by jdhughen RSS

    inheritance between instances problem

    jdhughen Community Member

      How do you or can you "break" the inheritance properties between child instances of a Lib movie clip? I'm coming from AE and 3d. In the 3d community we would say to make an instance unique. Is that posiable in flash?  Example

      let say I have a dynamic text box "txt_Box1" whose content comes from var=TEXT and that box is place in a mc called MC_Circle which has a layer with a graphic circle element that txt_Box1 is on top of and a mask layer masking the text box in case of overflow input. MC_Circle is added to the Lib. Then another mc is created called MC_Square. Layer 1 contains a graphic square and layer 2 has an child instance of MC_Circle. This is also added to the Lib. So I have a text box masked on top of a circle placed on top of a square.  pretty simple. Now the problem I'm having comes when i want to use this element on differnt pages of my site.

       

      I have no problem getting the unique content in the box on each page using var=text=text for page x. The problem I'm having is when/if I want to make the mc container a differnent size. When I scale the mc it scales the text font size also (not what I want). I don't want to change the text font size just change the size of the square/circle/box container so it can hold more or less text of the same size. And if I change the scale of any of the elements in any of the instances it changes all the other children. I totally don't get this behavior and I'm obviously missing some vital concept here of how flash works. I would expect inheritance to flow from the parent to the child but not back upstream and not between children. if I want to change all my instances I would go back and edit the parent. I wouldn't expect edits to a child to effect a parent.

       

      I've tried making copies of  in the lib, changing names but can't find anyway to break this upstream inheritance. Is there some way for me to tell flash to "make this instance of myMovie_mc unique ??  I hope I'm making sense to somebody here

       

      Thanks

       

      Joel

       

      BTW this is AS2.0 and I'm using cs5.5

        • 1. Re: inheritance between instances problem
          Ned Murphy CommunityMVP

          I am not sure I follow each variation of your examples, but if you wanted to change different parts of a movieclip then each part needs to be a separate addressable entity within the movieclip. 

           

          If you want to scale the outermost container, then everything that is a child of it will scale as you describe.  If you want the square to be sized separately from the circle/text, then you need to have them as separate entities within a parent container.  That way you can target the square to tell it to change while leaving the circle/text unaffected.

           

          "And if I change the scale of any of the elements in any of the instances it changes all the other children."

           

          This one I do not follow.  If you mean children within the object you scaled, yes, it will.  If you mean you change the size of the textfield it also changes the size of the mask, it shouldn't.  But I am talking about changes using code, not changes done manually.

           

          If you manually change a symbol in the library, anything that uses that symbol will reflect the change.  If you wanted a variation of that shared symbol, then you create a copy of it and use the copy... but still, anything changed within that copy that is a subsymbol will affect all objects using the subsymbol.

           

          I think there was, to my disbelief, someone who showed some way of creating a copy of a symbol in the library and turning it into a unique symbol that was independent of any parts it inherited via library symbols.  If that is the beast you seek, I cannot remember if I was dreaming it or not, but I have been unable to repeat it if it actually worked.

          • 2. Re: inheritance between instances problem
            jdhughen Community Member

            Ned,

            Thanks for the reply...

            sorry if the example is not too clear. I tried to keep it simple. The actual problem is with a custom scrolling dynamic text box. It is comprosed of several nested mc's with all the controlling actionscript and slider graphic pieces, mask, etc and the text box itself being the deepest "nested" item.  The problem I'm having is I'm using instances of this "scrolling_txt_box" on for different pages. On one of the pages I want the shrik the height of the whole unit. If I just use the scale tool on the main container it scales everything down and it looks fine and the scroller works fine except the text is all squashed. If I go down inside to the text box itself and scale it back up to make the text look right then the text in the other 3 locations is all stretched tall. I can't get one to look right without making the others look bad. I tried making a COPY of the whole scrolling_txt_box unit in the library, renaming it but since the "guts" are made of the same pieces which are all also MC's then when changes are made to them they change all the other instance of themselves. It's a real nightmare. It wouldn't be a problem if I could overcome the problem with the text itself being squashed.

             

            Is there any way to scale the text box without effecting the actual font size inside the text box?

             

            In my early example when i say child I mean instance of the original master mc in the Lib. In all my experience with nested and dependent elements the idea that changing a part of a child (ie instance) would ripple back up to the parent and accross to all the other children is really odd and seems to really limit the ability to use Lib items to there full extent. While I can see times when you might want changes to ripple upstream, I can see a lot more where you wouldn't.  It looks like I'm going to have to totally build a new scrolling_txt_box, code, graphics and everthing just so it will be a little shorter in height. bummer

             

            thanks

             

            Joel

            • 3. Re: inheritance between instances problem
              Ned Murphy CommunityMVP

              I am still not clear on "what" you are scaling "how", but I can say that if you are "scaling" then whatever you are scaling is changing its characteristics.  If you scale a textfield, the characteristics of it get scaled as well.  I fyou change the width of it rather than scale it, you may not be affecting the characteristics of the text it holds (it depends at which stage you are changing its width.

               

              If you are changing things with code, then changing the size of one instance's textfield should have no effect on any other instance.  If you are changing the textfield manually, then any instance containing it will be changed.

               

              For what I think you are doing, you probably want to make the textfield and its mask and its background all separate objects and address any adjustments to their size using code.  You can make the textfield autosize so that it changes size (height, normally) to meet the needs of the text it has to hold.

              • 4. Re: inheritance between instances problem
                jdhughen Community Member

                Ned,

                Thanks for the reply.

                 

                What I ended up doing was kind of what you said. I went back through and made duplicates/renamed all the involved MC's and then "re-assembled" a new "scrolling_txt_box" (scrolling_txt_box2). since I built it using copies of the all the other MC's any code connectted with them came also. I then had to go through the code update the MC references to reflex the new names of the MC pieces, mostly by just adding a "a" to the end of the name. Everything seems to work now and I'm able to change the size of the whole unit and the text box without effecting the others.

                 

                The only problem I having now is the scroller slider tab (the part that slides up and down the track) is only moving half way. I'm getting all the text scrolled but the tab will only move down half the track, either with the mouse wheel or by click drag. You can't move it past approx 1/2 way down the scroller track.

                 

                The way I made the scroller_txt_box2 smaller was to open it and select all the graphic element MCs and mask etc (basically everything EXCEPT the text box field) and vertical scaled the whole group (using the free tranform tool) down to the height I wanted. this adjusted everything proprtionaly at once. I then selected the text box and adjusted it's starting size in it's properties to fit(I am using auto-size).

                 

                I've looked all though the code and can't find anything different (other than MC names of course) that might be causing this. Sooo....

                 

                My new question is can the group "scalling" (with the free transform tool) of the scroller graphic MC pieces to approx 1/2 the original height some how affect the travel of the "tab" in the slider ?  I did traces of all the vars related to height and travel distance as far as I can tell in the code below and could not find anything that seemed out of the ordinary. I did the same traces on the other non scaled scroller boxes and the traced var values seem to be proprtionaly the same in relation (I hope that made sense) . Since this is the only instance to this box I will be using I can hard code values if I can determine which one is affect the distance that my tab can travel. Can you see a var here that might be limiting the amount of travel of the "tab"

                 

                [CODE]

                // scroller setup

                onClipEvent (load) {

                    oldY = 1;

                    Y = 1;

                    vY = 0;

                    newY = 0;

                    mouseWheelHitTest = true;

                    contentHeight = _parent.scrolledMCa._height; // scrolledMCa is the container for the

                    scrollSpeed = _parent.speed_content;

                    scrollStep = _parent.step_content;

                    viewHeight = _parent.line._height;

                    buttonSize = _parent.dragMC._height; //this is the "tab"

                    buttonY = buttonMC._y; // this is the "tab" position

                    scrollHeight = _parent.scrolledMCa._height;

                    scrollContent = _parent.scrolledMCa._y;

                    scrollContent1 = _parent.scrolledMCa;

                    newY = _parent.scrolledMCa._height;

                    var mouseListener = new Object();

                    mouseListener.onMouseWheel = function(delta)

                    {

                        if (!mouseWheelHitTest || scrollContent1.hitTest(_root._xmouse, _root._ymouse, false) || hitTest(_root._xmouse, _root._ymouse, false))

                        {

                            if (buttonMC._y >= 0 && buttonMC._y <= scrollHeight - buttonSize + 1)

                            {

                                buttonMC._y = buttonMC._y - delta * _parent.mouse_speed;

                            }

                           // end if

                        }

                        // end if

                    };

                   // var trace results are listed in red, rounded

                    trace("contentHeight-" + contentHeight);// 423

                    trace("scrollSpeed"+scrollSpeed);// 2

                    trace("scrollStep"+scrollStep);// 2

                    trace("viewHeight-" + viewHeight);// 94

                    trace("buttonSize-" + buttonSize);// 25

                    trace("buttonY-" + buttonY);// 0

                    trace("scrollHeight-" + scrollHeight);// 423

                    trace("scrollContent-" + scrollContent);// 1

                    trace("scrollContent1-" + scrollContent1);// _level0.instance295.instance303.scrolledMC

                    trace("newY-" + newY);// 423

                //

                    Mouse.addListener(mouseListener);

                    hiScroll = _parent.line._height - _parent.dragMC._height;

                    step = (scrollHeight - buttonSize - hiScroll) / hiScroll;

                    y = _parent.scrolledMCa._y;

                //

                    // more var trace results

                    trace("buttonMC-"+buttonMC._y);// 0

                    trace("hiScroll-" + hiScroll);// 69

                    trace("y-" + y);// 1

                }

                // scrolling loop

                onClipEvent (enterFrame) {

                    if (_parent.drag_but)

                    {

                        if (buttonMC._y >= 0)

                        {

                            buttonMC._y = buttonMC._y - scrollStep;

                        }

                        // end if

                    }

                    // end if

                    if (_parent.down_but)

                    {

                        if (buttonMC._y <= scrollHeight + buttonSize)

                        {

                            buttonMC._y = buttonMC._y + scrollStep;

                        }

                        // end if

                    }

                    // end if

                    if (buttonMC._y <= 0)

                    {

                        buttonMC._y = 0;

                    }

                    // end if

                    if (buttonMC._y >= viewHeight - buttonSize)

                    {

                        buttonMC._y = viewHeight - buttonSize;

                    }

                    // end if

                    level = buttonMC._y - buttonY;

                    lev = int(y - level * step);

                    newY = oldY + (lev - oldY) / scrollSpeed;

                    _parent.scrolledMCa._y = newY;

                    oldY = newY;

                }

                 

                Ideas ???

                 

                Thanks

                 

                Joel