In my example above, i dont have the code set up in an AS file as your propose. It is explained as being on the main timeline of a Flash Pro file, so no "private" functions. And when set up as a regular function, on the main timeline of the fla as noted, your code outputs this error:
| Scene 1, Layer 'Layer 3', Frame 1, Line 10 | Warning: 1090: Migration issue: The onEnterFrame is not triggered automatically by Flash Player at run time in ActionScript 3.0. You must first register this handler for the event using addEventListener ( 'enterFrame', callback_handler). |
I did use an AS file but failed horribly so if u want, please write the code u provided (above) as an AS file (constructor function etc...) because when i did so (using BubbleMaker3.as) as the document class in the fla, without anything on the stage, only a library item called bubble linked for AS, with BubbleMaker3.as looking like this:
package
{
import flash.display.*;
import flash.events.*;
import bubble;//this is irrelevant
public class BubbleMaker3 extends MovieClip
{
import flash.events.TimerEvent;
import flash.utils.Timer;
var bubblesInGame:uint;
public var bubbleTimer:Timer;
var container_mc:MovieClip;
var cursor3:MovieClip;
var score:int;
public function BubbleMaker3()
{
var bubbleA:MovieClip = new bubble;
bubblesInGame = 5;
bubbleTimer = new Timer(1100, bubblesInGame);
bubbleTimer.addEventListener(TimerEvent.TIMER, createBubbles);
bubbleTimer.start();
/*cursor3 = new Cursor3();
addChild(cursor3);
cursor3.enabled = false;
Mouse.hide();
stage.addEventListener(MouseEvent.MOUSE_MOVE, dragCursor);*/
score = 0;
function createBubbles(event:TimerEvent):void
{
addChild(bubbleA);
container_mc = new MovieClip();
addChild(container_mc);
container_mc.addChild(bubbleA);
bubbleA.x = Math.random() * stage.stageWidth;
bubbleA.y = (Math.random() * stage.stageHeight);
}
}
/*function dragCursor(event:MouseEvent):void
{
cursor3.x = this.mouseX;
cursor3.y = this.mouseY;
}*/
}
}
i got the same result re the position issue: when the movie clip appears on the stage in the swf, it is always in the same spot. Its position is indeed random but only at each additional test of the movie, not what i want.
Further, i got errors to do with the cursor being masked, hence it is commented in my code (above)
| D:\flash cs5.5\images\bubble_4_document_class\BubbleMaker2.as, Line 44 | 1120: Access of undefined property Mouse. |
Plus, the timer didnt work properly at all and addChild only add one instance of the bubble, the timer makes the movie clip appear to "jump" around the stage 5 times, and on the 5th, it stays and plays out, then reappears in the same position, as said.
Precisely why i didnt produce all this effort in my initial query....to try to focus on the question of: why when the Math.random code is in an mc on the stage it appears randomly while when it is on the main timeline or in a AS, does it not appear or trace randomly?
ok sorry i didn't run this example to test if it would work sorry.
you can still use the example I wrote for you but you'll have to change the function name to something else