Greetings,
I am in my first few weeks of learning Action Script 3, and I’m still busily working through tutorials and lessons to figure all this out. I came across a tutorial for a rising bubble effect that I would like to implement in a school assignment, but I’m struggling with it:
Are the directions I followed, and an idea what I’m going for. I’ve modified the code a little bit from what was offered on the tutorial, adding notes to help myself along, and a couple of other small changes.
import flash.events.Event;
var bubbles = 100;
var thisBubble:Object;
for (var i = 0; i < bubbles; i++) {
thisBubble = this.addChild(new MC_bubble());
thisBubble.addEventListener(Event.ENTER_FRAME, displace);
thisBubble.yspeed = Math.random() * 2 + .2;
with (thisBubble) {
// Decides where on the X axis the bubbles will appear
x = Math.random() * stage.stageWidth;
// Decides where on the Y axis bubbles will appear
y = Math.random() * stage.stageHeight;
// Sets the size of the bubbles
width = height = 1 + Math.random() * 20;
// Opacity of the bubbles (??)
alpha = Math.random();
}
}
function displace(e:Event):void{
e.target.y -= e.target.yspeed;
if (e.target.y >= stage.stageWidth || e.target.x <= 0){
e.target.y = 400;
e.target.x = 10 + Math.random() * stage.stageWidth;
}
}
One modification I made was this line:
if (e.target.y = stage.stageWidth || e.target.x <= 0){
to
if (e.target.y == stage.stageWidth || e.target.x <= 0){
Before I made this change, the bubbles would all go crazy at the bottom of this stage, and this line had a compiler error of:
Warning: 1100: Assignment within conditional. Did you mean == instead of =?
Hence the reason for the change, but I recognize my modification here could be part of my new issue.
The problem I’m having is that the bubbles are not looping. I’ve researched the syntax of my for statement, and tried to find some better information on my function, but I’m still a newbie.
Can anyone offer any assistance? I imagine it’s something simple. Thank you in advance.
~Sarah