Saturday, May 12, 2012

[Action Script] Accessing variable from another class is changing its value? May,2012

Hi, hoping someone could help me out with this.. I have this variable count in one class to keep track of a movieclip being dragged and dropped on another movieclip. When dragged, the value of the variable becomes 1. When I test this within the class, the value is reflected as 1. But when I access the same variable from another class, the value is reflected as 0. I have on idea why this is happening and am unable to solve it:/

The class where the variable is created:
ActionScript Code: package {    import flash.display.MovieClip;    import flash.events.MouseEvent;    import flash.geom.Point;    //import fl.controls.CheckBox;    //import fl.controls.RadioButton;         public class pine extends MovieClip    {        protected var originalPosition:Point;        public var count:Number=0;                //constructor        public function pine()        {            //this.subClicked2=subClicked2;            originalPosition=new Point(x,y);                    buttonMode=true;            //event listener on mouse click            addEventListener(MouseEvent.MOUSE_DOWN, down);            //counting();                     }                        //handle mouse click event        public /*protected*/ function down(event:MouseEvent):void        {            //allows object to come to front when moved            parent.addChild(this);            startDrag();            //event listener on mouse release            stage.addEventListener(MouseEvent.MOUSE_UP, stageUp);        }                public /*protected*/ function stageUp(event:MouseEvent):void        {            //handle mouse release event            stage.removeEventListener(MouseEvent.MOUSE_UP, stageUp);            stopDrag();            if (dropTarget) {                if (x>275 && x<847 && y>0 && y<543)                {                        //scale up                        scaleX=scaleY=1.5;                        x=530;                        y=220;                        //make transparent                        alpha=0.5;                        count+=1;                        //no more mouseover                        buttonMode=false;                        stage.removeEventListener(MouseEvent.MOUSE_DOWN, down);                        counting();                    }                                     //else if dropped on another object, return to original position                    else {                        returnToOriginalPosition();                    }                }                else  {                    returnToOriginalPosition();                }                        }                //bring object back to its original position        public /*protected*/ function returnToOriginalPosition():void        {            x=originalPosition.x;            y=originalPosition.y;        }                public function counting():void        {            trace("pineapples="+count);        }    }}
This is the class which is accessing the variable count:
ActionScript Code: package {    import flash.display.MovieClip;    import flash.events.Event;    import flash.events.MouseEvent;    public class pizza extends MovieClip    {        public var totalIngs:Number;        var p:pine=new pine();        // var ol:olives=new olives();        //public var countPine:Number;        //public var countOlives:Number;        //public var totalIngs:Number;        public function pizza()        {            this.totalIngs = totalIngs;            this.countPine = countPine;            //this.countOlives = countOlives;            //trace("entered constructor");                   }                public function total():void        {            //trace("entered total function");            countPine=p.count;            trace("total function: pineapples present = "+countPine);            //trace("working?");        }    }}
Please advise on how this can be fixed, thanks!
Accessing variable from another class is changing its value?

Related Post



0 comments: