Link to home
Start Free TrialLog in
Avatar of basiclife
basiclife

asked on

Flash - multiple instances with different properties

This question is a follow-up to http:Q_21185524.html

I want to create floating balloons which are buttons with different colour, text and motion. Any help greatly appreciated
Avatar of Vicker Leung
Vicker Leung
Flag of Hong Kong image

basiclife~

Haha is great that you really wanna know about it~!!

The scripts are little bit hard right here,
I will provide you my sample file later~!!

However I will point out the steps here.

First of all, draw a simple balloon movie clip~
This movieclip should contains a ballon image and a dynamic text field named "content"
Remember that it should be a movieclip!!

And then in the library, right click the balloon mc, click linkage...
Identifier field fill in "balloon"
And then tick the export for actionscript and tick the export in first frame boxes.

In the main stage, add the following codes in frame 1

_root.createEmptyMovieClip("balloon_area", 1); // This is the area which the balloon will be present.
_root.balloon_area._x = 0; // Confirm the position of the balloon area
_root.balloon_area._y = 0;
_root.balloon_number = 1; // This is a number to identify each balloon from each other

_root.balloon_content = new Array ("flash", "dreamweaver", "firework", "freehand", "expert", "exchange"); // An array to store all the names for the balloon

And then add these codes in frame 10, actually what frame number larger than 1 is ok. No big deal
 
balloon_name = "balloon_" add _root.balloon_number; // This will make a more meaningful name for the balloon
_root.balloon_area.attachMovie ("balloon", balloon_name, _root.balloon_number); // It pull a balloon from the library to the balloon area
_root.balloon_area [balloon_name]._x = random (640); // Randomly place the balloon on the stage
_root.balloon_area [balloon_name]._y = 480; // Put the balloon to the bottom
_root.balloon_area [balloon_name].content.text = _root.balloon_content [random (6)]; // Put random text into the balloon
_root.balloon_area [balloon_name].speed = random (5) + 3; // Random speed of the balloon

_root.balloon_area [balloon_name].onEnterFrame = function ()
{
      this._y = this._y - this.speed; // Move the balloon according to it's own speed
      
      if (this._y < -250)
      {
            this.removeMovieClip (); // Remove the balloon is it is out of bound
      }
}
_root.balloon_number++;


on frame 50, put in this code
actually this is a loop back to the code in frame 10 so that another balloon is built
so, if this frame is farer, the balloon will be generated slower

gotoAndPlay (10);

That's it~~!! :)
Vicker
basiclife,

Sample files here~~!!

www.geocities.com/vickerleung/balloon.zip

Of course, draw better balloon than mine before use :p

Vicker
Avatar of basiclife
basiclife

ASKER

"This GeoCities site has been deactivated due to inactivity."

You can upload the file here and it'll arrive on my PC

http://bristol-house.demon.co.uk/uni/upload.php put the file in /misc
basiclife,

Haha I am sorry that it is inactivated,

But it is funny that I just upload my file, and it say inactive =.=""

no matter, I have reativated my site and also uploaded to your FTP
Sorry for any inconvenience~

Gd luck :)
Vicker
No inconvenience at all. Thatnks for the upload. I'm guessing you're using MX 2004? I'm using MX and it wouldn't open the file, however, with a little bit of imagination and a hex editor I can see the script in the file itself (well most of it, I think).

Nice balloons ;-)

If you're bored and have the time, could you upload the file in an older format? Or will my version be unable to do the scripting you've described?

Either way I'm going to sit and have a play for a few hours. Thanks very much for your help so far

In case anyone else wants the file you uploaded, it's at http://bristol-house.demon.co.uk/balloon-28.10.04-09.03.56.zip
basiclife,

O~~ sure,

I will upload as MX version

Catch the balloons in your FTP~

Cheers :)
Vicker
ok, that file's at  http://bristol-house.demon.co.uk/balloon-28.10.04-09.27.01.zip for anyone reading this later...

Ok, that one loads fine - Thank you very much!

I can see it creating the objects and scrolling through their locations, setting captions, etc...

Ok, some questions: Why does it have to be a movie clip? as I said in the last thread I'm new to this (although the programming itself is not a problem, just the concept here). Also, how can I add mouse interaction? Are the o~~~ 's actually buttons? Despite the fact they're created as a movie clip?

_root.balloon_area[balloon_name].content.text = _root.balloon_content[random(6)]; <-- The 6 is the size of the array I'm guessing?

and lastly, what controls the rate of creation of balloons? Did I miss something? I'm gussing there is no reasonable limit to how many balloons you have except memory / rendering speed (this won't be an issue but I'm curious)
And now I've left you with that Mammoth set of questions, I'm off to get some sleep. See you tomorrow. Thanks for your help
ASKER CERTIFIED SOLUTION
Avatar of Vicker Leung
Vicker Leung
Flag of Hong Kong image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
o~~~'s = balloons. sorry
basiclife,

You have scripting error~~!!

It should be

o~~~'s= balloons. sorry;

You missed the semicolon~ haha

Vicker
lol