# (Flash MX) Scripting movement and Playing imported SWFs

**URL:** https://forum.kirupa.com/t/flash-mx-scripting-movement-and-playing-imported-swfs/38726
**Category:** flash
**Created:** [December 29, 2003, 1:50am UTC](https://forum.kirupa.com/t/flash-mx-scripting-movement-and-playing-imported-swfs/38726 "2003-12-29T01:50:01Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![demonqueller](https://avatars.discourse-cdn.com/v4/letter/d/dc4da7/32.png) [@demonqueller](https://forum.kirupa.com/u/demonqueller)
#### Post date: [December 29, 2003, 1:50am UTC](https://forum.kirupa.com/t/flash-mx-scripting-movement-and-playing-imported-swfs/38726/1 "2003-12-29T01:50:01Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [December 29, 2003, 1:59am UTC](https://forum.kirupa.com/t/flash-mx-scripting-movement-and-playing-imported-swfs/38726/2 "2003-12-29T01:59:23Z")

</div>

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:.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [December 29, 2003, 7:10am UTC](https://forum.kirupa.com/t/flash-mx-scripting-movement-and-playing-imported-swfs/38726/3 "2003-12-29T07:10:58Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [December 29, 2003, 9:05am UTC](https://forum.kirupa.com/t/flash-mx-scripting-movement-and-playing-imported-swfs/38726/4 "2003-12-29T09:05:53Z")

</div>

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(-:

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [December 29, 2003, 2:26pm UTC](https://forum.kirupa.com/t/flash-mx-scripting-movement-and-playing-imported-swfs/38726/5 "2003-12-29T14:26:22Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [December 29, 2003, 3:02pm UTC](https://forum.kirupa.com/t/flash-mx-scripting-movement-and-playing-imported-swfs/38726/6 "2003-12-29T15:02:55Z")

</div>

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(-:
