Jump to content

Kizzi Needs Actionscript Help... [lock plz mods]


Recommended Posts

I'm learning scripting (Actionscript 2 on MX Professional), and I've made a circle that you can drag, a square that you can't, and some dynamic text that says "Drag the circle to the square." However, I don't know how to make it change the text when you drag the circle in the square. So:

1) The code (duh, lol).

2) Possibly an explanation.

[spoiler=Code on the Circle]

onClipEvent (mouseDown) {

if (this.hitTest(_root._xmouse, _root._ymouse)) {

startDrag(this, false);

}

}

 

onClipEvent (mouseUp) {

if (this.hitTest(_root._xmouse, _root._ymouse)) {

stopDrag();

}

}

 

 

 

Edit: Okay, I've got the trace command working, so how do I make the text change?

[spoiler=Code on the Layer]

circle.onRelease = function(){

if (circle.hitTest(area)) {

trace("You dragged the circle to the square!") }

else {

trace("Drag the circle to the square.") };

}

 

 

 

Edit2: I've got the text to change, but it'll only change once, and appears as "0layer1.txt" at the start.

[spoiler=Updated Code]

circle.onRelease = function(){

//The only way I can get it to work.

if (circle.hitTest(area)==true) {

txt.text="You dragged the circle to the square!" }

else {

txt.text="Drag the circle to the square." }

}

 

 

 

Edit3: Thanks to Cyber Lucifer for helping me.

[spoiler=Final Code]

[spoiler=Frame1]

circle.onRelease = function() {

if (circle.hitTest(area)==true) {

gotoAndStop(2);

}

}

 

onEnterFrame = function() {

if (circle.hitTest(area)==true) {

gotoAndStop(2);

}

else {

gotoAndStop(1);

}

}

 

 

[spoiler=Frame2]

circle.onRelease = function() {

if (circle.hitTest(area)==false) {

gotoAndStop(1);

}

}

 

 

[spoiler=Circle]

onClipEvent (mouseDown) {

if (this.hitTest(_root._xmouse, _root._ymouse)) {

startDrag(this, false);

}

}

 

onClipEvent (mouseUp) {

if (this.hitTest(_root._xmouse, _root._ymouse)) {

stopDrag();

}

}

 

 

 

 

Link to comment
Share on other sites

Well I suppose you should make a new keyframe.

Then edit the code on frame to:

circle.onRelease = function(){

if (circle.hitTest(area)) {

gotoandstop(2);

}

 

Then in that keyframe do everything you want to do.

Hope it works

I managed to fix it using what you've given me. Tyvm' date=' +rep :D

[spoiler=Final Code']

[spoiler=Frame1]

circle.onRelease = function() {

if (circle.hitTest(area)==true) {

gotoAndStop(2);

}

}

 

onEnterFrame = function() {

if (circle.hitTest(area)==true) {

gotoAndStop(2);

}

else {

gotoAndStop(1);

}

}

 

 

[spoiler=Frame2]

circle.onRelease = function() {

if (circle.hitTest(area)==false) {

gotoAndStop(1);

}

}

 

 

[spoiler=Circle]

onClipEvent (mouseDown) {

if (this.hitTest(_root._xmouse, _root._ymouse)) {

startDrag(this, false);

}

}

 

onClipEvent (mouseUp) {

if (this.hitTest(_root._xmouse, _root._ymouse)) {

stopDrag();

}

}

 

 

 

 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

Guest
This topic is now closed to further replies.
×
×
  • Create New...