Actionscript help

I have a flash game that has the ‘drag and drop’ feature. The drag and drop works fine on the timeline (the main timeline) but the drag and drop feature that i have inside a movie clip doesnt work the same even tho the code is exactly the same. (i copied and pasted)

is this bcos it is in a movie clip? What extra coding wud I need to add to fix this issue?

Cheers, x:thumb2:

what’s the code? could be something simple like a path issue . . .

this is the code that works in the timeline but not the movie clip… they are the same code used over an over

 
onClipEvent (load) {
  origX = this._x;
  origY = this._y;
  
}
onClipEvent (mouseDown) {
  if (this.hitTest(_root._xmouse, _root._ymouse)) {
    this.startDrag();
 _root.answer1="";
  }
}
onClipEvent (mouseUp) {
  if (this.hitTest(_root._xmouse, _root._ymouse)) {
    this.stopDrag();
 _root.answer1 = "wrong";
    
    // see if the dropZone conatins the center of this mc
    if (_parent.dropZone1.hitTest(this._x,this._y,true)) {
      
      // center it on the drop zone
      this._x = _parent.dropZone1._x;
      this._y = _parent.dropZone1._y;
    } else {
      
      // return it to its original location
      
   this._x = origX;
      this._y = origY;
    }
  }
}

Where is dropZone1 located? If it is on the main timeline you can change _parent to _root. If it is not then you’ll have to adjust the path to it. Basically all _parent does is say go up and out one timeline from where the code is written and look for the object after the “.”

sorry i dont think i explained it well enough. Ive used the same code throughout the game (for drag n drop) but wen published the whole thing works but the ‘correct’ and ‘wrong’ feature doesnt show within the movie clip) but works fine on the timeline.
Maybe I can send you the file, cos i dont think im explaining it well.

I no its somethingto do with the movie clip, cos i also have a button that does the same thing, works in timeline, but not in movie clip…

do i need to go unload_movieclip??

I am just so confused as to why it all works fine if its in the main timeline but not if its in a mov clip

it won’t work inside a movieclip because the paths have changed. _root.something is now _root.MC1.something.

Are you familiar with the target tool? In your actionscript panel there is a button that looks like the scope on a rifle. Click it and you’ll see all the items in your file that have instance names and you’ll see how they are nested inside each other. Locate the one you want and select it and flash will automatically insert the correct path for you. You’ll notice if its different from what you have in the code.

If you still can’t get it post your fla :hr:

In my game the code i use here … [COLOR=#0000ff]_root[/COLOR].[COLOR=#000080]answer1[/COLOR] = [COLOR=#ff0000]“wrong”[/COLOR]; displays WRONG when you drop that number. Answer1 is the var name of the text box

when i use the target you mentioned i clicked on the Answer_field (this is the instance name of the text box. and i get this code come up

this._parent._parent.answer_field

now i need the text to display wrong so i made it look like this

this._parent._parent.answer_field = “wrong”

when i ran my game this didnt work. Im really confused and dont get why its not displaying the text “WRONG”.

How come i can use _root on the main timeline but It says to use this._parent._parent. within the moving clip using the target tool ??

I even tried _root.Game1_2.answer1 = “wrong” and this didnt display WRONG either. (Game1_2 is the name of my Movie Clip)

The drag and drop works fine, it just wont display the text I ask it to.

Please help.

Sorry, in that target tool you can choose whether you want to display the target as relative or absolute. Looks like you used relative?

Anyway, this._parent._parent means starting from the current timeline where the code is go out two timelines to find the text box called answer_field.

_root always refers to the main timeline.

Can you post your fla? If I can fix it and explain it to you it might be easier than just trying to guess how you have the file organized. :hr:

The file will be too big to post on here.

So would I use the Var name or the instance name? in the main timeline i use the Vasr name, code being _root.answer1 = “wrong”

Im guessing the code would be this._parent._parent.answer_field = “wrong” but that still doesnt display the text WRONG.

i fixed it :te:

code was this._parent.answer2 = “wrong”

thanks for your help. the direction you sent me lead me to the answer so thank you.

glad you figured it out! always most satisfying to do it yourself. :smiley: