Skip to main content
Participant
April 7, 2011
Answered

1013: The private attribute may be used only on class property definitions.

  • April 7, 2011
  • 3 replies
  • 4755 views

This error is just making me wanna commit

where have i gone wrong? Help would be awesome

package classes

{

import flash.display.Sprite;

import flash.events.Event;

public class MYball extends Sprite {

// Constants:

// Public Properties:

// Private Properties:

private var _vx,

_vy,

_radius:Number ;

private var yspeed:int = 4;

private var xspeed:int = 4;

// UI Elements:

// Initialization:

public function MYball(x:Number, y:Number,

   vx:Number=4, vy:Number=4){

this.x = x;

this.y = y;

this._vx = vx;

this._vy = vy;

this._radius = this.width / 2;

configUI();

this.addEventListener(Event.ENTER_FRAME, drop);

this.addEventListener(Event.ENTER_FRAME, bounce);

}

// Public Methods:

// Protected Methods:

private function drop (e:Event) {

if (this.y < (stage.stageHeight - (this.width /2))) {

this.y += this.yspeed ;

}

trace (this.y) ;

}

protected function configUI():void { }

}

// Private Methods:

private function bounce (e:Event) {

this.x += this._vx ;

this.y += this._vy ;

// IF BALL HITS LHS OR RHS THEN

if ((this.x + this._radius >= stage.stageWidth) ||

(this.x - this._radius <= 0)) {

// REVERSE ITS X DIRECTION

this._vy*= -1 ;

}

// IF BALL AT TOP OR BOTTOM THEN

if ((this.y + this._radius >= stage.stageHeight) ||

(this.y - this._radius <= 0)) {

// REVERSE ITS DIRECTION

this._vx*= -1;

}

// REVERSE ITS Y DIRECTION

}

public function get radius():Number {

return this._radius ;

}

public function get vx():Number {

return this._vx;

}

public function set vx(i:Number) {

if (i<20) {

this._vx = i ;

} else {

this._vx = 20 ;

}

}

}

}

This topic has been closed for replies.
Correct answer Kenneth Kawamoto

Below should not give you any compiling error - whether this does what you want is another matter though

package classes {
   
    import flash.display.Sprite;
    import flash.events.Event;
   
    public class MYball extends Sprite {
       
        private var _vx:Number, _vy:Number, _radius:Number;
        private var yspeed:int = 4;
        private var xspeed:int = 4;

        public function MYball(x:Number, y:Number, vx:Number=4, vy:Number=4):void {
            // ...
        }
       
        private function drop (e:Event):void {
            // ...   
        }

        protected function configUI():void {
            // ...
        }

        private function bounce (e:Event):void {
            // ...
        }
       
        public function get radius():Number {
            // ...   
        }

        public function get vx():Number {
            // ...   
        }
       
        public function set vx(i:Number):void {
            // ...   
        }
    }   
}

3 replies

February 3, 2013

am having a problem too.. cant seem to figure it out though.. some help pls?

import com.doitflash.consts.Orientation;

import com.doitflash.consts.Easing;

import com.doitflash.events.ScrollEvent;

import com.doitflash.starling.utils.scroller.Scroller;

import starling.events.TouchEvent;

import starling.events.TouchPhase;

import starling.events.Touch;

import starling.extensions.ClippedSprite;

import flash.geom.Point;

var content:ClippedSprite = new ClippedSprite(); // the content you want to scroll

content.clipRect = new Rectangle(0, 0, 500, 500); // set the space that you want your content to be visible at, set its mask actually

content.addEventListener(TouchEvent.TOUCH, onTouch);

this.addChild(content);

var scroll:Scroller = new Scroller();

scroll.boundWidth = 500; // set boundWidth according to the mask width

scroll.boundHeight = 500; // set boundHeight according to the mask height

scroll.content = content; // you MUST set scroller content before doing anything else

scroll.orientation = Orientation.VERTICAL; // accepted values: Orientation.AUTO, Orientation.VERTICAL, Orientation.HORIZONTAL

// you call this function, to start scrolling

private function onTouch(e:TouchEvent):void

{

    var touch:Touch = e.getTouch(stage);

    var pos:Point = touch.getLocation(stage);

   

    if (touch.phase == TouchPhase.BEGAN)

    {

        scroll.startScroll(pos); // on touch begin

    }

    else if (touch.phase == TouchPhase.MOVED)

    {

        scroll.startScroll(pos); // on touch move

        //trace(_scroll.isHoldAreaDone); // to see that we have got out of the hold area or not

    }

    else if (touch.phase == TouchPhase.ENDED)

    {

        scroll.fling(); // on touch ended

    }

}

kglad
Community Expert
Community Expert
February 3, 2013

please don't cross-post.

check your duplicate message.

Participant
January 5, 2012

I am having the same problem any help would be greatly appreciated

package {

          import flash.events.Event;

          import flash.display.*;

          import flash.events.KeyboardEvent;

          import flash.ui.Keyboard;

          import org.papervision3d.materials.WireframeMaterial;

          import org.papervision3d.materials.utils.MaterialsList;

          import org.papervision3d.objects.parsers.DAE;

          import org.papervision3d.view.BasicView;

          import org.papervision3d.objects.DisplayObject3D;

          import org.papervision3d.events.FileLoadEvent;

          import org.papervision3d.cameras.CameraType;

          import org.papervision3d.scenes.Scene3D;

          import org.papervision3d.view.Viewport3D;

          import org.papervision3d.render.BasicRenderEngine;

          import org.papervision3d.cameras.Camera3D;

          import org.papervision3d.objects.primitives.Plane;

          import org.papervision3d.events.InteractiveScene3DEvent;

          import org.papervision3d.materials.BitmapFileMaterial;

          import org.papervision3d.objects.primitives.Cube;

          public class Galaxy extends BasicView {

                    private var solarsystem:DisplayObject3D;

                    private var rotX:Number = 1.0;

                    private var rotY:Number = 1.0;

                    private var rotZ:Number = 1.0;

                    private var camPitch:Number = 90;

                    private var camYaw:Number = 270;

                    private var easeOut:Number = 1.5;

                    private var easeIn:Number = 1.5;

                    private var keyRight:Boolean;

                    private var keyLeft:Boolean;

                    private var keyForward:Boolean;

                    private var keyBackward:Boolean;

                    public function Galaxy() {

 

                              super(stage.stageWidth,stage.stageHeight,true,false,CameraType.FREE);

 

                              stage.frameRate = 40;

                              init();

                              startRendering();

                    }

                    private function init():void {

                              stage.addEventListener(KeyboardEvent.KEY_DOWN,keyDownHandler);

                              stage.addEventListener(KeyboardEvent.KEY_UP,keyUpHandler);

                              solarsystem = new DAE();

                              solarsystem.addEventListener(FileLoadEvent.LOAD_COMPLETE,modelLoaded);

                              DAE(solarsystem).load("Assets/solar.dae");

                              scene.addChild(solarsystem);

                    }

                    private function modelLoaded(e:FileLoadEvent):void {

                              scene.addChild(solarsystem);

                    }

                    private function keyDownHandler(e:KeyboardEvent):void {

                              switch (e.keyCode) {

                                        case "W".charCodeAt() :

                                        case Keyboard.UP :

                                                  keyForward = true;

                                                  break;

                                        case "S".charCodeAt() :

                                        case Keyboard.DOWN :

                                                  keyBackward = true;

                                                  break;

                                        case "A".charCodeAt() :

                                        case Keyboard.LEFT :

                                                  keyLeft = true;

                                                  break;

                                        case "D".charCodeAt() :

                                        case Keyboard.RIGHT :

                                                  keyRight = true;

                                                  break;

                              }

                    }

                    private function keyUpHandler(e:KeyboardEvent):void {

                              switch (e.keyCode) {

                                        case "W".charCodeAt() :

                                        case Keyboard.UP :

                                                  keyForward = false;

                                                  break;

                                        case "S".charCodeAt() :

                                        case Keyboard.DOWN :

                                                  keyBackward = false;

                                                  break;

                                        case "A".charCodeAt() :

                                        case Keyboard.LEFT :

                                                  keyLeft = false;

                                                  break;

                                        case "D".charCodeAt() :

                                        case Keyboard.RIGHT :

                                                  keyRight = false;

                                                  break;

                              }

                    }

 

                    override protected function onRenderTick(e:Event=null):void {

 

private function moveObject():void {

                              if (keyForward) {

                                        camera.moveForward(30);

                              }

                              else if (keyBackward) {

                                        camera.moveBackward(30);

                              }

                              if (keyRight) {

                                        camera.localRotationY -=2;

                              }

                              else if (keyLeft) {

                                        camera.localRotationY +=2;

                              }

                    }

 

                              var xDist:Number = mouseX - stage.stageWidth * 0.5;

                              var yDist:Number = mouseY - stage.stageHeight * 0.5;

                              camPitch += ((yDist * rotX) - camPitch + 90);

                              camYaw += ((xDist * rotY) - camYaw + 270) * easeOut;

                              camera.orbit(camPitch, camYaw);

                              super.onRenderTick();

                    }

          }

}

I am getting the same error message up 1013: The private attribute may be used only on class property definitions. for  private function moveObject():void {

I have put it in Bold. I would really appreciate anyone that can help me with this I have been tyring to sort it for ages and when I think I have got it my cameras dont work.

Thanks

Community Expert
January 5, 2012

isn't your function moveObject placed within another function onRenderTick?

--

Kenneth Kawamoto

http://www.materiaprima.co.uk/

Community Expert
April 7, 2011

Some of your functions towards the end are outside of class definition block.

Participant
April 7, 2011

what should it look like ? if poss

Kenneth KawamotoCommunity ExpertCorrect answer
Community Expert
April 7, 2011

Below should not give you any compiling error - whether this does what you want is another matter though

package classes {
   
    import flash.display.Sprite;
    import flash.events.Event;
   
    public class MYball extends Sprite {
       
        private var _vx:Number, _vy:Number, _radius:Number;
        private var yspeed:int = 4;
        private var xspeed:int = 4;

        public function MYball(x:Number, y:Number, vx:Number=4, vy:Number=4):void {
            // ...
        }
       
        private function drop (e:Event):void {
            // ...   
        }

        protected function configUI():void {
            // ...
        }

        private function bounce (e:Event):void {
            // ...
        }
       
        public function get radius():Number {
            // ...   
        }

        public function get vx():Number {
            // ...   
        }
       
        public function set vx(i:Number):void {
            // ...   
        }
    }   
}