(Flash MX) Scripting movement and Playing imported SWFs

Hello everyone,

I am new at Action Scripting, so please forgive me if these questions sound ridiculous.

I’ve altered Kirupa’s tutorial on “creating continuous motion” to make lines flash by from left to right. This is what the code looks like:

onClipEvent (enterFrame) {
//generating movement
location = this._x;
var i;
i = 1+_root._xmouse/5;
if (this, hitTest(_root.block)) {
this._x = -500;
} else {
this._x = location+i++;
}
}

It works great, but I’d like to alter the code a bit more.

So here is Question 1: How can I make the lines move from left to right independently from the x-axis mouse movement, so that the speed and direction of the lines remain constant? (Right now, a lateral movement of the mouse slows down/accelerates my lines, and can even make them go backward, something I don’t want.)

Question 2:

The file I mentioned above is called “moving_lines.swf.” Another file named “main.swf” calls it into action with this code:

_root.lines.loadMovie(“moving_lines.swf”);

What’s weird is that it plays the flashing lines only once, instead of continuously. I haven’t put any “stop” command anywhere. Can anyone tell me what I am doing wrong?

Thank you very much for your help!

D.

I’m not sure about #1 question but I think I can solve #2. You say it only plays once? Try changing the code in the moving_lines.swf movie from: onClipEvent (enterframe) {; to ;

onClipEvent (load) {

  • Hope that helps :thumb:.

Thank you, Sharif, for your prompt response. Unfortunately, your suggestion didn’t work. The lines just stopped moving when I replaced (enterframe) with (load).

Regarding Question no. 1, I figured it out thanks to another of Kirupa’s tutorial, one on basic X-axis movement. The code for the moving lines now reads as follows:

onClipEvent (enterFrame) {
//generating movement
location = this._x;
speed = 1;
if (this, hitTest(_root.block)) {
this._x = -500;
} else {
this._x = location+100;
}
}

It works great on preview mode by itself, but as soon as I import the file into another movie, pffft, it only plays once. … I’m running out of walls to bang my head onto!

D.

Change the “_root.block” in “_parent.block”
[AS]onClipEvent (enterFrame) {
//generating movement
location = this._x;
speed = 1;
if (this, hitTest(_parent.block)) {
this._x = -500;
} else {
this._x = location+100;
}
}[/AS]

scotty(-:

Scotty,

thank you for your suggestion. Even though it didn’t work, it did put me on the right track. Instead of putting the block that respawns the lines in the child swf (the “hitTest”), I simply took out the symbol and put it on the main document. The code remains the same, but now it works the way it’s supposed to. Thank you Scotty and Sharif for giving me a hand!

D.

It was worth a try:)
btw just now I saw that the code should be[AS]onClipEvent (enterFrame) {
//generating movement
location = this._x;
speed = 1;
if (this.hitTest(_parent.block)) {
this._x = -500;
} else {
this._x = location+100;
}
}

[/AS]
a point in stead of a comma…

scotty(-: