Implicit parent class/object reference

Hello,
Is there any way I can get an implicitly reference to the class/object that instantiated a second object ? At the moment I have been doing this by creating this explicitly by passing the parent object as an argument through the constructor of the object to store it, but it would be nice if there was an implicit parent reference somewhere accessible from within the newly created object. Any thoughts about this ?
Many Thanks,
Rems

public class Thing {  // note: extends Object, implements no interface
  private Factory creator;
  Thing(Factory creator) {
    this.creator = creator;
  public void foo() {
    // do stuff here
public class DifferentThing // also extends Object, implements no interface, and doesn't subclass Thing
  private Factory anyName;
  DifferentThing(Factory whatever) {
    anyname = whatever;
  public int bar(String x) {
    // do completely different stuff here
public class Factory {
  public Object create(String s) {
    if (s.equals("Thing")) {
      return new Thing(this);
    } else if (s.equals("Different thing")) {
      return new DifferentThing(this);
    } else {
      return null;
}There you go. A brain-dead simple Factory class, that generates objects of different classes, which do not implement a common interface, and neither extends the other, yet both have a reference to the factory method that created them. All you have is a convention that the constructors of the classes in question take a Factory object as a parameter.

Similar Messages

  • How to refer the parent class object from an inner class

    Hi,
    I have a class X, which contains an inner private class Y. Class X has a method getY which returns an object of class Y. Class Y has a method getParent. I want to return the object of parent class from this. The code is like this:
    public inerface IY;
    public class X {
    private class Y implements IY {
    public getParent {
    // ... return the object of parent class which created the object of this inner class
    public IY getY() {
    return new Y();
    Can somebody help me with this...

    interface IY {
    public class X {
        private class Y
            implements IY {
            private X parent;
            public Y(X x)
                parent = x;
            public X getParent()
                // ... return the object of parent class which created the object of this inner class
                return parent;
        public IY getY()
            return new Y(this);
    }Filip

  • Create a entity object myself in a Parent class

    1) I made 2 tables, a parent and a child.
    2) I created entity classes out of them, and an association.
    Now I want a method in the parent-class, where I create a child, belonging to the parent. How do I do that? I see no constructor, just a Create(), but what do I fill in for the attributelist, I guess the attributes :-) but how do these two objects reference to each other?
    So I'm looking for something like this code in the Parent class:
    public void addChild(String NameChild)
    Child.create(NameChild, This)
    Is this correct? Or not?
    null

    Are you looking for a Composition ie "Child" should be contained in a "Parent"?

  • How to reference the Parent view Object attribute in Child View object

    Hi , I have the requirememt to generate Tree like struture to display Salary from joining date to retirement date in yearly form.I have writtent two Pl/SQL function to return parent node and child nodes(based on selected year).
    1.First function --> Input paramter (employee id, retirement date , joining date) --> return parent node row with start_date and end_date
    2. 2nd function --> input paarmter(employee id, startDate, end_date) --> return child node based on selected parent node i.e. start date and end date
    I have created two ADF view object based on two function return
    Parent Node --> select * from Table( EUPS.FN_GET_CONTR_SAL_BY_YR(employeeId,retirement Date, dateOf joining)) ;
    Child Node --> select * FROM TABLE( EUPS.FN_GET_CONTR_SAL_FOR_YEAR( employeId,startDate, endDate) ) based on selected parent node.
    I am giving binding variable as input for 2nd function (child node) . I don't know how to reference the binding variable value in child view from parent view.
    Like I have to refernce employeId,startDate, endDate values in 2nd function from parent view object. some thing like parentNode.selectedStart_date parentNode.employeeId.
    I know we can achive this writing the code in backing bean.But i want to know how can we refernce parent view object attribute values in child view object using Groovy or otherway?
    I will appreciate your help.
    Thanks

    I have two view com.ContractualSalaryByYearlyView for Parent Node and com.ContractualSalaryByYearlyView for child Node.
    I have created view link(ContractualSalYearlyByYearViewLink) betweem two view by giving common field empId, stDate , endDate.(below is the view link xml file).
    I tried give the binding attribute values using parent object reference like below in com.ContractualSalaryByYearlyView xml file but getting error
    Variable ContractualSalaryByYearlyView not recognized.I think i am using groovy expression.
    Thanks for quick response.
    com.ContractualSalaryByYearlyView xml
    <ViewObject
    <DesignTime>
    <Attr Name="_isExpertMode" Value="true"/>
    </DesignTime>
    <Variable
    Name="empId"
    Kind="where"
    Type="java.lang.Integer">
    <TransientExpression><![CDATA[adf.object.ContractualSalaryByYearlyView.EmpId]]></TransientExpression>
    </Variable>
    ContractualSalYearlyByYearViewLink.xml file
    <ViewLinkDefEnd
    Name="ContractualSalaryByYearlyView"
    Cardinality="1"
    Owner="com.ContractualSalaryByYearlyView"
    Source="true">
    <DesignTime>
    <Attr Name="_finderName" Value="ContractualSalaryByYearlyView"/>
    <Attr Name="_isUpdateable" Value="true"/>
    </DesignTime>
    <AttrArray Name="Attributes">
    <Item
    Value="com.ContractualSalaryByYearlyView.EmpId"/>
    <Item
    Value="com.ContractualSalaryByYearlyView.StDate"/>
    <Item
    Value="com.ContractualSalaryByYearlyView.EndDate"/>
    </AttrArray>
    </ViewLinkDefEnd>
    <ViewLinkDefEnd
    Name="ContractualSalaryForYearView"
    Cardinality="-1"
    Owner="com.ContractualSalaryForYearView">
    <DesignTime>
    <Attr Name="_finderName" Value="ContractualSalaryForYearView"/>
    <Attr Name="_isUpdateable" Value="true"/>
    </DesignTime>
    <AttrArray Name="Attributes">
    <Item
    Value="com.ContractualSalaryForYearView.EmpId"/>
    <Item
    Value="com.ContractualSalaryForYearView.StDate"/>
    <Item
    Value="com.ContractualSalaryForYearView.EndDate"/>
    </AttrArray>
    </ViewLinkDefEnd>

  • How to access the parent class variable or object in java

    Hi Gurus,
    I encounter an issue when try to refer to parent class variable or object instance in java.
    The issue is when the child class reside in different location from the parent class as shown below.
    - ClassA and ClassB are reside in xxx.oracle.apps.inv.mo.server;
    - Derived is reside in xxx.oracle.apps.inv.mo.server.test;
    Let say ClassA and ClassB are the base / seeded class and can not be modified. How can i refer to the variable or object instance of ClassA and ClassB inside Derived class.
    package xxx.oracle.apps.inv.mo.server;
    public class ClassA {
        public int i=10;
    package xxx.oracle.apps.inv.mo.server;
    public class ClassB extends ClassA{
        int i=20;   
    package xxx.oracle.apps.inv.mo.server.test;
    import xxx.oracle.apps.inv.mo.server.ClassA;
    import xxx.oracle.apps.inv.mo.server.ClassB;
    public class Derived extends ClassB {
        int i=30;
        public Derived() {
           System.out.println(this.i);                  // this will print 30
           System.out.println(((ClassB)this).i);  // error, but this will print 20 if Derived class located in the same location as ClassB
           System.out.println(((ClassA)this).i);  // error, but this will print 20 if Derived class located in the same location as ClassA
        public static void main(String[] args) { 
            Derived d = new Derived(); 
    Many thanks in advance,
    Fendy

    Hi ,
    You cannot  access the controller attribute instead create an instance of the controller class and access the attribute in the set method
    OR create a static method X in the controller class and store the value in that method. and you can access the attribute by 
    Call method class=>X
    OR if the attribute is static you can access by classname=>attribute.
    Regards,
    Gangadhar.S
    Edited by: gangadhar rao on Mar 10, 2011 6:56 AM

  • How to reference the class-instance, created in parent class.

    Hi, I have following scenario. During compilation I am gettting error message -- "cannot resolve symbol - symbol : Variable myZ"
    CODE :
    under package A.1;
         ClassZ
         Servlet1
              ClassZ myZ = new ClassZ;
    under package A.2;
         Servlet2 extends Servlet1
              myZ.printHi();
    How to reference the class-instance created in the parent class?

    some corrections ...
    under package A.1;
         ClassZ
         Servlet1
              init()
                   ClassZ myZ = new ClassZ;
    under package A.2;
         Servlet2 extends Servlet1
              myZ.printHi();

  • Plugins using Parent (calling object or Class)'s Methods

    I would like to know if this design makes sense (or if im abusing the inheritance concept of java)
    This comes about because :: Plugins, that are only known about at runtime, know of each others existance. But the core application does not know about plugins until runtime. The plugins might be reused so the core calling class may not be known till runtime either. So
    Public Static Class PluginContainer {
    Main() {
    doSearchofDirectoryForUseablePlugins()
    while pluginsLeft {
    Load plugin so it can be referenced by name();
    plugin[x].runmain()
    SendMessage( String pluginName, Object message) {
    doBlahToFindCorrectPlugin();
    plugin[x].doSomethingWithMessage( Object message);
    public Class plugin { // in a far off directory
    public plugin() { //setup myself blah}
    public runmain( ) { //do stuff
    // ohh lets find out if my plugin friends are here
    Class myParent = this.getSuperClass(); // does this give me my parent given that my parent is static??
    myParent.sendMessage("Friend", aLittleSomethingiMadeEarlier);
    Is this the correct way of doing this? Im new to this type of java programming. This comes late in the night - so i may be completely loopy over this apparent problem that seems so easy!
    Thanks in Advance
    Gary

    1. You cannot declare a static top level class. Only nested classes (classes that are members of the surrounding class) can be declared static.
    2. The Plugin class does not extend PluginContainer so PluginContainer is not the parent class, the Object class is.
    What you probably want to do is declare a Plugin interface and have all you plugins implement that interface.

  • Getting the calling object reference / class?

    Dear forum members,
    Is it possible for A in the below example to get that B was the "caller"?
    class A {
      A() {
      public void someMethod(String text) {
        System.out.println("I was called with: " + text);
        System.out.println("I was called by: " + thatMagicWayToGetCallerClassOrReference());
    class B {
      public static void main(String[] args) {
        A a = new A();
        a.someMethod("HOLA HOLA");
    }

    Another way of getting the class of your caller is to use a SecurityManager object. getClassContext() is protected but you can get at it by subclassing SecurityManager (it works if you just instanciate the manager without installing it). This gives you a reference to the Class object itself where the stack trace returns only the class name. Bear in mind that the class in question will be several items up the array, the first entry is the SecurityManager itself, the second the called class.
    However, I agree with others it doesn't sound like the best design. If you're having trouble with not being able to change the interface specifications to pass the extra information then consider using a static reference, if necessary a ThreadLocal. What happens if you want to call the offending method indirectly through some central method at some future time? You've lost the call origin data.
    Why can't you simply add a parameter to the offending call?

  • Error 1054 Open VI Object Reference

    Hi Ppl,
    I'm using LabVIEW 8.6 and I'm debugging a code that uses the  Open VI Object Reference node. The parent reference thats passed in is a refrence of a VI instance and the vi object class is the control type. Though the control is present in the VI, the node returns error 1054 and says object not found. 
    I'm wondering why this was. However when the parent is the VI reference itself instead of the instance VI this works. I'm not able to understand the problem.
    Thanks,
    Sathish

    Sorry, I made what you have told me:
    now i have this error:
     why? If you have implemented a correct Vi can you give me it please?
    Thanks!
    Attachments:
    ClearChart.vi ‏14 KB
    test.vi ‏12 KB

  • My derived class suddenly doesn't recognize the parent class

    I had my assignment coded, debugged, working and ready to go. So I bring my flash drive upstairs to play around with it on my other computer. When I compile the base class it compiles fine, but now when I try to compile the derived class, and the test class with the main method, I'm coming up with errors.
    They have something to do with the base class not being recognized, because I can't instantiate any objects of the class now, and i get an error when attempting to compile the derived class to the effect of "cannot find symbol; symbol: class BaseClass". i get this error throughout the derived class, from the initial declaration of the class (public class DerivedClass extends BaseClass), to any references made toward methods of the parent class.
    My base class compiles with no problem, but it's like nothing else is able to "use" it. I'm not sure if it has something to do with the PC im using now, and I can't confirm this at the moment because the PC I used to write the code is down (waiting on an upgrade).
    ehhh.....help.
    Message was edited by:
    asphaltninja
    null

    It's not the fault of the computer hardware.
    It's not the fault of the operating system.
    It's not the fault of the JDK.
    So don't go rebooting or reinstalling anything. The problem is that you didn't set up things on the new computer in the same way they were set up on the old computer.
    In particular the compiling problem is that the compiled version of BaseClass isn't in the classpath when you try to compile DerivedClass. I can't tell why from your description.

  • Throwing null object reference , when focus into the spark textarea ,if it is in the popup

    I added a textarea to vrgoup container and added that vgroup as popup to the application. while i am trying to focus into the textarea , it always throwing me null object reference. to see that you need to have debugger version of flash player installed. please help me if anybody knows the solution.
    here is my code.
    code
    protected function btn_clickHandler(event:MouseEvent):void
    var vgroup:VGroup = new VGroup();
    var ta:TextArea = new TextArea();
    vgroup.percentWidth = 100;
    vgroup.addElement(ta);
    PopUpManager.addPopUp(vgroup, this);
    Following is the error thrown
    TypeError: Error #1009: Cannot access a property or method of a null object reference.
    at spark.components::Scroller/focusInHandler()[E:\dev\hero_private\frameworks\projects\spark \src\spark\components\Scroller.as:1258]
    at flash.display::Stage/set focus()
    at flashx.textLayout.container::ContainerController/http://ns.adobe.com/textLayout/internal/2008::setFocus()[C:\Vellum\branches\v2\2.0\dev\out put\openSource\textLayout\src\flashx\textLayout\container\ContainerController.as:2265]
    at flashx.textLayout.container::ContainerController/mouseDownHandler()[C:\Vellum\branches\v2 \2.0\dev\output\openSource\textLayout\src\flashx\textLayout\container\ContainerController. as:2067]
    at flashx.textLayout.container::TextContainerManager/mouseDownHandler()[C:\Vellum\branches\v 2\2.0\dev\output\openSource\textLayout\src\flashx\textLayout\container\TextContainerManage r.as:1939]
    at spark.components.supportClasses::RichEditableTextContainerManager/mouseDownHandler()[E:\d ev\hero_private\frameworks\projects\spark\src\spark\components\supportClasses\RichEditable TextContainerManager.as:665]
    at flashx.textLayout.container::ContainerController/http://ns.adobe.com/textLayout/internal/2008::requiredMouseDownHandler()[C:\Vellum\branche s\v2\2.0\dev\output\openSource\textLayout\src\flashx\textLayout\container\ContainerControl ler.as:2088]
    at flash.events::EventDispatcher/dispatchEventFunction()
    at flash.events::EventDispatcher/dispatchEvent()
    at mx.core::UIComponent/dispatchEvent()[E:\dev\hero_private\frameworks\projects\framework\sr c\mx\core\UIComponent.as:13128]
    at mx.managers::SystemManager/mouseEventHandler()[E:\dev\hero_private\frameworks\projects\fr amework\src\mx\managers\SystemManager.as:2924]

    The simplest example I could come up with consists of 3 files:
    Main.mxml
    <?xml version="1.0" encoding="utf-8"?>
    <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
                      xmlns:s="library://ns.adobe.com/flex/spark"
                      xmlns:mx="library://ns.adobe.com/flex/mx"
                      applicationComplete="open()">
         <fx:Script>
              <![CDATA[
                   import mx.managers.PopUpManager;
                   public function open():void {
                        var popUp:CustomComponent = PopUpManager.createPopUp(
                             this, //parent
                             CustomComponent, //class name
                             true //modal
                        ) as CustomComponent;
                        PopUpManager.centerPopUp(popUp);
              ]]>
         </fx:Script>
    </s:Application>
    CustomComponent.as
    package {
         import spark.components.supportClasses.SkinnableComponent;
         public class CustomComponent extends SkinnableComponent {
              public function CustomComponent() {
                   super();
                   setStyle('skinClass', CustomComponentSkin);
    CustomComponentSkin.mxml
    <?xml version="1.0" encoding="utf-8"?>
    <s:Skin xmlns:fx="http://ns.adobe.com/mxml/2009"
              xmlns:s="library://ns.adobe.com/flex/spark"
              xmlns:mx="library://ns.adobe.com/flex/mx">
         <fx:Metadata>
              [HostComponent("CustomComponent")]
         </fx:Metadata>
         <s:Panel>
              <s:TextArea/>
         </s:Panel>
    </s:Skin>

  • Error #1009 while loading swf "Cannot access a property or method of a null object reference."

    Hello
    I'm trying to load a swf called "polaroids.swf" into my main swf called "09replacesSWF.swf". I keep getting the error when I test the movie. I'm completely lost and have been at this for hours. If I just test polaroids.fla the movie works fine but if I try to load it into 09replacesSWF.swf, I get the error. I need some help PLEASE!!!!!
    I tried to debug the movie and flash says......."Cannot display source code at this location".
    ....... TypeError: Error #1009: Cannot access a property or method of a null object reference.
        at Polaroids$iinit()
    Here is my AS code
    package {
        import flash.display.*;
        import flash.filters.*;
        import flash.utils.*;
        import flash.net.*;
        import flash.events.*;
        import flash.filters.DropShadowFilter;
        import caurina.transitions.*;
        public class Polaroids extends MovieClip {
            //Variables
            public var stageContainer:MovieClip;
            private var _scaleTempo:Number;
            private var _thumbStr:Number;
            private var _stageHeight:Number;
            private var _stageWidth:Number;
            private var _count:Number;
            private var _initBGHeight:Number;
            private var _initBGWidth:Number;
            //Arrays
            private var _backgroundImageArr:Array;
            private var _imageURLArr:Array;
            private var _imageCaptionArr:Array;
            private var _imagesArr:Array;
            //Bitmaps
            private var _image:Bitmap;
            private var _backgroundImage:Bitmap;
            private var _bitmap:BitmapData;
            private var _backgroundBitmap:BitmapData;
            //XML
            private var _xmlLoader:URLLoader;
            private var _imageXML:XML;
            //Holders
            private var _imageContainer:ImageContainer;
            private var _backgroundImageHolder:MovieClip;
            //Image States
            private var _activeImage = null;
            private var _previousActiveImage = null;
            //Loaders
            private var backgroundImageLoader:Loader;
            public function Polaroids() {
                //sets up initial variable values
                _count = 0;
                _backgroundImageArr=new Array;
                _imageURLArr=new Array;
                _imageCaptionArr=new Array;
                _imagesArr=new Array;
                _scaleTempo=9;
                _thumbStr = .3;
                backgroundImageLoader = new Loader();
                _stageHeight=stage.stageHeight;
                _stageWidth=stage.stageWidth;
                _backgroundImageHolder = new MovieClip();
                stageContainer = new MovieClip();
                addChild(stageContainer);
                init();
            //Add Stage Listener
            private function addedToStage(e:Event):void {
                stage.addEventListener(Event.RESIZE, onResize);
            Initialise
            private function init():void {
                //Setup stage
                stage.align     = StageAlign.TOP_LEFT;
                stage.scaleMode = StageScaleMode.NO_SCALE;
                //Load XML
                var _xmlLoader:URLLoader=new URLLoader;
                _xmlLoader.load(new URLRequest("photos.xml"));
                _xmlLoader.addEventListener(Event.COMPLETE,processXML);
                this.addEventListener(Event.ADDED_TO_STAGE, addedToStage);
            Process XML
            private function processXML(e:Event):void {
                _imageXML=new XML(e.target.data);
                _backgroundImageArr[0] = _imageXML.@backgroundImage;
                for (var i:int=0; i < _imageXML.*.length(); i++) {
                    _imageURLArr[i]=_imageXML.image[i].@url;
                    _imageCaptionArr[i]=_imageXML.image[i].@caption;
                loadImages();
                loadBackgroundImage();
            Load Background Image
            private function loadBackgroundImage():void {
                backgroundImageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,addBack ground);
                backgroundImageLoader.load(new URLRequest(_backgroundImageArr[0]));
            Add background image to stage
            private function addBackground(e:Event):void {
                _backgroundImage=Bitmap(e.target.content);
                _backgroundBitmap=_image.bitmapData;
                _backgroundImage.smoothing = true;
                _backgroundImageHolder.addChild(_backgroundImage);
                _initBGHeight = backgroundImageLoader.contentLoaderInfo.height;
                _initBGWidth = backgroundImageLoader.contentLoaderInfo.width;
                if ((_initBGWidth/_initBGHeight) > (stage.stageWidth/stage.stageHeight)) {
                    _backgroundImageHolder.height = stage.stageHeight;
                    _backgroundImageHolder.width =  _backgroundImageHolder.height * _initBGWidth / _initBGHeight;
                } else {
                    _backgroundImageHolder.width = stage.stageWidth;
                    _backgroundImageHolder.height= _backgroundImageHolder.width * _initBGHeight / _initBGWidth;
            Load Images
            private function loadImages():void {
                for (var i:int=0; i < _imageURLArr.length; i++) {
                    var imageLoader:Loader=new Loader;
                    imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,addImage);
                    imageLoader.load(new URLRequest(_imageURLArr[i]));
            Add images to MovieClip on Stage
            private function addImage(e:Event):void {
                _image=Bitmap(e.target.content);
                _bitmap=_image.bitmapData;
                _image.smoothing = true;
                _imageContainer = new ImageContainer();
                _imageContainer.falseBtn.buttonMode = true;
                _imageContainer.falseBtn.doubleClickEnabled = true;
                _imageContainer.imageHolder.addChild(_image);//Add Bitmap to a MoviClip _imageContainer
                _image.x = _imageContainer.width/2 - (_image.width/2 + 15);
                _image.y = _imageContainer.height/2 - (_image.height/2 + 80) ;
                _imageContainer.imageCaption.text = _imageCaptionArr[_count];
                _imageContainer.scaleX = _thumbStr;
                _imageContainer.scaleY = _thumbStr;
                _imageContainer.rotation = 30 - 60 * Math.random();
                if (Math.round(Math.random() * 1) == 1) {
                    _imageContainer.y=stage.stageHeight * Math.random() + _imageContainer.height * 2;
                    if (Math.round(Math.random() * 1) == 1) {
                        _imageContainer.x=stage.stageWidth + _imageContainer.width * 2;
                    } else {
                        _imageContainer.x=- _imageContainer.width * 2;
                } else {
                    _imageContainer.x=stage.stageWidth * Math.random() + _imageContainer.width * 2;
                    if (Math.round(Math.random() * 1) == 1) {
                        _imageContainer.y=stage.stageHeight + _imageContainer.height * 2;
                    } else {
                        _imageContainer.y=- _imageContainer.height * 2;
                //Setup Attributes
                _imageContainer.newX = Math.round((_imageContainer.width/2) + (stage.stageWidth-_imageContainer.width)*Math.random());
                _imageContainer.newY = Math.round((_imageContainer.height/2) + (stage.stageHeight-_imageContainer.height)*Math.random());
                _imageContainer.oldRotation = _imageContainer.rotation;
                _imageContainer.oldX = _imageContainer.newX;
                _imageContainer.oldY = _imageContainer.newY;
                _imageContainer.startX = _imageContainer.x;
                _imageContainer.startY = _imageContainer.y;
                _imageContainer.oldHeight = _imageContainer.scaleY;
                _imageContainer.oldWidth = _imageContainer.scaleX;
                _imageContainer.id = _count;
                _imageContainer.addEventListener(Event.ENTER_FRAME, animateImage);
                _imageContainer.addEventListener(MouseEvent.MOUSE_DOWN,dragImage);
                _imageContainer.addEventListener(MouseEvent.MOUSE_UP,dropImage);
                _imageContainer.addEventListener(MouseEvent.MOUSE_OUT, dropImage);
                _imageContainer.falseBtn.addEventListener(MouseEvent.DOUBLE_CLICK, setup_activeImage);
                _imagesArr.push(_imageContainer);//Add image reference to an Array
                _imageContainer.filters = [new DropShadowFilter(0,0,0,.9,8,8,1,1,false,false)];
                //Button Listeners
                _imageContainer.nextBtn.visible = false;
                _imageContainer.previousBtn.visible = false;
                _imageContainer.nextBtn.buttonMode = true;
                _imageContainer.previousBtn.buttonMode = true;
                _imageContainer.nextBtn.addEventListener(MouseEvent.MOUSE_DOWN, nextImage);
                _imageContainer.previousBtn.addEventListener(MouseEvent.MOUSE_DOWN, previousImage);
                //Add Container to Stage
                addChild(_imageContainer);
                stageContainer.addChild(_imageContainer);
                _count++;
            Animate Images onto Stage
            private function animateImage(e:Event):void {
                e.target.y += (e.target.newY - e.target.y) / _scaleTempo;
                e.target.x += (e.target.newX - e.target.x) / _scaleTempo;
                if (Math.round(e.target.y) == e.target.newY) {
                    e.target.removeEventListener(Event.ENTER_FRAME, animateImage);
            Drag & Drop Images
            private function dragImage(e:MouseEvent) {
                if (e.currentTarget != _activeImage) {
                    e.currentTarget.startDrag();
                    if (_activeImage == null) {
                        stageContainer.setChildIndex(DisplayObject(e.currentTarget), stageContainer.numChildren-1);
                    } else {
                        stageContainer.setChildIndex(DisplayObject(e.currentTarget), stageContainer.numChildren-2);
            private function dropImage(e:MouseEvent) {
                if (e.currentTarget != _activeImage) {
                    e.currentTarget.stopDrag();
                    e.currentTarget.oldX = e.currentTarget.x;
                    e.currentTarget.oldY = e.currentTarget.y;
            onResize Handler
            private function onResize(e:Event):void {
                for (var i:int = 0; i<_imagesArr.length; i++) {
                    if (_imagesArr[i] != _activeImage) {
                        _imagesArr[i].x = Math.round(stage.stageWidth * (_imagesArr[i].x/_stageWidth));
                        _imagesArr[i].y = Math.round(stage.stageHeight * (_imagesArr[i].y/_stageHeight));
                    } else {
                        _activeImage.x = stage.stageWidth/2;
                        _activeImage.y = stage.stageHeight/2;
                    _imagesArr[i].oldX = Math.round(stage.stageWidth * (_imagesArr[i].oldX/_stageWidth));
                    _imagesArr[i].oldY = Math.round(stage.stageHeight * (_imagesArr[i].oldY/_stageHeight));
                    _imagesArr[i].newX = Math.round(stage.stageWidth * (_imagesArr[i].newX/_stageWidth));
                    _imagesArr[i].newY = Math.round(stage.stageHeight * (_imagesArr[i].newY/_stageHeight));
                    _imagesArr[i].startX = Math.round(stage.stageWidth * (_imagesArr[i].startX/_stageWidth));
                    _imagesArr[i].startY = Math.round(stage.stageHeight * (_imagesArr[i].startY/_stageHeight));
                //Background Resizer
                if ((_initBGWidth/_initBGHeight) > (stage.stageWidth/stage.stageHeight)) {
                    _backgroundImageHolder.height = stage.stageHeight;
                    _backgroundImageHolder.width =  _backgroundImageHolder.height * _initBGWidth / _initBGHeight;
                } else {
                    _backgroundImageHolder.width = stage.stageWidth;
                    _backgroundImageHolder.height= _backgroundImageHolder.width * _initBGHeight / _initBGWidth;
                _stageWidth = stage.stageWidth;
                _stageHeight = stage.stageHeight;
            Handle Selected Image
            private function zoomImage():void {
                stageContainer.setChildIndex(_activeImage, stageContainer.numChildren-1);
                Tweener.addTween(_activeImage,{scaleX: 1, scaleY: 1, rotation: 0, x: _stageWidth/2 , y: _stageHeight/2, time: 1});
                _activeImage.nextBtn.visible = true;
                _activeImage.previousBtn.visible = true;
            private function returnImage():void {
                stageContainer.setChildIndex(_previousActiveImage, stageContainer.numChildren-2);
                Tweener.addTween(_previousActiveImage,{scaleX: .3, scaleY: .3, rotation: _previousActiveImage.oldRotation, x: _previousActiveImage.oldX , y: _previousActiveImage.oldY, time: 1});
                _previousActiveImage.nextBtn.visible = false;
                _previousActiveImage.previousBtn.visible = false;
            private function setup_activeImage(e:Event):void {
                if ((_activeImage == null) && (_previousActiveImage == null)) {
                    _activeImage = e.currentTarget.parent;
                    zoomImage();
                } else if (e.currentTarget.parent != _activeImage) {
                    _previousActiveImage = _activeImage;
                    _activeImage = e.currentTarget.parent;
                    zoomImage();
                    returnImage();
                } else {
                    Tweener.addTween(_activeImage,{scaleX: .3, scaleY: .3, rotation: _activeImage.oldRotation, x: _activeImage.oldX , y: _activeImage.oldY, time: 1});
                    _activeImage.nextBtn.visible = false;
                    _activeImage.previousBtn.visible = false;
                    _activeImage = null;
                    _previousActiveImage = null;
            Button Handlers
            private function nextImage(e:MouseEvent):void {
                var imageID = int(e.currentTarget.parent.id);
                if (imageID < _imagesArr.length - 1) {
                    _previousActiveImage = e.currentTarget.parent;
                    _activeImage = _imagesArr[imageID+1];
                    zoomImage();
                    returnImage();
                } else {
                    _previousActiveImage = e.currentTarget.parent;
                    _activeImage = _imagesArr[0];
                    zoomImage();
                    returnImage();
            private function previousImage(e:MouseEvent):void {
                var imageID = int(e.currentTarget.parent.id);
                if (imageID != 0) {
                    _previousActiveImage = e.currentTarget.parent;
                    _activeImage = _imagesArr[imageID-1];
                    zoomImage();
                    returnImage();
                } else {
                    _previousActiveImage = e.currentTarget.parent;
                    _activeImage = _imagesArr[_imagesArr.length-1];
                    zoomImage();
                    returnImage();
    }

    Raymond,
    The error is at line 55....when I debug
    TypeError: Error #1009: Cannot access a property or method of a null object reference.
        at Polaroids$iinit()[/Volumes/Herman's Passport/Music Rocka/RockaGallery/Polaroids.as:55]
    So i'm looking in the code.....

  • Strange memory behaviour using the System.Collections.Hashtable in object reference

    Dear all,
    Recently I came across a strange memory behaviour when comparing the system.collections.hashtable versus de scripting.dictionary object and thought to analyse it a bit in depth. First I thought I incorrectly destroyed references to the class and
    child classes but even when properly destroying them (and even implemented a "SafeObject" with deallocate method) I kept seeing strange memory behaviour.
    Hope this will help others when facing strange memory usage BUT I dont have a solution to the problem (yet) suggestions are welcome.
    Setting:
    I have a parent class that stores data in child classes through the use of a dictionary object. I want to store many differenct items in memory and fetching or alteging them must be as efficient as possible using the dictionary ability of retrieving key
    / value pairs. When the child class (which I store in the dictionary as value) contains another dictionary object memory handeling is as expected where all used memory is release upon the objects leaving scope (or destroyed via code). When I use a system.collection.hashtable
    no memory is released at all though apears to have some internal flag that marks it as useable for another system.collection.hashtable object.
    I created a small test snippet of code to test this behaviour with (running excel from the Office Plus 2010 version) The snippet contains a module to instantiate the parent class and child classes that will contain the data. One sub will test the Hash functionality
    and the other sub will test the dictionary functionality.
    Module1
    Option Explicit
    Sub testHash()
    Dim Parent As parent_class
    Dim d_Count As Double
    'Instantiate parent class
    Set Parent = New parent_class
    'Create a child using the hash collection object
    Parent.AddChildHash "TEST_hash"
    Dim d_CycleCount As Double
    d_CycleCount = 50000
    'Add dummy data records to the child container with x amount of data For d_Count = 0 To d_CycleCount
    Parent.ChildContainer("TEST_hash").InsertDataToHash CStr(d_Count), "dummy data"
    Next
    'Killing the parent when it goes out of scope should kill the childs. (Try it out and watch for the termination debug messages)
    'According to documentation and debug messages not really required!
    Set Parent.ChildContainer("TEST_hash") = Nothing
    'According to documentation not really as we are leaving scope but just to be consistent.. kill the parent!
    Set Parent = Nothing
    End Sub
    Sub testDict()
    Dim Parent As parent_class
    Dim d_Count As Double
    'Instantiate parent class
    Set Parent = New parent_class
    'Create a child using the dictionary object
    Parent.AddChildDict "TEST_dict"
    Dim d_CycleCount As Double
    d_CycleCount = 50000
    'Blow up the memory with x amount of records
    Dim s_SheetCycleCount As String
    s_SheetCycleCount = ThisWorkbook.Worksheets("ButtonSheet").Range("K2").Value
    If IsNumeric(s_SheetCycleCount) Then d_CycleCount = CDbl(s_SheetCycleCount)
    'Add dummy data records to the child container
    For d_Count = 0 To d_CycleCount
    Parent.ChildContainer("TEST_dict").InsertDataToDict CStr(d_Count), "dummy data"
    Next
    'Killing the parent when it goes out of scope should kill the childs. (Try it out and watch for the termination debug messages)
    'According to documentation and debug messages not really required!
    Set Parent.ChildContainer("TEST_dict") = Nothing
    'According to documentation not really as we are leaving scope but just to be consistent.. kill the parent!
    Set Parent = Nothing
    End Sub
    parent_class:
    Option Explicit
    Public ChildContainer As Object
    Private Counter As Double
    Private Sub Class_Initialize()
    Debug.Print "Parent initialized"
    Set ChildContainer = CreateObject("Scripting.dictionary")
    End Sub
    Public Sub AddChildHash(ByRef ChildKey As String)
    If Not ChildContainer.Exists(ChildKey) Then
    Dim TmpChild As child_class_hashtable
    Set TmpChild = New child_class_hashtable
    ChildContainer.Add ChildKey, TmpChild
    Counter = Counter + 1
    Set TmpChild = Nothing
    End If
    End Sub
    Public Sub AddChildDict(ByRef ChildKey As String)
    If Not ChildContainer.Exists(ChildKey) Then
    Dim TmpChild As child_class_dict
    Set TmpChild = New child_class_dict
    ChildContainer.Add ChildKey, TmpChild
    Counter = Counter + 1
    Set TmpChild = Nothing
    End If
    End Sub
    Private Sub Class_Terminate()
    Debug.Print "Parent being killed, first kill all childs (if there are any left!) - muahaha"
    Set ChildContainer = Nothing
    Debug.Print "Parent killed"
    End Sub
    child_class_dict
    Option Explicit
    Public MemmoryLeakObject As Object
    Private Sub Class_Initialize()
    Debug.Print "Child using Scripting.Dictionary initialized"
    Set MemmoryLeakObject = CreateObject("Scripting.Dictionary")
    End Sub
    Public Sub InsertDataToDict(ByRef KeyValue As String, ByRef DataValue As String)
    If Not MemmoryLeakObject.Exists(KeyValue) Then MemmoryLeakObject.Add KeyValue, DataValue
    End Sub
    Private Sub Class_Terminate()
    Debug.Print "Child using Scripting.Dictionary terminated"
    Set MemmoryLeakObject = Nothing
    End Sub
    child_class_hash:
    Option Explicit
    Public MemmoryLeakObject As Object
    Private Sub Class_Initialize()
    Debug.Print "Child using System.Collections.Hashtable initialized"
    Set MemmoryLeakObject = CreateObject("System.Collections.Hashtable")
    End Sub
    Public Sub InsertDataToHash(ByRef KeyValue As String, ByRef DataValue As String)
    If Not MemmoryLeakObject.ContainsKey(KeyValue) Then MemmoryLeakObject.Add KeyValue, DataValue
    End Sub
    Private Sub Class_Terminate()
    Debug.Print "Child using System.Collections.Hashtable terminated"
    Set MemmoryLeakObject = Nothing
    End Sub
    Statistics:
    TEST: (Chronologically ordered)
    1.1 Excel starting memory: 25.324 kb approximately
    Max memory usage after hash (500.000 records) 84.352 kb approximately
    Memory released: 0 %
    1.2 max memory usages after 2nd consequtive hash usage 81.616 kb approximately
    "observation:
    - memory is released then reused
    - less max memory consumed"
    1.3 max memory usages after 3rd consequtive hash usage 80.000 kb approximately
    "observation:
    - memory is released then reused
    - less max memory consumed"
    1.4 Running the dictionary procedure after any of the hash runs will start from the already allocated memory
    In this case from 80000 kb to 147000 kb
    Close excel, free up memory and restart excel
    2.1 Excel starting memory: 25.324 kb approximately
    Max memory usage after dict (500.000 records) 90.000 kb approximately
    Memory released: 91,9%
    2.2 Excel starting memory 2nd consequtive dict run: 27.552 kb approximately
    Max memory usage after dict (500.000 records) 90.000 kb approximately
    Memory released: 99,4%
    2.3 Excel starting memory 3rd consequtive dict run: 27.712 kb approximately
    Max memory usage after dict (500.000 records) 90.000 kb approximately
    Memory released:

    Hi Cor,
    Thank you for going through my post and took the time to reply :) Most apreciated. The issue I am facing is that the memory is not reallocated when using mixed object types and is not behaving the same. I not understand that .net versus the older methods
    use memory allocation differently and perhaps using the .net dictionary object (in stead of the scripting.dictionary) may lead to similar behaviour. {Curious to find that out -> put to the to do list of interesting thingies to explore}
    I agree that allocated memory is not a bad thing as the blocks are already assigned to the program and therefore should be reallocated with more performance. However the dictionary object versus hashtable perform almost identical (and sometimes even favor
    the dictionary object)
    The hashtable is clearly the winner when dealing with small sets of data.
    The issue arises when I am using the hash table in conjunction with another type, for example a dictionary, I see that the dictionary object's memory is stacked on top of the claimed memory space of the hashtable. It appears that .net memory allocation and
    reuse is for .net references only. :) (Or so it seems)
    In another example I got with the similar setup, I see that the total used memory is never released or reclaimed and leakage of around 20% allocated memory remains to eventually crash the system with the out of memory message. (This is when another class
    calls the parent class that instantiates the child class but thats not the point of the question at hand)
    This leakage drove me to investigate and create the example of this post in the first place. For the solution with the class -> parent class -> child class memory leak I switched all to dictionaries and no leakage occurs anymore but nevertheless thought
    it may be good to share / ask if anyone else knows more :D (Never to old to learn something new)

  • Accessing variables in a parent class?

    Hello everyone,
    I'm rather new to java, and I've been looking at the documentation a bit but am still trying to figure out just what I am looking for. I've posted an example of such before where I have two seperate files, the parent class file and the child class file. What I want to do is somehow return the instance of parent that child was created with from the below code.
    public class parent {
         protected int var;
         public static void main(String[] args) {          
              child chld = new child();
    }Is it possible to get the same instance of parent that created the child? If so, can it be used to access or modify the variables held by parent? Or is it only possible to do this by creating methods to set or get the value of the variable?
    Can someone point me to the proper term as well, so as I might check the manual as well?

    Another thing I just noticed; your question does not seem to match your post's subject title. Taking that into context, it is possible to read your post very differently. Do you mean that you want to reference parent from inside of its own method, not necessarily after it has returned?
    You can access an object's variables and its methods from within a method it owns. To clarify what I mean...
    public class Something
        int someData = 0;
        public void someAction()
            // Something has a variable "someData" which can be accessed directly from inside of Something's own method someAction()
            someData = 5;
            System.out.println(someData);
    }If you mean you want a reference to the object itself from within one of its methods, Google for the "this" keyword.
    None of these have anything to do with the child object though, so I'm still a bit stumped as to what exactly you mean. Perhaps a combination of all answers received so far?
    Again, you probably need to further clarify exactly what you're looking for.

  • Need to be enlightened on Parent, Child object assignments

    Hi!
    I am too boggled with parent class, child class objects assignments. For example say I have something like this:
    class parent{
       int a;
        void doStuff(){...}
    class child extends parent{
    int b;  
    void doOtherStuff(){...}
    }Ok. Now. if have have something like this:
    parent p;
    child c;Then which one of the below is legal and why and why not?
    1.) c = p;
    2.) p = c;
    I think p = c is legal. If so, can I do p.a =12; p.b=15;
    Why and why not?
    Please be my lifesaver.
    Thank You for reading!

    parent p;
    child c;
    If these are defined as global variables then both p and c will be null, meaning they refer nothing. Since a child inherits properties of the parent you can hold a child object using a parent reference
    so this is legal
    p = c;
    (Note: you need to understand the concept of a reference and object well. Here p and c are both references not objects).
    When you hold a child object using a parent's reference only parent's properties are visible. If you want to see the child's properties then you need to cast that reference to a child reference. So you can't say p.b=12.
    Hope you got what you want

Maybe you are looking for

  • ITunes won't detect firmware 4.3.3 for iPhone 3GS

    I've read about the problem where it doesn't download it and you have to turn off the firewall etc.  However my problem is that it just won't detect it at all.  I check for updates and it says that my iphone is update to date which is running on a 4.

  • How to store multiple format text file in a oracle table

    Hi, I want to store a file which has multiple format for field separation so is it possible in Oracle data integrator if yes then how ..... Waiting for reply regards palash

  • "Notes" making duplicates in my gmail account

         This is my first Macbook or Mac Computer I've ever owned, and thought it was awesome that my notes synced with my gmail account. Except now, after upgrading to Mountain Lion there is always a folder in my trash labeled recovered items or somethi

  • When I press a letter on the keyboard it does multiple letters when I only press it once

    This has only just happened and it is not always the same letter. The letter on the keyboard changes from time to time. Sometimes the keyboard is unresponsive like when I want to add numbers. I will press "s" and 5  or 6 "s" will appear on the screen

  • Install MAC BOOK Pro from scratch

    Hi all, I have Yosemite running on my MAC Pro. In parallel I am trying to get Yosemite running on my MAC Book Pro that was used by my son before. Unfortunately the Installation stucks at the end telling me " only one second to go" but nothing happens