"upload" is not a function - actionscript-3

I have an annoying problem. I've googled a bit and can't really find any good answers, so I'm hoping to find some help here.
I'm getting this error, which seems to be fairly common:
TypeError: Error #1006: update är inte en funktion. // = update is not a function (english)
at se.qmd.spaceInvaders::ShipHandler/onEnterFrame()
Update definently is a function, so I really can't understand what the problem is.
My setup. I'm using Flashdevelop. I have a Main class, which is set as the document class in my fla file.
I have a package structure with my Main class in the src folder, and my subclasses in se.qmd.spaceInvaders and se.qmd.starLight. I also use TweenMax and keep it in the "normal" package structure from the src folder.
In the Main class I add to the stage an instance of the class LeGun - which is also an "exported" movieclip in the fla file, an instance of the class StarHandler and an instance of the class ShipHandler. I also have a keyboard listener which with the help of an enterframe function moves my instance of the LeGun class.
Fine, no problems. The StarHandler works like it should, and the ShipHandler works as it should up until i call 1 or 2 methods in the Ship class - which is also an "exported" movieclip in the fla file. The Ship class is of course the class that contains the Ship that is handled by the ShipHandler.
I'm including my ShipHandler and Ship classes below, and hope it doesn't make the post excede some length.
ShipHandler.as :
package se.qmd.spaceInvaders {
import flash.display.MovieClip;
import se.qmd.spaceInvaders.Ship;
import flash.display.Stage;
import flash.events.Event;
public class ShipHandler extends MovieClip {
private var _shipArray:Array = [];
private const NUM_START_SHIPS:int = 25;
private var s:Stage = null;
private var _directionX:Number = 1;
private var _directionY:Number = 1;
private var _velocityX:Number;
private var _velocityY:Number;
private const YBORDER_TOP:int = 50;
private const YBORDER_BOTTOM:int = 525;
public function ShipHandler(o:Stage) {
s = o; // tar emot stage från main
createObjects();
this.addEventListener(Event.ENTER_FRAME, onEnterFrame);
}
private function createObjects():void {
for (var i:int = 0; i < NUM_START_SHIPS; i++) {
var aShip:Ship = new Ship();
aShip.x = Math.random() * (s.stageWidth - aShip.width) + aShip.width / 2;
aShip.y = Math.random() * (s.stageHeight - aShip.height -135) + aShip.height / 2 + 55;
this.addChild(aShip);
_shipArray.push(aShip);
aShip.startMove(Math.random(), Math.random());
}
}
private function onEnterFrame(e:Event):void {
for (var i:int = 0; i < _shipArray.length; i++) {
var aShip:Ship = _shipArray[i] as Ship;
aShip.update();
}
}
}
}
Ship.as :
package se.qmd.spaceInvaders {
import flash.display.MovieClip;
import flash.events.Event;
public class Ship extends MovieClip {
private var _directionX:Number = 1;
private var _directionY:Number = 1;
private var _velocityX:Number;
private var _velocityY:Number;
private const YBORDER_TOP:int = 50;
private const YBORDER_BOTTOM:int = 525;
public function Ship() {
//s = o; // tar emot stage
this.addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
}
private function onAddedToStage(e:Event):void {
removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
this.width = 50;
this.height = 18;
}
public function update():void {
// x led vänster kant
if(this.x <= this.width / 2) {
this.x = this.width / 2;
_directionX *= -1;
}
// x led höger kant
if(this.x >= 800 - this.width / 2) {
this.x = 800 - this.width/2;
_directionX *= -1;
}
// y led top kant
if(this.y <= YBORDER_TOP + this.height/2) {
this.y = YBORDER_TOP + this.height / 2;
_directionY *= -1;
}
// y led botten kant
if(this.y >= YBORDER_BOTTOM - this.height/2) {
this.y = YBORDER_BOTTOM - this.height / 2;
_directionY *= -1;
}
this.x += _velocityX * _directionX;
this.y += _velocityY * _directionY;
}
public function startMove(directionX:Number, directionY:Number):void {
trace(directionX, directionY);
_velocityX = 10;
_velocityY = 10;
if (directionX < 0.5) {
_directionX = -1;
}
if (directionY < 0.5) {
_directionY = -1;
}
}
public function changeDirection():void {
_directionX *= -1;
_directionY *= -1;
}
}
}
As soon as i call either the methods startMove or update from the ShipHandler, i get the error i wrote above.
Would appreciate any help as it seems to me I must be doing something fundamentally wrong...

It sounds to me like Ship is just a MovieClip (which is a dynamic class and hence the compiler is not complaining when you're trying to access a method that does not exist at compile-time.) MovieClips don't have an update() method, so when you try to invoke it, it cannot be found on the Ship instance.
Is the MovieClip in your FLA file really exported as se.qmd.spaceInvaders.Ship (and not just Ship)? If it's just Ship, that would explain why your written class is not assigned as the class of your ship graphics, leaving it to be just a simple MovieClip which would explain this error.

I have tried your original code and it works fine for me. I did not need to change anything.
Are you compiling from the Flash IDE? In that case, try cleaning the cache with Control > Delete ASO files like this:
Try casting the ship instead like this:
private function onEnterFrame(e:Event):void {
for (var i:int = 0; i < _shipArray.length; i++) {
var aShip:Ship = Ship(_shipArray[i]);
if(aShip)
aShip.update();
else
throw Error("ship is null at position " + i)
}
}
Or use Vector instead of Array:
var _shipArray : Vector.<Ship> = new Vector.<Ship>();

Related

Make three MovieClips appear and disappear inside a snowglobe when shaken

I used a creative cow tutorial to create my own snow globe that moves and snow reactivates - it really is a great tutorial.
What I'm trying to do is Change between 3 Movie clips in the ActionScript - But each time I add my movie clip names - Or try and add a simple visibility code I break my snow globe actions.
I have my MovieClip instances named friendsSceneThree, BuddiesSceneTwo and HatsOffSceneOne. I would think they'd be good but somewhere I'm missing something. Right now I can't get the code to even SEE The movieclips I'm getting a simple:
TypeError: Error #1006: value is not a function.at SnowGlobeContainer/update()
Down in the 'if drag' Update is where I'd like to Change from One MClip to the Next.
What Am I Not Seeing?!?! Any help would be greatly appreciated! Thanks
Here is the ActionScript:
package {
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.geom.Rectangle;
import flash.geom.Point;
public class SnowGlobeContainer extends Sprite {
public var snowForeground:SnowGeneratorCircle;
public var snowBackground:SnowGeneratorCircle;
public var friendsSceneThree:MovieClip;
public var buddiesSceneTwo:MovieClip;
public var hatsOffSceneOne:MovieClip;
public var drag:Boolean = false;
public var over:Boolean = false;
public var startPos:Point = new Point;
public var mouseDownOffset:Point = new Point;
public var bounds:Rectangle = new Rectangle;
public var vel:Point = new Point(0,0);
public var pos:Point = new Point(x,y);
public var old:Point = new Point(x,y);
public var gravity:Number = 5+(Math.random()*1);
public var restitution:Number = 0.5;
public var friction:Number = 0.9;
public function SnowGlobeContainer() {
// save some initial persistant properties
startPos.x = this.x;
startPos.y = this.y;
old.x = this.x;
old.y = this.y;
bounds.x = 0;
bounds.y = 0;
bounds.width = 600;
bounds.height = startPos.y;
// add mouse interaction listeners and show the cursor on rollover
this.mouseChildren = false;
this.useHandCursor = true;
this.buttonMode = true;
this.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
this.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
this.addEventListener(Event.ENTER_FRAME, update);
}
protected function onMouseOver(e:MouseEvent=null):void { over = true; }
protected function onMouseOut(e:MouseEvent=null):void { over = false; }
protected function onMouseDown(e:MouseEvent=null):void {
// Save the offset of your mouse when you first start dragging. Same functionality as startDrag(false)
mouseDownOffset.x = mouseX;
mouseDownOffset.y = mouseY;
drag = true;
}
protected function onMouseUp(e:MouseEvent=null):void {
vel.x = vel.y = 0;
pos.x = x;
pos.y = y;
drag = false;
}
public function update(e:Event):void {
// this if/else statement controls the mouse over and out instead of using event listeners
if(mouseY < -175 || mouseY > 175 || mouseX < -175 || mouseX > 175){
if(over) onMouseOut();
}else{
if(!over) onMouseOver();
}
if(drag){
// drag around..
this.x = parent.mouseX - mouseDownOffset.x;
this.y = parent.mouseY - mouseDownOffset.y;
// keep this thing on the table :)
if(y >= bounds.height) y = bounds.height;
// if you "shake" or move the mouse quickly, we are going to reset the snow particles
var d:Point = new Point(Math.abs(old.x - x), Math.abs(old.y - y));
if(d.x > 50 || d.y > 50 ){
snowForeground.reset();
snowBackground.reset();
friendsSceneThree.visible = false;
}
// update the history position
old.x = x;
old.y = y;
vel.y = (y-old.y)/2;
}else{
// if you drop this object it should have a bit of realistic falling..
vel.y += gravity;
pos.y += vel.y;
// bounce
if(pos.y > bounds.height){
pos.y = bounds.height;
vel.y *= -(Math.random()*restitution);
}
y = pos.y;
}
}
}
}
I appreciate the help -- If you haven't noticed I'm new to all of this scripting. I'm looking in on lynda.com and other forums. the SnowGeneratorCircle.as is:
package {
import flash.display.Sprite;
import flash.events.Event;
public class SnowGeneratorCircle extends Sprite {
var totalFlakes:int = 500;
var flakes:Array = new Array();
public function SnowGeneratorCircle() {
addSnowFlakes();
addEventListener(Event.ENTER_FRAME, update);
}
protected function addSnowFlakes():void{
for(var i:int=0; i<totalFlakes; i++){
var f:SnowFlake = new SnowFlake();
addChild(f);
flakes.push(f);
}
}
public function reset():void{
for(var i:int=0; i<totalFlakes; i++){
var f:SnowFlake = flakes[i];
f.reset();
}
}
public function update(e:Event=null):void {
for(var i:int=0; i<totalFlakes; i++){
var f:SnowFlake = flakes[i];
f.update(0);
}
}
}
}
I debugged - didn't clean up the code, because every time I did - it broke the actions. So I left the code with the double spacing. That's how it went in when I copied and pasted from the tutorial anyway.
Here's the error on line 173 - which is the MovieClip I'd like to have change.
Attempting to launch and connect to Player using URL /Volumes/Lacie Biggest S2S/GRaid/Veronica
/V/Rubio/Work/SUBARU/SnowGlobe Subaru/SnowGlobeAnima/snowGlobeShakev3.swf
[SWF] Volumes:Lacie Biggest S2S:GRaid:Veronica:V:Rubio:Work:SUBARU:SnowGlobe >Subaru:SnowGlobeAnima:snowGlobeShakev3.swf - 468081 bytes after decompression
TypeError: Error #1006: value is not a function.
at SnowGlobeContainer/update()[/Volumes/Lacie Biggest S2S/GRaid/Veronica/V/Rubio/Work/SUBARU
/SnowGlobe Subaru/SnowGlobeAnima/SnowGlobeContainer.as:173]
I just don't know how to get the actionscript to find my MovieClips and then swap them out wt each shake of the globe.

Actionscript 3: Trouble with removing child from parent

I am coding for learning purposes and have encountered an apparently unfixable problem.
I will first introduce you to my code.
This is a function in my Main class
public function confirm_route(evt:MouseEvent):void
{
var route = new Route(this, Airport.return_ROUTE);
Airport.return_ROUTE = new Array();
}
"Airport.return_ROUTE" is simply an array and its origin is not really relevant for the problem. In the Main class I'm also declaring my background var, and putting it as a public static var. Since I need to access this background from two other classes, I don't see another option but to declare it as that, even though I think it is not ideal. I will come back to this later in the explaination.
My Route class is dynamically creating new flights on the screen, hence the name. This is based on the Airport.return_ROUTE array. I need these flights to be added as childs to the background, which was created at Main class as mentioned. This is also why I added "this" as a parameter when calling the route function.
this.myparent = pMyParent;
I use the line above to be able to refer to the main instance. Since the Route instance is no movieclip I guess this is the only way to be able to refer to this.
As earlier mentioned the Route instance dynamically creats new_flights.
new_flight = new Flight(infoarray);
myparent.background_mc.addChild(new_flight);
This obviously is purposed to add the new_flight to the background movieclip.
Let us then look at the Flight class, since this is where the problem occurs.
Due to my game concept I need the new_flight to be removed once it reaches a certain point on the background movieclip.
This function is intended to do that job:
private function deleteThis():void
{
this.parent.removeChild(this)
}
This returns TypeError: Error #1009: Cannot access a property or method of a null object reference.
I really don't understand how to solve this differently.
EDIT: As requested, I will post my Route class.
package
{
import flash.events.TimerEvent;
import flash.utils.Timer;
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.EventDispatcher;
import Main;
public class Route extends Main
{
public var income:Number;
public var routePoints:Array;
private var routeTimer:Timer;
private var new_flight:Flight;
// ------------
private var myparent:Main;
public function Route(route_array:Array, pMyParent)
{
this.myparent = pMyParent;
this.routePoints = route_array;
routeTimer = new Timer(2000);// 2 second
routeTimer.addEventListener(TimerEvent.TIMER, route_function);
routeTimer.start();
}
private function route_function(event:TimerEvent):void
{
for (var counter:uint = 0; counter < routePoints.length - 1; counter ++)
{
trace("Coords: ", routePoints[counter][0],routePoints[counter][1],routePoints[counter + 1][0],routePoints[counter + 1][1]);
new_flight = new Flight(myparent, routePoints[counter][0],routePoints[counter][1],routePoints[counter + 1][0],routePoints[counter + 1][1]);
myparent.bg_image.addChild(new_flight);
var checkTimer:Timer = new Timer(15);// 1 second
checkTimer.addEventListener(TimerEvent.TIMER, check_function);
checkTimer.start();
function check_function(event:TimerEvent):void
{
if (new_flight.finished = true)
{
checkTimer.stop();
}
}
}
}
}
}
EDIT 2: Posting Flight class aswell
package
{
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.events.Event;
import flash.display.SimpleButton;
import flash.display.Stage;
import flash.events.TimerEvent;
import flash.utils.Timer;
import fl.controls.Button;
import flash.display.DisplayObject;
public class Flight extends MovieClip
{
public static var speed:uint = 1
public var finished:Boolean = false;
protected var absvector:Number;
protected var vector:Array;
protected var myTimer:Timer;
//protected var parentContainer:MovieClip;
protected var utgangspunkt_x;
protected var utgangspunkt_y;
protected var destinasjon_x;
protected var destinasjon_y;
protected var vector_x;
protected var vector_y;
private var myparent:Main
public function Flight(pMyParent, utgangspunkt_x, utgangspunkt_y, destinasjon_x, destinasjon_y):void
{
addEventListener(Event.ADDED_TO_STAGE, init);
this.myparent = pMyParent;
this.utgangspunkt_x = utgangspunkt_x;
this.utgangspunkt_y = utgangspunkt_y;
this.x = utgangspunkt_x;
this.y = utgangspunkt_y;
this.destinasjon_x = destinasjon_x + 10;
this.destinasjon_y = destinasjon_y + 10;
this.vector_x = Math.abs(this.destinasjon_x-this.utgangspunkt_x);
this.vector_y = Math.abs(this.destinasjon_y-this.utgangspunkt_y);
this.height = 20;
this.width = 20;
}
public function init(evt:Event):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
trace(this.parent)
trace("---------------------------------------------------")
if (utgangspunkt_x < destinasjon_x)
{
this.rotation = -(Math.atan((utgangspunkt_y-destinasjon_y)/(destinasjon_x-utgangspunkt_x)))/(Math.PI)*180;
}
else
{
this.rotation = 180-(Math.atan((utgangspunkt_y-destinasjon_y)/(destinasjon_x-utgangspunkt_x)))/(Math.PI)*180;
}
absvector = Math.sqrt(Math.pow((destinasjon_x - utgangspunkt_x),2) + Math.pow((utgangspunkt_y - destinasjon_y),2));
vector = [(destinasjon_x - utgangspunkt_x) / absvector,(utgangspunkt_y - destinasjon_y) / absvector];
stage.addEventListener(Event.ENTER_FRAME, movement)
}
private function movement(evt:Event):void
{
if (this.vector_x > this.vector_y)
{
if (destinasjon_x>utgangspunkt_x)
{
if (this.x < destinasjon_x)
{
this.x += speed*vector[0];
this.y -= speed*vector[1];
}
else
{
deleteThis()
}
}
else if (destinasjon_x<utgangspunkt_x)
{
if (this.x > destinasjon_x)
{
this.x += speed*vector[0];
this.y -= speed*vector[1];
}
else
{
deleteThis()
}
}
}
else
{
if (destinasjon_y>utgangspunkt_y)
{
if (this.y < destinasjon_y)
{
this.x += speed*vector[0];
this.y -= speed*vector[1];
}
else
{
deleteThis()
}
}
else if (destinasjon_y<utgangspunkt_y)
{
if (this.y > destinasjon_y)
{
this.x += speed*vector[ 0];
this.y -= speed*vector[1];
}
else
{
deleteThis()
}
}
}
}
private function deleteThis():void
{
finished = true;
this.parent.removeChild(this)
}
}
}
I suspect your deleteThis method is called more than once. That would explain why you have [object Image] and then nothing...
Is this method called by some kind of event? If that is the case, make sure this event is not triggered more than once.

Line 108 1136: Incorrect number of arguments. Expected 1

I cant fix this error and when I do it causes another one. I want to be able to hit key "71" and have a new instance of the movieclip added to the stage. any suggestions? Im a novice so probably alot of mistakes...
package {
import flash.display.MovieClip; //imports needed
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.events.Event;
import flash.text.engine.EastAsianJustifier;
import flash.events.KeyboardEvent;
import flash.display.Stage;
public class myJellyFish extends MovieClip {
private var startScaleX:Number;
private var startScaleY:Number;
//private var cliqued:Number;
private var stayonscreenLeft:Number;
private var stayonscreenRight:Number;
private var stayonscreenTop:Number;
private var stayonscreenBottom:Number;
private var moveDirection:Number;
private var speed:Number;
private var turnspeed:Number;
public function myJellyFish() {
startScaleX = this.scaleX;
startScaleY = this.scaleY;
stayonscreenBottom = 400;
stayonscreenRight = 500;
stayonscreenLeft = 5;
stayonscreenTop = 5;
moveDirection = .5;
speed = Math.random()*10;
turnspeed = 25;
this.addEventListener(MouseEvent.ROLL_OVER, scrolledOver);
this.addEventListener(MouseEvent.ROLL_OUT, scrolledOff);
this.addEventListener(MouseEvent.CLICK, directionChange);
this.addEventListener(Event.ENTER_FRAME, life)
trace("custom class be a working");
// constructor code
}
function myMethod () {
trace("method also be a workin'");
}
private function scrolledOver(Event:MouseEvent):void{
this.alpha = .5;
}
private function scrolledOff(Event:MouseEvent):void{
this.alpha = 1;
}
private function directionChange(e:Event):void{
moveDirection = moveDirection * -1;
}
private function life(e:Event):void{
if (moveDirection > 0){
Hmovement();
}
if (moveDirection < 0){
Vmovement();
}
}
private function Vmovement():void{
this.y += speed;
if(this.y <= stayonscreenBottom){
speed = speed * -1;
this.startScaleY * -1;
}
if(this.y >= stayonscreenTop){
speed = speed * -1;
this.startScaleY * -1;
}
}
private function Hmovement():void{
this.x += speed;
if(this.x >= stayonscreenRight){
speed = speed * -1;
}
if(this.x <= stayonscreenLeft){
speed = speed * -1;
}
}
private function generate(e:KeyboardEvent):void{
var movieClip:myJellyFish = new myJellyFish();
addChild(movieClip);
movieClip.x = (Math.random() * 200) + 20;
movieClip.y = (Math.random()*200) + 20;
movieClip.name = "jellyfish";
}
public function moreClips (event:KeyboardEvent){ //if that key is "F" it will play the tween
trace(event.keyCode);
if (event.keyCode == 71){
generate();
}
}
}//end class
}//end package
First of all, as Rin said, there will be an argument error when calling the generate function.
Secondly, you need to add a KeyboardEvent (ref) listener in order to receive the keyboard events.
The easiest way to listen to keyboard events is to add the listener to the Stage (because the KeyboardEvents will bubble to the Stage no matter where they were triggered.) In order to get a reference to the Stage, you need to wait until your MovieClip has been added to the DisplayList (when your instance of myJellyFish has been added as a child somewhere).
You do this by listening for the Event.ADDED_TO_STAGE event.
// Your constructor
public function myJellyFish() {
// ...
// Add event listener which will trigger when
// the MovieClip has been added to the DisplayList
this.addEventListener(Event.ADDED_TO_STAGE, handleAddedToStage);
}
protected function handleAddedToStage(e:Event):void {
// Remove event listener since it's no longer needed
this.removeEventListener(Event.ADDED_TO_STAGE, handleAddedToStage);
// You now have a reference to the stage, let's add the KeyboardEvent listener
stage.addEventListener(KeyboardEvent.KEY_DOWN, moreClips);
}
Edit: fixed typo in removeEventListener.
Your generate function has 1 argument wich is e:KeyboardEvent, since you have function moreClips which alredy has the KeyboardEvent, you don't need the argument for the generate function.
Basicly what you are doing now is calling the generate() function without the argument. All you should do is remove the argument from the function.
private function generate():void{
var movieClip:myJellyFish = new myJellyFish();
addChild(movieClip);
movieClip.x = (Math.random() * 200) + 20;
movieClip.y = (Math.random()*200) + 20;
movieClip.name = "jellyfish";
}

Bubble pop game Actionscript: defining ToString() method through a reference with a static type class

Hello I have the actionscript code here for a bubble popping game. When the game starts, bubbles fall down from the top of the game to the bottom and score is kept for the most bubbles clicked or popped in 30 seconds.
The size of the bubble is defined by the initialize method in the code, and uses ToString() to calculate the score. ToString gives me a 1061: Call to a possibly undefined method Random through a reference with static type uint. This error which I cannot figure out where it comes from.
If anyone with experience in AS3 could give me some pointers to my faults, I would greatly appreciate it. Thank You.
package {
import flash.display.MovieClip;
import flash.events.Event;
import flash.media.Sound;
public class Ball extends MovieClip{
static public var burstCounter: uint;
private var vx: Number;
private var vy: Number;
private var gravity: Number;
private var stageWidth;
private var stageHeight;
private var bubble:Ball = new Ball();
private var score: uint=0;
public function Ball() {
bubble.addEventListener(Event.ADDED_TO_STAGE, initialize)
bubble.addEventListener(MouseEvent.CLICK, burst)
bubble.addEventListener(Event.ENTER_FRAME, dropping)
}
public function initialize (e:Event):void
{
bubble.x = Math.random() * stageWidth;
bubble.y = 0;
stageWidth = stage.stageWidth;
stageHeight = stage.stageHeight;
bubble.vx = Math.random() * 2 - 1;
bubble.vy = Math.random() * 2 + 1;
gravity = 0.1;
var sizeScale = Math.random() * 1.2 + .6;
bubble.scaleX = bubble.scaleY = sizeScale;
score = (10 / sizeScale);
scoreValue.text = score.ToString();
var colorTran = new ColorTransform();
colorTran.color = Math.random() * 0xFFFFFF;
transform.colorTransform = colorTran;
addChild(bubble);
}
function dropping(e: Event) :void
{
x += vx;
y += vy;
vy += gravity;
if((x<0) || (x>stageWidth) || (y<0) || (y>stageHeight))
{
if(parent != null)
{
parent.removeChild(this);
}
removeEventListener(Event.ENTER_FRAME, dropping)
}
}
function burst (e:Event):void
{
var ballonPopping: Sound = new BalloonPopping();
bubble.removeEventListener(Event.ADDED_TO_STAGE, initialize);
bubble.removeEventListener(Event.ENTER_FRAME, dropping);
removeChild(bubble);
ballonPopping.play();
burstCounter += score;
}
}
}
Try Math.random() instead...
You need to change each occurrence of
Math.Random()
to
Math.random()
note the lowercase r
Or...since it looks like you just edited this question for ToString()
Try
toString()
Notice how similar the errors are. You're tying to call a method that doesn't exist on both of these. Capitalization matters VAR is not the same as var
uint doesn't have a ToString() method either, but it has a toString().
Case is important in method names. :)
Be mindful that casing does matter when naming & calling properties or methods.
ActionScript uses pascalCasing for its members, including static ones. Constants use ALL_CAPS.
I can't think of any class members in ActionScript that use CamelCasing like you've been doing - as far as I'm aware, there aren't any.

A loop in enterframe?

I'm animating a bunch of words in AS3. Because I'm going to be using this on a mobile device, I want to use bitmaps rather than Sprites. So I've created WordObjects, which have a .bitmap property that I can access.
I have the following code, which fires on the click event and loops through an array inside an enterframe event. This is probably a bad idea, but I'm not sure how to do it better. (What is surprising is that it runs just fine in Flashbuilder, but slows to a crawl in Flash CS5.)
Is there some better way to do this? I just want an efficient way to animate the array of bitmaps.
private function clickhandler (e:MouseEvent){
this.addEventListener(Event.ENTER_FRAME, blowemup);
}
private function blowemup(e:Event){
var newPosition:Number;
for(var i:int=0; i<arrWordObjects.length; i++)
{
newPosition = updatePosition(arrWordObjects[i].bitmap);
arrWordObjects[i].bitmap.x += newPosition;
arrWordObjects[i].bitmap.y += getRandomNumber();
}
}
Something that will make a huge difference is using for each(Object in Array) rather than the standard for loop.
private function blowemup(e:Event):void
{
var newPosition:Number;
var i:ArrWordsObjectClass; // <-- don't know what the class for this is, just replace
for each(i in arrWordObjects)
{
newPosition = updatePosition(i.bitmap);
i.bitmap.x += newPosition;
i.bitmap.y += getRandomNumber();
}
}
A for each loop is typed, meaning a lot of time is saved where normally it'd be trying to work out what arrWordObjects[i] is every iteration.
Also, side note: using one ENTER_FRAME driven function and looping through everything in your application that you want to handle each frame is much more efficient than applying hundreds of listeners for objects.
I normally create a handler class that contains the ENTER_FRAME and an array storing my objects, like so:
package
{
import flash.events.Event;
import flash.display.Sprite;
public class Handler extends Sprite
{
// vars
public var elements:Array = [];
/**
* Constructor
*/
public function Handler()
{
addEventListener(Event.ENTER_FRAME, _handle);
}
/**
* Called on each dispatch of Event.ENTER_FRAME
*/
private function _handle(e:Event):void
{
var i:Element;
for each(i in elements)
{
i.step();
}
}
}
}
Then I create a base class for all the objects that I want to handle, containing the step() function called above.
package
{
import flash.display.DisplayObject;
public class Element extends Object
{
// vars
public var skin:DisplayObject;
/**
* Called on each dispatch of Event.ENTER_FRAME at Handler
*/
public function step():void
{
// override me
}
}
}
Now just extend Element with your objects:
package
{
import flash.display.Sprite;
public class MyThing extends Element
{
/**
* Constructor
*/
public function MyThing()
{
skin = new Sprite();
skin.graphics.beginFill(0);
skin.graphics.drawCircle(0,0,40);
skin.graphics.endFill();
}
/**
* Override step
*/
override public function step():void
{
skin.x += 4;
}
}
}
And get it all going!:
var handler:Handler = new Handler();
var m:MyThing;
var i:uint = 0;
for(i; i<10; i++)
{
m = new MyThing();
m.y = Math.random()*stage.stageHeight;
handler.elements.push(m);
addChild(m.skin);
}
How many bitmaps do you plan to have on the stage at a time?
I have had 40 900x16px bitmaps animating on the stage at full speed running on my iphone using air 2.6.
I used a foreach loop in an enterframe event which i added on mouseclick and removed once the animation was finished.
Remember to compile it for the mobile with gpu rendering enabled. (gpu in your app.xml if you are using air 2.6)
This is worth a read too, it explains a lot about performance for mobile devices
http://help.adobe.com/en_US/as3/mobile/WS901d38e593cd1bac-3d719af412b2b394529-8000.html
Here is a basic example of what I had...
package
{
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.geom.Rectangle;
[SWF(frameRate="30", backgroundColor="#FF00FF")]
public class Test extends Sprite
{
private var fields:Vector.<Bitmap> = new Vector.<Bitmap>();
public function Test()
{
this.stage.scaleMode = StageScaleMode.NO_SCALE;
this.stage.align = StageAlign.TOP_LEFT;
for(var i:int = 0; i< 37; i++){
var bd:BitmapData = new BitmapData(960, 16, true, 0x000000);
bd.fillRect(new Rectangle(0, 0, 900, 16), Math.round( Math.random()*0xFFFFFFFF ));
var b:Bitmap = new Bitmap(bd);
b.x = 0;
b.y = i*16;
stage.addChild(b);
fields.push(b);
}
stage.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
}
private var inertia:Boolean = false;
private var yCurrent:Number;
private var ySpeed:Number;
private var startY:Number;
private var cy:Number = 0;
private function onEnterFrame(e:Event):void{
if(!inertia){
ySpeed = (startY - yCurrent) ; // / 16;
startY = yCurrent
} else {
ySpeed *= 0.8;
if(ySpeed < 0.01 && ySpeed > -0.01){
inertia = false;
stage.removeEventListener(Event.ENTER_FRAME, onEnterFrame);
}
}
cy += ySpeed;
if(cy > 640)
cy -= 640;
var ty:Number = cy;
for each(var tf:Bitmap in fields){
tf.y = ty;
ty += 16;
if(ty > 640)
ty -= 640;
}
}
private function onMouseDown(e:MouseEvent):void{
inertia = false;
startY = e.stageY;
yCurrent = e.stageY;
stage.addEventListener(Event.ENTER_FRAME, onEnterFrame);
stage.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
stage.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
}
private function onMouseMove(e:MouseEvent):void{
yCurrent = e.stageY;
}
private function onMouseUp(e:Event):void{
inertia = true;
stage.removeEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
stage.removeEventListener(MouseEvent.MOUSE_UP, onMouseUp);
}
}
}
I would suggest looking at writing a custom effect on Adobe's website over registering for ENTER_FRAME event. What you've put up there means this code will forever run as long as the program is running. If you wanted to stop the effect or run for 10 frames and stop then you'll have to write more code. It gets even more complex if you want to apply this to several instances. You're going to have to resolve problems that custom effects framework solves.
I'd read how to write custom effects here:
http://livedocs.adobe.com/flex/3/html/help.html?content=createeffects_1.html