Google
 
Webnews.only-4-geeks.com
Interesting places
news.only-4-geeks.com Forum Index » Flash - ActionScript

putting a game inside one big movieclip

 
Jump to:  
 
Jale3
PostPosted: Wed Sep 03, 2008 3:12 am    Post subject: putting a game inside one big movieclip
       
I'm using the script below on a movie clip that moves and interacts with other
movie clips. the movie clip the script is applied to is on it's own keyframe
on the timeline in the main scene. now, i want to put everything i just made
(the movie clip the script is applied to and the movie clips it interacts with)
into one big movie clip so i can easily put it on a flash based website. I'm
pretty sure the "_root." has to be changed but I'm not quite sure what to
change it to

onClipEvent (load) {
power = .35;
radius = 7.5;
yspeed = 0;
xspeed = 0;
friction = 0.95;
gravity = 0.1;
thrust = 0.75;
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.LEFT)) {
if (!_root.wall.hitTest(_x-9, _y, true)) {
xspeed -= power*thrust;
}
}
if (Key.isDown(Key.RIGHT)) {
if (!_root.wall.hitTest(_x+9, _y, true)) {
xspeed += power*thrust;
}
}
if (Key.isDown(Key.UP)) {
if (!_root.wall.hitTest(_x, _y-9, true)) {
yspeed -= power;
}
}
if (Key.isDown(Key.DOWN)) {
if (!_root.wall.hitTest(_x, _y+9, true)) {
yspeed += power;
}
}
if ((_root.wall.hitTest(_x, _y+9, true)) or (_root.wall.hitTest(_x, _y-9,
true)) or (_root.wall.hitTest(_x+9, _y, true)) or (_root.wall.hitTest(_x-9, _y,
true))) {
_root.play();
}
if ((_root.win.hitTest(_x, _y+9, true)) or (_root.win.hitTest(_x, _y-9,
true)) or (_root.win.hitTest(_x+9, _y, true)) or (_root.win.hitTest(_x-9, _y,
true))) {
_root.gotoAndPlay(13);
}
xspeed += gravity;
yspeed *= friction;
_y += yspeed;
_x += xspeed;
}
 

 
NSurveyor
PostPosted: Wed Sep 03, 2008 10:31 am    Post subject: Re: putting a game inside one big movieclip
       
Jale3,

You are absolutely correct. _root refers to the main timeline of a movie. By
restructuring your timeline, many of the paths no longer refer to actual
MovieClips. There are a few ways of fixing this.

1. Using an absolute path again. If you give the "one big movieclip" an
instance name of "big_mc", you would change all the _root's to _root.big_mc.
However, this method is not recommended as it is what caused the problem in the
first place.

2. Using a relative path. Clearly, the MovieClip with the above code will
always be on the same timeline, with the wall and win MovieClips as well. And
so, if this clip "looks" for the others from its point of view, then there
should never really be a problem where you place the game. In this case, you
could replace _root with this._parent. "this" simply refers to the current
timeline (of the MovieClip that the code resides on) and "_parent" refers to
the parent timeline from the specific MovieClip.

3. A third, lazier option would be to make all references of _root refer to
the "big movieclip" and this can be achieved with one line:
big_mc._lockroot = true;

Despite being the easies fix, the second method is a better approach as there
might be complications of some sort down the line.

By the way, you might want to look into the onEnterFrame event handler as a
replacement for the outdated onClipEvent.
 

 
Jale3
PostPosted: Wed Sep 03, 2008 10:01 pm    Post subject: Re: putting a game inside one big movieclip
       
I've tried this._parent with the buttons and they work once everything is in
one movie clip and that works fine. the code for the buttons is below. But
when i tried to replace all "_root" to "this._parent" on the main movie clip
that moves and nothing happens. it moves fine with the arrow keys but it
doesn't do onything when it touches the 'wall", nor when it touches the "win".
What can anyone make of it?

<<For "start" Button>>

onClipEvent (enterFrame) {
if (Key.isDown(Key.ENTER)) {
this._parent.play();
}
}

<<For main character>>
onClipEvent (load) {
power = .35;
radius = 7.5;
yspeed = 0;
xspeed = 0;
friction = 0.95;
gravity = 0.1;
thrust = 0.75;
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.LEFT)) {
if (!this._parent_mc.wall.hitTest(_x-9, _y, true)) {
xspeed -= power*thrust;
}
}
if (Key.isDown(Key.RIGHT)) {
if (!this._parent_mc.wall.hitTest(_x+9, _y, true)) {
xspeed += power*thrust;
}
}
if (Key.isDown(Key.UP)) {
if (!this._parent_mc.wall.hitTest(_x, _y-9, true)) {
yspeed -= power;
}
}
if (Key.isDown(Key.DOWN)) {
if (!this._parent_mc.wall.hitTest(_x, _y+9, true)) {
yspeed += power;
}
}
if ((this._parent_mc.wall.hitTest(_x, _y+9, true)) or
(this._parent_mc.wall.hitTest(_x, _y-9, true)) or
(this._parent_mc.wall.hitTest(_x+9, _y, true)) or
(this._parent_mc.wall.hitTest(_x-9, _y, true))) {
this._parent_mc.play();
}
if ((this._parent_mc.win.hitTest(_x, _y+9, true)) or
(this._parent_mc.win.hitTest(_x, _y-9, true)) or
(this._parent_mc.win.hitTest(_x+9, _y, true)) or
(this._parent_mc.win.hitTest(_x-9, _y, true))) {
this._parent_mc.gotoAndPlay(13);
}
xspeed += gravity;
yspeed *= friction;
_y += yspeed;
_x += xspeed;
}
 

 
Jale3
PostPosted: Wed Sep 03, 2008 10:06 pm    Post subject: Re: putting a game inside one big movieclip
       
(The "MC" after this._parent is a mistake made by my, and even when i take that away nothing happens
 

 
Jale3
PostPosted: Wed Sep 03, 2008 10:06 pm    Post subject: Re: putting a game inside one big movieclip
       
(The "MC" after this._parent is a mistake made by me, and even when i take that away nothing happens
 

Page 1 of 1 .:.

Google
 
Webnews.only-4-geeks.com

Windows Update | C++ | C | PHP | JavaScript | Photoshop | Programming | Windows 2000 | Python | Windows XP | Object | Flash | Flash - ActionScript | Paint Shop Pro | Excel | PowerPoint | Access | Word | Windows 98 | Internet Explorer 6.0 | CorelDraw12 | Java | XML | asm x86 | Linux Mandrake | Linux RedHat | Outlook |  | news from newsgroups |_ | s

Web Templates

Awesome Website Templates ©

gry i zabawy Rijana Transport HACCP Dynamika maszyn elektrycznych prÄ…du przemiennego