-1

I found a swf file that does what I am trying to do. So I down loaded it and decompiled it so i could learn how to do it correctly. Then apply that to what I am working on. There are supposed to many items and the individual is to drag and drop it in to the correct catagory. If correct when it is released it stays, if incorect it moves back to start.What it looks like

I have made a couple of changes to the original file as it did not work. You can see where there was original code as in (onClipEvent). I seem to have fixed most problems but I can not release the dragged item onto the correct spot. I have also added action script to the sprites. Each colored triangle numbering them from one to 5 from left to right(hope this was correct) Thanks for your help. A frustrated science teacher.

    // Action script…

// [onClipEvent of sprite 2 in]
//onClipEvent (load)
this.addEventListener(Event.ENTER_FRAME, this.loading);
function loading(e:Event)
{
this.numItems = 2;
}

// [onClipEvent of sprite 2 in]

//onClipEvent (load)
this.addEventListener(Event.ENTER_FRAME, loading);
function loading(event:Event){
this.numItems = 3;
}

// [onClipEvent of sprite 2 in]

//onClipEvent (load)
this.addEventListener(Event.ENTER_FRAME, loading);
function loading(event:Event){
this.numItems = 3;
}

// [onClipEvent of sprite 8 in]

//onClipEvent (load)
this.addEventListener(Event.ENTER_FRAME, loading);
function loading(event:Event){
    this.defx = _x;
    this.defy = _y;
    if (this.theText.text.length > 20)
    {
        this.theText._height = 31;
        this.theBox._height = 27;
    }
    else
    {

        this.theText._height = 19;
        this.theBox._height = 19;
    } // end else if
}

// [onClipEvent of sprite 8 in frame 1]

//on (press)
this.addEventListener(MouseEvent.MOUSE_DOWN, pressed);
function pressed(event:Event){
    if (this.noDrag != true)
    {
        startDrag (this, false);
    } // end if
}

// [onClipEvent of sprite 8 in frame 1]

//on (release)
this.addEventListener(MouseEvent.MOUSE_UP, relea);
function relea(event:Event){
    if (this.noDrag != true)
    {
        stopDrag ();
        if(this.hitTest(_root["dz" + this.answer]))
        {
            totalHeight = 0;
            for (v = 0; v < _root.dbCount; v++)
            {
                if (_root["dbutton" + v].answer == this.answer)
                {
                    totalHeight = totalHeight + _root["button" + v].theBox._height ;
                } // end if
            } // end of for
            ++_root.dbCount;
            this .duplicateMovieClip("dbutton" + _root.dbCount, _root.dbCount * 100);
            _root["dbutton" + _root.dbCount]._x = this.defX;
            _root["dbutton" + _root.dbCount]._y = this.defY;
            _root["dbutton" + _root.dbCount].answer = _root.answerdest[_root.dbCount + 1];
            _root["dbutton" + _root.dbCount].theText.text = _root.answername[_root.dbCount +1];
            if (_root["dbutton" + _root.dbCount].theText.text == "undefined")
            {
                _root["dbutton" + _root.dbCount].theText.text = "Finished!";
                _root["dbutton" + _root.dbCount].noDrag = true;
            } // end if
            this.noDrag = true;
            this._y = _root["dz" + this.answer]._y + totalHeight;
            this._x = _root["dz" + this.answer]._x - _root["dz" + this.answer]._width / 2;
            ++_root["dz" + this.answer].numItems;
            _root.glamp1.gotoAndPlay (1);
        }
        else
        {
            this.x = this.defX;
            this._y = this.defY;
            _root.rlamp1.gotoAndPlay(1);
        } // end if
    } // end else if
}

// [onClipEvent of sprite 2 in frame 1]

//onClipEvent (load)
this.addEventListener(Event.ENTER_FRAME, loading);
function loading(event:Event){
this.numItems = 2;
}

// [onClipEvent of sprite 2 in frame 1]

//onClipEvent (load)
this.addEventListener(Event.ENTER_FRAME, loading);
function loading(event:Event){
this.numItems = 3;
}

// [Action in Frame 1]

answername = Array();

answerdest = Array();

answername[0] = "gravel";

answerdest[0] = "1";
answername[1] = "water";

answerdest[1] = "2";

dbCount = 0;

dbutton.duplicateMovieClip("dbutton" + dbCount,dbCount * 100);

dbutton.visible = false;

dbutton0.answer = answerdest[dbCount];

dbutton0.theText.text = answername[dbCount];
  • 2
    "I can not release the dragged item onto the correct spot." This does nothing to help us understand the problem. Tell us what exactly happens compared to what you observe happening. Is there an error message? Did you try running it with the debugger? Also, it sounds like your desired goal is a very simple one. Why decompile this one? Making a script do what you're describing is easy from scratch. I'd start from the beginning instead of reverse engineering someone else's code. But whatever suits you. – Neal Davis Dec 07 '16 at 04:18
  • When I release the mouse It does not drop the dragged item onto the target. Instead it stays with the mouse. Second I would like to start from scratch but could not find an example of how to set three items to one target and another differnet 3 items to a different target. This was the closest example i could find. I am relatively new at actionscript codding. – user7259892 Dec 08 '16 at 01:24

2 Answers2

0
//on (release)
this.addEventListener(MouseEvent.MOUSE_UP, relea);
function relea(event:Event){

Should be

//on (release)
this.addEventListener(MouseEvent.MOUSE_UP, relea);
function relea(event:MouseEvent){ // **** MouseEvent, not Event

You see? You are telling the relea function to expect anEvent. It should be expecting a MouseEvent. Does that fix it?

Neal Davis
  • 2,010
  • 2
  • 12
  • 25
  • Thanks for finding that error but unfortunately it did not fix the problem. still will not release the dragged object when I let go of the button. – user7259892 Dec 08 '16 at 01:36
  • On "this.addEventListener" what is "this"? It should be the thing you are releasing on. You could add a trace(this) in debug mode and tell me what it says in the output window. – Neal Davis Dec 08 '16 at 01:53
  • under output is shows _level0 does this make any sense to you? I thought "this" was my text box that i was moving – user7259892 Dec 08 '16 at 03:43
  • Is there a way that I can share the actual fla file as this might help just in case the error is in code I placed on one of the sprites? i am new to this site and am not sure if this is allowed? – user7259892 Dec 08 '16 at 03:54
  • _level0 is the main timeline or something like that. So instead of this.addEventListener do myTextBox.addEventListener – Neal Davis Dec 08 '16 at 05:08
0

Thanks for your help I found out the answer to this question was that I ended up placing the same code in both the sprites action frame and in the main time lines action frame it should only be in the sprites.