Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    Flash




Starfield Class



There's no Source/Experiments section on here, so I figured i'd leave this bit of code with you guys...

I was recently working on a new game www.createage.com/Game/main.html and I needed to get a cool starfield effect, this really isn't a big deal but I figured that you guys could mess around with it, I don't know do whatever you want with it really, the class Definition is as follows:


ActionScript Code:
// put in flash===== var starfield = new Starfield(_root, 300, 5, -1);class Starfield{    private var target : MovieClip;    public function Starfield (target : MovieClip, starCount : Number, maxSpeed : Number, dir : Number)    {        this.target = target;        createStars (starCount, maxSpeed, dir);    }    private function createStars (starCount : Number, maxSpeed : Number, dir : Number) : Void    {        for (var i = 0; i < starCount; i ++)        {            var mc;            var dist : Number = Math.round (Math.random () * 100);            mc = target.createEmptyMovieClip ('star' + i, i);            mc.lineStyle (1, 0xFFFFFF, dist);            mc.lineTo (0, 1);            mc._x = Math.random () * 550;            mc._y = Math.random () * 400;            mc.speed = (dist / 100) * maxSpeed;            mc.onEnterFrame = function ()            {                                if (dir >= 0)                {                    this._x += this.speed;                    if (this._x > 550)                    {                        this._x = 0;                    }                } else                {                    this._x -= this.speed;                    if (this._x < 0)                    {                        this._x = 550;                    }                }            }        }    }}


You guys should know how to use it , anyway enjoy.
... oh yeah if you use this, the dots are WHITE so set your background to a dark color.

-Michael

If you don't know how to use it, just ask one of us will help you.



ActionScript.org Forums > ActionScript Forums Group > ActionScript 2.0
Posted on: 08-05-2005, 06:15 AM


View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread

Starfield Class
Hey guys, I was recently working on a new game www.createage.com/Game/main.html and I needed to get a cool starfield effect, this really isn't a big deal but I figured that you guys could mess around with it, I don't know do whatever you want with it really, the class Definition is as follows:


PHP Code:



// put in flash===== var starfield = new Starfield(_root, 300, 5, -1);class Starfield{    private var target : MovieClip;    public function Starfield (target : MovieClip, starCount : Number, maxSpeed : Number, dir : Number)    {        this.target = target;        createStars (starCount, maxSpeed, dir);    }    private function createStars (starCount : Number, maxSpeed : Number, dir : Number) : Void    {        for (var i = 0; i < starCount; i ++)        {            var mc;            var dist : Number = Math.round (Math.random () * 100);            mc = target.createEmptyMovieClip ('star' + i, i);            mc.lineStyle (1, 0xFFFFFF, dist);            mc.lineTo (0, 1);            mc._x = Math.random () * 550;            mc._y = Math.random () * 400;            mc.speed = (dist / 100) * maxSpeed;            mc.onEnterFrame = function ()            {                                if (dir >= 0)                {                    this._x += this.speed;                    if (this._x > 550)                    {                        this._x = 0;                    }                } else                 {                    this._x -= this.speed;                    if (this._x < 0)                    {                        this._x = 550;                    }                }            }        }    }} 




You guys should know how to use it , anyway enjoy.
... oh yeah if you use this, the dots are WHITE so set your background to a dark color.

-Michael

StarField
For some reason I cant find how to make a starfield like in startrack. Just want to know were a link to that is.

STARFIELD
HELLO

IM TRYING TO MAKE A STARFIELD KINF OF BACK GROUND WERE THE STARS BLAST OF THE MIDDLE

LIKE THE OLD SCREENSAVERS FOR WINDOWS
KNOW ANY TUTORIALS?

Starfield
I couldn't find what i was after with a search (just found syko's really cool starfield) but thats not what im after. If someone can show me an example of some or some links that would be great thanks

StarField
For some reason I cant find how to make a starfield like in startrack. Just want to know were a link to that is.

STARFIELD
HELLO

IM TRYING TO MAKE A STARFIELD KINF OF BACK GROUND WERE THE STARS BLAST OF THE MIDDLE

LIKE THE OLD SCREENSAVERS FOR WINDOWS
KNOW ANY TUTORIALS?

Starfield.....
Guys a on clip event that takes a clip and brings it from very tiny, to close up on the z axis. Say for instance if you wanted to create the illusion of traveling through space. But only use one clip and have it duplicate it self all over at different positions on the artboard.

Ewan, anyone?

Thanks in advance....


www.orlandomediasolutions.com
csatterwhite@orlandomediasolutions.com

Blinking Starfield
i am trying to make a starfield where certain stars blink, and others are stationary and dont do anything

i would like to use actionscript for this - unless someone has a nice, good looking way of doing it through something else

any help would be appreciated

it would also be good to have the stars be in random places and certain random stars will blink, but to a maximum - so say to a maximum of 10 stars, just so that all of them do not blink

also it would be nice if they blinked at different times and different speeds

anyways - sorry to ask so much, i figure if one person doesnt know one part, someone else will, or should

thanks

A Zooming Starfield?
In Flash MX, how could i create a simple starfield zooming past the viewer, as if you were going through hyperspace?

anyone have any ideas how to make the stars appear to be whipping past? and then coming to sudden stop?

if you could respond with as much detail as possible, that would help a bunch.

thanks!

Starfield/Warp Help Please
hey,
im having a lot of trouble trying to convert the code for this starfield...
http://www.actionscript.org/showMovie.php?id=569

problem is its in actionscript 1.0 whereas the application i need the warp in, is in actionscript 2.0. Im just not versed enough in knowing the differences in 1.0 and 2.0 to make a real difference...

I would really appreciate someone helping me out on getting this same effect on 2.0, thanks!

Stop Starfield?
I downloaded a starfield movie from this site and it works perfect. My only problem is Im trying to make the starfield play for only 10 seconds. Here is the code that makes the starfield:


Code:
var maxY = 725;

function star (){
this.Dot._xscale = this.Dot._yscale = 10;
this._rotation = Math.round(Math.random()*360);
this.scal = .5;
var r = Math.random()
this.scalFact = 1+r/3;
this.Dot._y = maxY-r*maxY;
}
star.prototype = new MovieClip;
sp = star.prototype;
sp.onEnterFrame = function(){
this.scal*=this.scalFact;
this.Dot._xscale = this.Dot._yscale+=this.scal/3;
this.Dot._y+=this.scal;

//width of starfield
if(this.Dot._y>400){
this.removeMovieClip();
}
}
Object.registerClass("Star", star);

function makeStar(){
for(i=0; i<Math.random()*5+3; i++){
++starCount;
attachMovie("Star", "Star"+starCount, starCount, {_x:350, _y:200});
}
}

starGen = setInterval(makeStar, 10);
How do I make it stop or clear after 10 seconds? Right now it just keeps looping the whole movie and the stars just keep coming.

Interactive Starfield
Hi everyone,
wondering if anyone can help me? I want to create a starfield. This I can do, simple motion toward the screen I can do, and its easy enough to use actionscript to apply a mouse control that changes the speed

However:

I want to be able to move the mouse left and right and the illusion of travel adjust to that particular direction. So like controlling a space craft travelling through space.

Can anyone help me in how to achieve this effect. If you would like an example of what effect I mean please visit this site:
www.amontobin.com
the animation in this field excursion is what I looking to achieve. I have Swift 3D if thats any help.

Thanks very much for the help and time

Sussex Tech

How To Make A Starfield?
I just can't seem to recreate the starfield effect.

My stars are either too big or blotchy and my animation just keeps
jumping about.

Can someone help me please?

Ta

Starfield Effect
does anyone know how you'd do something like the old "starfield screensaver"... you know where it looks like you are flying through space and the stars are passing you? anyone have any ideas or can maybe point me to a good tutorial that would help?

Parallaxed Starfield
Is it possible to generate a starfield that can be parallaxed with the mouse?

if so, can someone help me code this or send me in the right direction. thanks!

NOTE: star is a movieClip in my library which is set to export with actionscript

current code to generate a static starfield

Code:
//import mx. :: I don't recall this exact line of code, but it imports the mx Tween class
import mx.Transitions.*;

var stars:Array = new Array();
var MAX_STARS = 250; // how many stars are allowed on stage at once
var MAX_STAR_SCALE = 4; // the maximum size of a star

for(var i=0; i<MAX_STARS;i++)
{
// draw a new star on stage
newStar = _root.attachMovie( 'star', 'star'+i, i*1000 );

// adjust the star's position on stage
newStar._x = Math.ceil(Math.random()*Stage._width);
newStar._y = Math.ceil(Math.random()*Stage._height);

// resize the star to create false distance
// our star can be a maximum of 4 times the original star's size
newStar._width = newStar._width*Math.floor(Math.random()*MAX_STAR_SCALE);
newStar._height = newStar._height*Math.floor(Math.random()*MAX_STAR_SCALE);

// fade the star out and in as the mouse falls over it
newStar.onRollOver = function()
{
// create the tween
t = new Tween( this, "_alpha", Regular.easeIn, 0, 100, 1, true );
t.continueTo(0, 1); // fade out
t.continueTo(100, 1); // fade in
}

// just for fun, we can make the star explode when clicked
newStar.onRelease = function()
{
// explode the star
scaleY = new Tween( this, "_height", Bounce.easeIn, 0, 100, 1, true);
scaleX = new Tween( this, "_width", Bounce.easeIn, 0, 100, 1, true);
scale = Math.ceil(Math.random()*100);
scaleY.continueTo( scale * this._height, .5 );
scaleX.continueTo( scale * this._width, .5 );

// fade and die
fade = new Tween( this, "_alpha", Regular.easeOut, 100, 0, 1, true);
fade.continueTo( 0, 2 );

// take the star out of memory
unloadMovie(this);
}

// add our new star to a storage container for later use
stars.push( newStar );
}

Stopping Starfield?
Hi

Is it possible to stop a starfield after one frame? I followed this tutorial http://www.flashninjaclan.com/tutorialpage.php?ID=34 to make a starfield but i only want it on only one frame. at the moment it comes on all my frames and i wanted to know whether this can be stopped.

All help is much appreciated.

How To Make A Starfield?
I just can't seem to recreate the starfield effect.

My stars are either too big or blotchy and my animation just keeps
jumping about.

Can someone help me please?

Ta

3d Rotational Starfield - Toughy
Hi Guys,

Just wondering if anyone has any sugestions for this. I am just starting out making a fully 3d space sim. I have thought about the way I want to go about it in terms of distance etc.

I need to generate a starfield, The player will simply move the mouse to move up, down, left and right moving outward in each direction from the central point.

Mouse Up - will make the stars move down,
Mouse Down - will make the stars move up,
Mouse Left - will make the stars move right,
Mouse Right - will make the stars move left.

I would like to generate these stars randomly using the x and y co-ordinates with the random() command but it isn't nessessary.

Does anyone know how to create this so that when you rotate the screen 360 degrees the patern of stars will return to the pattern first seen, also this would need to work up and down etc...

Well any ideas? I know this might be a tricky one but i'm sure you guys could pull the stop out on this one

//Gary

[F8] Starfield-style Game
Hey, I'm having trouble making a game, and I cant seem to get something working. Here is what I have so far:

http://school.timswildwackyemporium....st/candy1.html

As you can see, When you play Once you catch the stars, they disappear.

As a result, the highest score you can get is one hundred.

I would like to make it so that rather than just delete the movieclip, I can movie it back into the beginning of the starfield.

I did not write the code for the starfield, which is why I'm having such trouble figuring this out.

Heres my code
ON THE FRAME

Code:
stop();
score = 0 ;
_root.attachMovie("count_down", "count_down", 12000, {_x:20, _y:330});
_root.attachMovie("hero", "hero_on_stage", 10000,{_x:200,_y:20});
_root.attachMovie("trail_sprite", "trail_mc", 8000);
trailbitmap = new flash.display.BitmapData(500, 350, true,0x000000);
_root.createEmptyMovieClip("trail", 1);
trail.attachBitmap(trailbitmap, 0);
trail_mc._visible = false;
hero_on_stage._visible = false;
power = .65;
yspeed = 0;
xspeed = 0;
wind = 0.00;
gravity = 0;
upconstant = 0.75;
friction = 0.99;
start_time = getTimer();
countdown = 30000;

hero_on_stage.onEnterFrame = function() {
elapsed_time = getTimer()-start_time;
_root.count_down.time_left.text = time_to_string(_root.countdown-elapsed_time);
if (elapsed_time >= countdown) {
_root.gotoAndStop(5);
_root.count_down.removeMovieClip();
};


if (Key.isDown(Key.LEFT)) {
xspeed = xspeed-power;
}
if (Key.isDown(Key.RIGHT)) {
xspeed = xspeed+power;
}
if (Key.isDown(Key.UP)) {
yspeed = yspeed-power*upconstant;
}
if (Key.isDown(Key.DOWN)) {
yspeed = yspeed+power*upconstant;
}
xspeed = (xspeed+wind)*friction;
yspeed = yspeed+gravity;
if (xspeed>15) {
xspeed = 15;
}
if (xspeed<-15) {
xspeed = -15;
}
if (yspeed>15) {
yspeed = 15;
}
if (yspeed<-15) {
yspeed = -15;
}
this._y += yspeed;
this._x += xspeed;
if (this._x<0) {
this._x += 500;
}
if (this._y<0) {
this._y += 350;
}
if (this._y>350) {
this._y -= 350;
}
if (this._x>500) {
this._x -= 500;
}

_root.trail_mc.trail_sprite._x = this._x;
_root.trail_mc.trail_sprite._y = this._y;
_root.trailbitmap.draw(_root.trail_mc);
trail_rectangle = new flash.geom.Rectangle(0, 0, 500, 350);
trail_blur = new flash.filters.BlurFilter(2, 2, 3);
_root.trailbitmap.applyFilter(_root.trailbitmap, trail_rectangle, new Point(0, 0), trail_blur);

};
MovieClip.prototype.placeInSpace = function(id) {
var ratio = this.focaldistance / Math.sqrt(this[id].z * this[id].z);
this[id]._x = this[id].x * ratio;
this[id]._y = this[id].y * ratio;
this[id]._xscale = this[id]._yscale = 1000 / this[id].z;
if (this[id].hitTest(hero_on_stage)){
_root.score ++;
this[id].swapDepths(10000);
this[id].removeMovieClip();

}
}

MovieClip.prototype.randomPlace = function(id) {
var radius = this.rmin + (this.rmax - this.rmin) * Math.random();
var polar = 2 * Math.PI * Math.random();
this[id].x = radius * Math.cos(polar);
this[id].y = radius * Math.sin(polar);
this[id].z = this.zmin + (this.zmax - this.zmin) * Math.random();
if (this[id].hitTest(hero_on_stage)){
_root.score ++;
this[id].removeMovieClip();
}
}


function time_to_string(time_to_convert) {
elapsed_hours = Math.floor(time_to_convert/3600000);
remaining = time_to_convert-(elapsed_hours*3600000);
elapsed_minutes = Math.floor(remaining/60000);
remaining = remaining-(elapsed_minutes*60000);
elapsed_seconds = Math.floor(remaining/1000);
remaining = remaining-(elapsed_seconds*1000);
elapsed_fs = Math.floor(remaining/10);
if (elapsed_hours<10) {
hours = "0"+elapsed_hours.toString();
} else {
hours = elapsed_hours.toString();
}
if (elapsed_minutes<10) {
minutes = "0"+elapsed_minutes.toString();
} else {
minutes = elapsed_minutes.toString();
}
if (elapsed_seconds<10) {
seconds = "0"+elapsed_seconds.toString();
} else {
seconds = elapsed_seconds.toString();
}
if (elapsed_fs<10) {
hundredths = "0"+elapsed_fs.toString();
} else {
hundredths = elapsed_fs.toString();
}
return minutes+":"+seconds+":"+hundredths;

}


ON THE STARFIELD MOVIECLIP

Code:
onClipEvent (load) {
this.count = 100;
this.speed = 3;
this.focaldistance = 25;
this.rmin = 50;
this.rmax = 1000;
this.zmin = 10;
this.zmax = 300;
for(var i = 0; i < this.count; i++) this.attachMovie("dot", i, i);

}

onClipEvent (enterFrame) {

for(var i = 0; i < this.count; i++) {
if((this[i].z -= this.speed) <= 0) this.randomPlace(i);
this.placeInSpace(i);

}

How To Move Spacecraft In Starfield
Hi all,
please see the following link,


Code:
http://www.flashkit.com/movies/3D/En...-850/index.php
in this link there is a starfield which moves in different direction according to mouse, Now i want to know how to show a spacecraft moving in this starfield.

Please anyone help me, I am trying this since many days.

Thank you for your time and consideration

Regards
Advika

Wish you a very Happy New Year !!! in advance

How To Create A Blinking Starfield With One Mc
I have create one blinking star in a mc.
It´s moving in a circle and blinking and changing colors.

Now I want to create a starfield with blinking stars where every individual
star is moving in a different way.

The problem is, if I copy and past 100 of this mc with my blinking star in the
same timeline (main) Theres no individuality. (I hope you understand my swedish/english).

I know that I can copy an paste the same mc at 100 different frames..but that´s "low tech.

Now then:
How the should the actionscript looks like which manage to solve this problem?
random something...??

I know I can read and learn, but I ´ve been working with this site for over a year now and I have
become halfblind (not really - I use glasses) of reading actionsript all nights long and working
at my regular job from 9 to 5.
The technical stuff It´s in other words not my strenght :wink

Here´s my portfolio site: http://www.goodwill.se
(The actionscripting is done with a lot of help from this forum)

Reverse Starfield Effect
Hey folks i am looking to reverse this effect http://jrgraphix.net/research/flash_starfield.php i want the circles to scale away rather then towards you. any ideas, tips, anything at all -thanks a bunch

Dynamic Starfield Don't Work
Hy

Can u please help me?

My starfield just don't move.
I realy dont know what to do!
please help.
it's urgent

thank you

Dynamic Starfield - SetInterval()
Hello, every. I was wondering why the following code is not working as expected:

ActionScript Code:
var starObj:Object = new Object();
var starDepth:MovieClip = new MovieClip();
var starArray:Array = new Array();
this.createEmptyMovieClip("starfield", 0);
var starMotion:Function = function () {
    starObj._x = random(401);
    starObj._y = 0;
    starObj._height = random(11)+10;
    starDepth = starfield.getNextHighestDepth();
    starfield.attachMovie("star_mc", starDepth, starDepth, starObj);
    starArray.push(starfield.getInstanceAtDepth(starDepth));
    for (i=0; i<starArray.length; i++) {
        with (starArray[i]) {
            if (_y-_height>500) {
                removeMovieClip();
                starArray.splice(i, 1);
            } else {
                _y += _height;
            }
        }
    }
};
starInterval = setInterval(starMotion, 30);


- THEORY -
It seems as though every time "splice()" is called, the for statement breaks. This would be fine if what I were dealing with was not graphical, however when the for statement breaks the rest of the movieClips in the array are forgotten and thus do not move. This makes for some very rough motion.
-----

"star_mc" is a movieclip in the library with the identifier "star_mc".

All help will be greatly appretiated.

Creating A Starfield Exhaust - Advice?
I am creating an exhaust from a space ship that dissolves into the site name. I'm trying to figure out the best way to approach this problem. I want the MC to trace the trail of the ship for a while but then eventually to dissolve quickly into the name.
I'm wondering if I should use maths or just do it manually. Unlike interactive duplicate clips, this path will stay stationary.

Any one have any ideas, examples, or tutorials that might give me some ideas?

Thanks
jeff

Infinite Panning...such As The Starfield Sample
I'm trying to create a 360 view of my house to place on my website, and do for a few of my friends. I've been able to manipulate the ActionScript for the Starfield Generator to limit it to only the X-Axis...but I cannot figure out how to place MY image instead of the Starfield...please, if you know how to do this, or to even correctly manipulate the ActionScript to allow for inputting MY image...please...PLEASE let me know. For more detail as to my needs, please email me ASAP...it might be beneficial...

Thanks to any and all that can help me.

Aaron

Generating A Random Starfield With The DuplicateMovieClip
I'm really new to actionscript, and I did this code, but it doesn't do anything...

code:
function addStars() {
nbstars = Math.round(Math.random()*200);
if (nbstars > 0) {
duplicateMovieClip("star", nbstars, "1");
setProperty("nbstars", _x, Math.round(Math.random()*400));
setProperty("nbstars", _y, Math.round(Math.random()*500));
nbstars--;
}
}
addStars();


What's wrong with it? The movie clip's instance name and name are "star" but it doesn't do anything.

Thanks
FleZ

Starfield Style HitTest Game
Hey, I'm having trouble making a game, and I cant seem to get something working. Here is what I have so far:

http://school.timswildwackyemporium....st/candy1.html

As you can see, When you play Once you catch the stars, they disappear.

As a result, the highest score you can get is one hundred.

I would like to make it so that rather than just delete the movieclip, I can movie it back into the beginning of the starfield.

I did not write the code for the starfield, which is why I'm having such trouble figuring this out.

Heres my code
ON THE FRAME

Code:
stop();
score = 0 ;
_root.attachMovie("count_down", "count_down", 12000, {_x:20, _y:330});
_root.attachMovie("hero", "hero_on_stage", 10000,{_x:200,_y:20});
_root.attachMovie("trail_sprite", "trail_mc", 8000);
trailbitmap = new flash.display.BitmapData(500, 350, true,0x000000);
_root.createEmptyMovieClip("trail", 1);
trail.attachBitmap(trailbitmap, 0);
trail_mc._visible = false;
hero_on_stage._visible = false;
power = .65;
yspeed = 0;
xspeed = 0;
wind = 0.00;
gravity = 0;
upconstant = 0.75;
friction = 0.99;
start_time = getTimer();
countdown = 30000;

hero_on_stage.onEnterFrame = function() {
elapsed_time = getTimer()-start_time;
_root.count_down.time_left.text = time_to_string(_root.countdown-elapsed_time);
if (elapsed_time >= countdown) {
_root.gotoAndStop(5);
_root.count_down.removeMovieClip();
};


if (Key.isDown(Key.LEFT)) {
xspeed = xspeed-power;
}
if (Key.isDown(Key.RIGHT)) {
xspeed = xspeed+power;
}
if (Key.isDown(Key.UP)) {
yspeed = yspeed-power*upconstant;
}
if (Key.isDown(Key.DOWN)) {
yspeed = yspeed+power*upconstant;
}
xspeed = (xspeed+wind)*friction;
yspeed = yspeed+gravity;
if (xspeed>15) {
xspeed = 15;
}
if (xspeed<-15) {
xspeed = -15;
}
if (yspeed>15) {
yspeed = 15;
}
if (yspeed<-15) {
yspeed = -15;
}
this._y += yspeed;
this._x += xspeed;
if (this._x<0) {
this._x += 500;
}
if (this._y<0) {
this._y += 350;
}
if (this._y>350) {
this._y -= 350;
}
if (this._x>500) {
this._x -= 500;
}

_root.trail_mc.trail_sprite._x = this._x;
_root.trail_mc.trail_sprite._y = this._y;
_root.trailbitmap.draw(_root.trail_mc);
trail_rectangle = new flash.geom.Rectangle(0, 0, 500, 350);
trail_blur = new flash.filters.BlurFilter(2, 2, 3);
_root.trailbitmap.applyFilter(_root.trailbitmap, trail_rectangle, new Point(0, 0), trail_blur);

};
MovieClip.prototype.placeInSpace = function(id) {
var ratio = this.focaldistance / Math.sqrt(this[id].z * this[id].z);
this[id]._x = this[id].x * ratio;
this[id]._y = this[id].y * ratio;
this[id]._xscale = this[id]._yscale = 1000 / this[id].z;
if (this[id].hitTest(hero_on_stage)){
_root.score ++;
this[id].swapDepths(10000);
this[id].removeMovieClip();

}
}

MovieClip.prototype.randomPlace = function(id) {
var radius = this.rmin + (this.rmax - this.rmin) * Math.random();
var polar = 2 * Math.PI * Math.random();
this[id].x = radius * Math.cos(polar);
this[id].y = radius * Math.sin(polar);
this[id].z = this.zmin + (this.zmax - this.zmin) * Math.random();
if (this[id].hitTest(hero_on_stage)){
_root.score ++;
this[id].removeMovieClip();
}
}


function time_to_string(time_to_convert) {
elapsed_hours = Math.floor(time_to_convert/3600000);
remaining = time_to_convert-(elapsed_hours*3600000);
elapsed_minutes = Math.floor(remaining/60000);
remaining = remaining-(elapsed_minutes*60000);
elapsed_seconds = Math.floor(remaining/1000);
remaining = remaining-(elapsed_seconds*1000);
elapsed_fs = Math.floor(remaining/10);
if (elapsed_hours<10) {
hours = "0"+elapsed_hours.toString();
} else {
hours = elapsed_hours.toString();
}
if (elapsed_minutes<10) {
minutes = "0"+elapsed_minutes.toString();
} else {
minutes = elapsed_minutes.toString();
}
if (elapsed_seconds<10) {
seconds = "0"+elapsed_seconds.toString();
} else {
seconds = elapsed_seconds.toString();
}
if (elapsed_fs<10) {
hundredths = "0"+elapsed_fs.toString();
} else {
hundredths = elapsed_fs.toString();
}
return minutes+":"+seconds+":"+hundredths;

}
ON FIELD MOVIECLIP

Code:
onClipEvent (load) {
this.count = 100;
this.speed = 3;
this.focaldistance = 25;
this.rmin = 50;
this.rmax = 1000;
this.zmin = 10;
this.zmax = 300;
for(var i = 0; i < this.count; i++) this.attachMovie("dot", i, i);

}

onClipEvent (enterFrame) {

for(var i = 0; i < this.count; i++) {
if((this[i].z -= this.speed) <= 0) this.randomPlace(i);
this.placeInSpace(i);

}

Blinking Starfield Out Of One Mc - The Final Question
I have create one tweening star in a mc.
Its´s a bitmap which is blinking and changing colors in a animated circle.

I´ve got one answer from shikozel who´s answered this:
>you need to give your star movie clip a linkage name. lets say star_mc. Then loop 100 times. in each
>loop you attach the >star_mc in a random place on the stage. lets say the width of your stage is
>500wx500h. The code should look like that:

>for(var i:Number=0;i<100;i++){
>star_mc=_root.attachMovie("star_mc","star_mc"+i,_rott.getNextHiestDepth())
>star_mc._x=random(500)
>star_mc._y=random(500)
>}


And the final question is:
Cool, this is the first step- to spread the mc all over.
But I wonder if they can be spread in time. Why?
- So every star is moving and blinking individual in time.
- Now the starfield moving and blinking as a group, where every
star is in the exactly same position in their tweening
process, in time.
(the blinking status is exactly the same for eveyone)
In other words:
How to create a starfield where every star is blinking and
changing it´s colors individual?
:b/]

3d Starfield Problem (based On Senocular's Script)
I have been working with the code from the tutorial on
Scripting 3D in Flash
by senocular .

http://www.kirupa.com/developer/acti...ape_camera.htm

What I am trying to do is add a button on the stage of the starfield mc that causes the camera to zoom back away from the star field ie "cameraView.target.z = -this.z".

I can get the stars to go in reverse just by changing the this.z to -this.z in the selectStar function. However, I cant seem to find a way to add this action to an mc that is stationary on my stage. My overall goal for this clip is to learn how to zoom into an object by pressing on it, then zoom back out to the original cameraView position. I tried just adding this action to my button:

on (press) {
_parent.cameraView.target.z = -this.z;
}

but all that did was stop all motion.

I really want to learn the script for doing dynamic websites like those done by sofake and wefail (i.e. Amplifier.com). I am self taught at flash and am currently going through a few books to learn actionscript, I really want to learn this (not just cut and paste) but I've run into a wall, and being that I'm the only Flash designer I know, it would be amazing if some kind person could lead me in the right direction.

P.S.(the sourcefiels can be downloaded here http://www.kirupa.com/developer/acti..._spaceship.htm )

Thank You for your time

Matt Fenton.

Calling A Function In Main Class From A Loaded Swfs Document Class
Hi
I have a main.swf that loads page.swf. They each have a document class called "Main" and "Page".

How can I call a function in Main from Page?

In AS2 this would be somthing like _parent.myFunction();


Cheers

Class Question: How To Access Timeline Objects From Class W/o Arguments
Hey all,

I am looking into builiding an application with OO functionality. I understand most of it. Except I cannot figure out how to access something in my app from a class. For instance, lets say I have one Loader class that loads some data and stores it in a variable inside the class (or on the main timeline, doesn't matter). Now, I know I can pass a reference to the data in an argument to another class for that class to manipulate. But if I have several data sources, and other variables and such, that I need to modify in a single class function, how would I do that without having to give the function access to them through arguments? I just want to be able to say, from a class, something like _root.someObject.someFunction();

So, any help would be greatly appreciated, and sorry if that made no sense at all, I tried to explain as best I could.

Happy Holidays!
Dave

[Flash 8] Referencing Class Variables From OnEnterFrame Created Within Class
Hi,
It's been a while since my last post here, but I was hoping someone could help me with a problem I'm having. I want to reference and change a class variable from within an onEnterframe function defined within a class. I can actually do this right now, but I want to do it in a different way. Here's a code sample of what I am talking about:


Test.fla file:

Code:
var t:tester = new tester()

Working tester.as file:


Code:
class tester{
private var num:Number = 100;

function tester(){
var classObj:tester = this;
var mc:MovieClip = _root.createEmptyMovieClip("test",1);
mc.onEnterFrame = function(){
trace(classObj.num); //This traces 100 (CORRECT!!!)
}
}
}
This traces 100 to the output window, just like it should

Here is the way that I would like to do it, because I want to reuse my onEnterFrame Stuff:

Code:
class tester{
private var num:Number = 100;

function tester(){
var classObj:tester = this;
var mc:MovieClip = _root.createEmptyMovieClip("test",1);
mc.onEnterFrame = this.mcOnEnterFrame;
}

private function mcOnEnterFrame(){
trace(num) //this traces undefined (BAD!!!)
}
}

As you can see, the work around to reading the class variable in the onEnterFrame function is to create a reference to the class object, before defining that function, then using the reference you created to access the class variables.

I have tried various iterations to get the second example working, but have had no luck. Does anyone know a way to get the second method working, or am I stuck using the first method.

AS3 Project In FDT + Flex SDK. Root Class Extends Visual Class From Swc
hello
question about compiling as3 project under FDT 3.0 with Flex SDK.

I want my main root class to contain some graphics already at the start. In Flash IDE I put some objects on the stage, make new symbol with all those objects inside, set linkage to MainClassGraphics, export it to swc, add this swc to source folder class-path. Then I write my root class:

Code:
package {

public class MainClass extends MainClassGraphics {
public function MainClass() {
trace('hey');
}
}
}

compiling with flex2 sdk - and I don't see any graphics. why?

if i try this way:

Code:
package {
import flash.display.Sprite;

public class MainClass extends Sprite {
public function MainClass() {
var s:Sprite = new MainClassGraphics();
addChild(s);
trace('hey');
}
}
}

then I see my graphics.. so swc looks like fine


crosspost here http://fdt.powerflasher.com/forum/vi...hp?f=21&t=2268

Accessing A Dynamic Text Field In A Class Other Than The Primary Class
I have tried to read and understand some of the other threads for this issue but, I think it would be easier to understand if I show my specific issue. I left some code out to make my issue more clear.

Alpha is the primary class with access to the stage. If I write the event listener and function contained in the Bravo function into the Alpha function it works. Although, I want it to be in a different class in the same package (such as the Bravo class).

I have created a instance of a class which is a physical object on the stage (lets say it's a card). The event listener is in the instance so that each instance has a self contained listener.

The bottom line is it works in the primary class but in no others. How can I make it access the text field (so when I click on the "card" the text field shows "something"?


ActionScript Code:
package a {
     public class Alpha {
          public function Alpha() {
               x:Bravo = new Bravo();
          }
     }
}

package a {
     public class Bravo {
          public function Bravo() {
               this.addEventListener(MouseEvent:CLICK, clickEvt);

               function clickEvt(event:MouseEvent) {
                    <MovieClip>.<MovieClip>.<DynamicTextField>.text = "something";
               }
          }
     }
}

Calling SetTimeout Within Custom Class And Cannot Access The Class' Variables
Hi All,

I'm creating an user interface with Flash 8, I'm new to Flash, my background is Java therefore I decided to use ActionScript to create a custom component that is reference within an external file.

My problem I believe is scope related. I have a status bar (label component), once I update the status bar I want to call the
"setTimeout" function to wait a couple of seconds before clearing my status bar. The "setTimeout" function is executing, but for some reason my status bar is not being cleared (accessed).

Below is a snippet of my code. Any help appreciated. Thanks.


/*
External File
*/
import mx.controls.Button;
import mx.controls.Label;

class MyApp
{
//private properties
private var mc_container:MovieClip;
private var btn:Button;
private var lbl_status:Label;
private var str:String = "do see me";

//constructor
public function MyApp(target:MovieClip)
{
trace("-- MyApp --");
mc_container = target.createEmptyMovieClip("mc_container", 100);
}
//public methods
public function init(width:Number, height: Number, xPos:Number, yPos:Number):Void
{
var my_app:MyApp = this;

btn = mc_container.createClassObject(Button, "btn", 1, {label:"click me"});
btn.setSize(100, 25);
btn.move(10, 10);
btn.clickHandler = function():Void
{
trace("btn clicked");
setTimeout(my_app.clearStatus, 2400);
//correct if I call directly
//my_app.clearStatus();
trace(str);
}

lbl_status = mc_container.createClassObject(Label, "lbl_status", 2, {text:"status bar message"});
lbl_status.setSize(200, 25);
lbl_status.move(0, 50);
}
public function clearStatus():Void
{
trace("calling clearStatus");
lbl_status.text = "";
}
}


/*
Called for Flash IDE
*/
var app:MyApp = new MyApp(this);
app.init(200, 200, 0, 0);

ActionScript 2.0 Class Scripts May Only Define Class Or Interface Constructs.
This is driving me nuts. I have an old AS1 project which I upgraded to AS2. It uses an include file, settings.as, which has stuff like this:
settings = new Object();
settings.property = 'some value';

Then I include it on the main timeline like this:
#include "settings.as"

Every time I render, I get a million and one Compile Errors stating:
"ActionScript 2.0 class scripts may only define class or interface constructs."

But it isn't an ActionScript 2.0 class! It's just a regular include. How do I avoid the bogus Compile Errors?

AddChild Works With Document Class, But Not Timeline-instantiated Class
I cannot get a sprite to display for me when I create an instance of a very simple class in my FLA file's timeline.
However, when I make the class file the FLA's document class file, it displays just fine.
The task in question is simply drawing a square with the shape class.

Problem example:
My class, Test.as, resides in the same folder as my FLA file - so I don't use any import statement. I'm new to lots of CS3 stuff. Can anyone tell me why this doesn't work and create the shape on the stage? This seems to fail silently without any errors:
var myTest:Test = new Test();

Working example:
Setting the document class to Test.










Attach Code

// Test class

package {
import flash.display.*;

public class Test extends Sprite {

public function Test():void{
doThing();
}

private function doThing():void{
var myRect:Shape = new Shape();
myRect.graphics.lineStyle (2, 0xcc0000, 1);
myRect.graphics.beginFill(0xcccccc, 1);
myRect.graphics.drawRect(10, 10, 200, 200);
addChild(myRect);
}
}
}

[AS3] Making An Auto-generated Class Inherit From Custom Class?
hi, just wondering if this is possible

i was hoping to find a way to get a bunch of objects in my library to inherit from (or even be) one class that i have made, but without having to make .as files for every single one

is this possible, or is there any other way to give objects another classes functionality in an auto-generated class?

cheers

Tough One: Accessing Class Methodes From Other Class Files
Tough question for the experts...

In my classfile class Classes.tools.depthManager, I've got a static methode


Code:
public static function getLoopDepth():Number {
In another classfile Classes.tools.frameRateViewer, I want to access that methode


Code:
var tempDepth = Classes.tools.depthManager.getLoopDepth();
The compiler claims: "There is no class or package with the name 'Classes.tools.depthManager' found in package 'Classes.tools'."

So I tried writing import Classes.tools.* at the top of my Classes.tools.frameRateViewer.as, hoping I could just write


Code:
var tempDepth =depthManager.getLoopDepth();
But there the compiler claims: "The class being compiled, 'Classes.tools.depthManager', does not match the class that was imported, 'depthManager'."

I'm sure the Classes.tools.depthManager.as works fine: I can call the static depthManager.getLoopDepth() from a button in the fla file...

Any ideas? Thanks!

Window Class Attach Scrollbar/Pane Class?
I am using MX 2004 Prof...

Is there a way to attach a scrollbar/pane to the body of a Window class to make the content scroll?

Button Created Within Class Cannot Access Class Properties
Hi,
I'm using the following code within a class:
code:
_head_mc.attachMovie("headButton", "head_btn", this.getNextHighestDepth());

_head_mc.head_btn.onRelease = function () {
containingClip_mc._parent._parent.clickedHead(_per sonName);
}


The button gets attached (line 1). This works because I can see the mouse changing to a finger.

The onRelease function is declared and works. I know because if I put a trace in there, it works.

The function it calls (containingClip_mc._parent._parent.clickedHead also works, becuase I can see traces from within it.

But the _personName variable is passed as undefined.

I know that this variable has a value, because I can trace it outside the function, but it seems that this onRelease function is not able to see the variable. It's declared as private, but setting it to public doesn't fix anything.

I imagine there's something I don't understand about the scoping of variables. I've tried _parent references, but that doesn't appear to help either. Is there a better way to do this or a workaround?

Barrette

Added by edit
Okay, I've pretty much determined this is a scoping issue. From the onRelease function, I'm unable to access ANY of the functions within my class. I still would like advice on how to do so..

Barrette

[Flash8] Calling BitmapData Class From Within Custom Class
I've written a custom class which resides in a .as file. Is there any way that functions from within my class can call the BitmapData class for bitmap manipulation?

**Error** ActionScript 2.0 Class Scripts May Only Define Class........
**Error** ActionScript 2.0 class scripts may only define class or interface constructs.
b2.onPress = function() {

**Error** ActionScript 2.0 class scripts may only define class or interface constructs.
b3.onPress = function() {

**Error** ActionScript 2.0 class scripts may only define class or interface constructs.
b4.onPress = function() {

ok this is what i have.

1 Movie clip with links to a .as file all is working fine the above error occurs when i publish the 1 movie clip which is getting pulled into the main movie

Any idea's it does not happen when 1 movie clip is published on its own just when 1 move clip is pulled into my main movie clip.

[F8] Referencing A Static Class Inside Another Class's Instance
I've got a movie loading into a framework.

This framework has 1 instance of the class main called main.

Inside this class, another class is used, but it is used directly, not as an instance. E.g.:
code:
import com.StaticClass;
class main {
private function UseStaticClass():void {
StaticClass.init();
}
}


From my movie, I can reference the main instance as _root.main. Can I reference StaticClass at all if there's no explicit instance created or it's not assigned to a public variable?

I can't modify main to include getter/setter methods, that's why I ask.

Thanks.

Child Class Trigger Event For Parent Class
is there a way for a parent class to listen to a variable in a subclass, and when it changes, run a function?

This seems like a pretty simple thing to do. I'm trying to keep my subclass independent of my main class, so i just have a variable that is set to false, and when its finished, it sets the variable to true.

The only thing i can think of is having an onEnterFrame that keeps checking the variable...but it seems like an event would be more efficient.

thanks!

Tween Class Applied In Custom Class Not Working
var sizerW:Object = new Tween(pda_mc,"_xscale",mx.transitions.Tween.None.e aseNone,pdaOrigW,pdaSmallW,3,true);

this code produces and error when applied in a custom class but not in a fla?

the error = There is no property with the name 'None'.

Custom Transitionmanager Class Problem/class Scope?
I'm writing a class that fades from one scene to another in a video game. A custom transitionManager object is created, and a listener is attached. Once the fade out from one scene is complete, the listener is triggered, the scene switches, and the new scene fades in.

This is the error I'm getting: "There is no method with the name 'myTransitionManager'.
myTransitionManager.addEventListener("allTransitio nsOutDone", fadeListener);". It is given everytime myTransitionManager is accessed by any of the class functions.

I assume this is a class scope issue. How can I create a custom transitionManager object accessable to the entire class? I need it to be accessed by at least three separate class functions.

Here's the source, starting with the constructor for the GameSection class:


Code:
public function GameSection(clip_to_fade:MovieClip){
var myTransitionManager:TransitionManager = new TransitionManager();
}

//class methods

function switch_section(clip_to_fade:MovieClip, fade_in_scene:String) {
// Define a listener object to use with the Tween objects.
var fadeListener:Object = new Object();
//create event listener for transitions being complete
fadeListener.allTransitionsOutDone = function(eventObj:Object) {
trace("allTransitionsOutDone event occurred.");
gotoAndPlay(fade_in_scene);
fadeIn(clip_to_fade);
};
myTransitionManager.addEventListener("allTransitionsOutDone", fadeListener);


fadeOut(clip_to_fade);
}

function fadeIn(in_mc:MovieClip) {
myTransitionManager.start(in_mc, {type:Fade, direction:Transition.IN, duration:1, easing:None.easeNone});
}

function fadeOut(out_mc:MovieClip) {
myTransitionManager.start(out_mc, {type:Fade, direction:Transition.OUT, duration:1, easing:None.easeNone});
}


Thanks!

Static Class Variable Referencing Class Instance
I was given the task of writing a class that would send serial requests for xml data, the idea being that the requests could be added while previous requests were still in progress, but the class would queue them and wait for the reply of one request to come back before sending the next.

The way I did this was to create a class instance for each request, and the request itself would be stored in an instance variable, waiting to be sent. A static variable called queue (accessible to all instances) was then given a reference to the instance, and when this reference got to the top of the queue, queue would call the sendRequest() method on that instance.

The reason why I am using one instance per request is so that the replies can be retrieved via the instance, so keeping each request entirely discreet.

Everything works very nicely, but the problem is my IT manager looked at the code and told me that you cannot put a reference to a class instance in a class static variable... and for this reason he has informed my line manager that he has serious reservations about the code, and recommends that it is not incorporated it into the project. However, the code works very well on my local machine and on the testsite, and no-one has experienced any problems with it.

Can someone reassure me here... I can see absolutely nothing wrong with having a class static array hold references to each of the instantiated class instances. And the proof is in the pudding.. it works. Can anyone else see a problem here?

Copyright © 2005-08 www.BigResource.com, All rights reserved