I am trying to get a hang of OOP in ActionScript 3 but I keep getting errors everywhere. I fix those errors and get other ones this is my Square class:

package com.scoobasteve {
import flash.display.*;
import flash.events.*;
import FluidLayout.*;
import com.greensock.*;

public class Square extends MovieClip {

    var squares:Array;
    var wIncr:Number = 0;
    var hIncr:Number = 0;
    var wIncrA:Number = 0;
    var hIncrA:Number = 0;
    var squareHolder:MovieClip;
    var square:MovieClip; 
    var sWidth:Number = 1000;
    var sHeight:Number = 600;

    public function Square() {
        squares = new Array();
        createSquares();
    }

    public function createSquares():void {
        wIncr = 0;
        hIncr = 0;

        for(var i:Number = 0; i<20; i++) {
            if(i%2==1)
                createSquare(wIncr,hIncr,"000000");
            else
                createSquare(wIncr,hIncr,"ff3300");
            wIncr+=2;
        }
        moveSquares();
    }

    public function createSquare(xPos:Number, yPos:Number, color):void {
        squareHolder = new MovieClip();
        square = new MovieClip(); 

        color = "0x"+color;

        this.addChild(squareHolder);
        squareHolder.addChild(square);
        squareHolder.x = 0;
        squareHolder.y = 0;

        square.graphics.lineStyle(1, color);
        square.graphics.beginFill(color);
        square.graphics.drawRect(0, 0, 50, 50);
        square.graphics.endFill();
        square.x=xPos;
        square.y=yPos;

        squares.push(square);

        squareHolder.addEventListener(MouseEvent.MOUSE_DOWN , onClick);
        squareHolder.addEventListener(MouseEvent.MOUSE_UP , onUnClick);
    }

    public function moveSquares() {
        wIncrA = 0;
        hIncrA = 0;
        for(var s in squares) {
            if (wIncrA>sWidth-100) {
                wIncrA = 0;
                hIncrA+=100;
            }
            TweenLite.to(s, 1, {x:wIncrA, y:hIncrA});
            wIncrA+=100;
        }
    }

    public function onClick(evt:MouseEvent):void {
        var object = evt.target;
        object.startDrag();
    }

    public function onUnClick(evt:MouseEvent):void {
        var object = evt.target;
        object.stopDrag();
    }
}
}

This is my main class:

package {
import flash.display.*;
import flash.events.*;
import FluidLayout.*;
import com.greensock.*;
import com.scoobasteve.*;

public class Test extends MovieClip {

    public function Test() {

        var s = new Square();
        addChild(s);
    }
}
}

The error I am getting is this:

ReferenceError: Error #1069: Property x not found on Number and there is no default value.

at com.greensock::TweenLite/init()
at com.greensock::TweenLite/renderTime()
at com.greensock.core::SimpleTimeline/renderTime()
at com.greensock::TweenLite$/updateAll()

And I have no idea what it means. I tried substituting static numbers for wIncrA and hIncrA but that did not work. Another question I had was what variables do I declare in the beginning of the class (before public function Square()) and do I give them values when I declare them up there?

3 answers

0
points

A reference error means you are trying to access a property on an object or call a function that doesn't exist. At some point something wants to look at property x on a Number object (a Number object isn't going to have an x property). Something is being used incorrectly in your program, so check for typos and mispellings first.

My guess is the line that calls TweenLite has potential for the problem. But I only say that because your code looks fine to me, but I'm not familiar with the framework that uses the TweenLite function so I can't say anything else about it, but I would start looking there.

Answered almost 7 years ago by Matt Milburn
0
points

Thats where I am confused. I am pretty sure the problem is with the line:

TweenLite.to(s, 1, {x:wIncrA, y:hIncrA});

but when I change it to:

TweenLite.to(s, 1, {x:100, y:100});

I still get the same error which I do not understand, and that is the correct way to call the tweenlite function.

Answered almost 7 years ago by Stephen Cronin
0
points

Try specifying the date type of s in the for loop:

for (var s:MovieClip in squares) {
    //etc.
}
Answered almost 7 years ago by Matt Milburn
  • When I do that I get this error: 1067: Implicit coercion of a value of type String to an unrelated type flash.display:MovieClip. Im assuming it means flash thinks s is a String, but I dont get why. I declared squares as an array and filled it with movieclips which are being called as s. Stephen Cronin almost 7 years ago