Problems with loaded movieclips

Hi there!

I am trying to make mc’s wich are loaded (by data wich stored in a database) on the internet draggable.
This should be easy, but for some reason it won’t work.
My code looks like this:


AnDo = new LoadVars()
AnDo.load("http://www.maartenlierop.nl/janv/janv.php") 
AnDo.onLoad = function(succes){
    if(succes){
        trace("communicatie succesvol");
        for(var i=0; i<this.cant; i++){
// loading the movieclips, and put them on their place
            createEmptyMovieClip (AnDo["instance"+i], i)
            loadMovie(AnDo["link"+i], AnDo["instance"+i]);
            setProperty (AnDo["instance"+i], _x, Ando["xpos"+i]);
            setProperty (AnDo["instance"+i], _y, Ando["ypos"+i]);
// this part shopuld make the loaded movieclip draggable, but this won't work
            AnDo["instance"+i].onPress = function () {
                AnDo["instance"+i]._x = mouse_x;
                AnDo["instance"+i]._y = mouse_y;
            }
            trace (AnDo["instance"+i]);
        }
    }else{
        trace("communicatie niet succesvol");
    }
}

Please note that for some reason i have to use the setproperty command to put the movieclips on place. When i change the setproperty method to


AnDo["instance"+i].[COLOR=#000084]_x[/COLOR] = Ando["xpose"+i];

it should de exactly the same, but in my case this won’t work anymore.

I’m right now only testing this script in a empty movieclip. Could anybody tell my what’s wrong here?

What dont you just use the drag function? Example:

something.onPress = function(){
   startDrag();
}
something.onRelease = function(){
   stopDrag();
}

hi!

Thanks fir your time.
Using the startdrag was the first thing i tried. But it didn’t work so i started to look for other ways to get this working. But without succes.

Is there something wrong in the way i am using the variable instancename for the mc’s?

Try this:

AnDo = new LoadVars()
AnDo.load("http://www.maartenlierop.nl/janv/janv.php") 
AnDo.onLoad = function(succes){
    if(succes){
        trace("communicatie succesvol");
        for(var i=0; i<this.cant; i++){
// loading the movieclips, and put them on their place
            var dragclip:MovieClip = createEmptyMovieClip (AnDo["instance"+i], i)
            loadMovie(AnDo["link"+i], AnDo["instance"+i]);
            setProperty (AnDo["instance"+i], _x, Ando["xpos"+i]);
            setProperty (AnDo["instance"+i], _y, Ando["ypos"+i]);
// this part shopuld make the loaded movieclip draggable, but this won't work
            dragclip.onPress = function () {
                this.startDrag();
            }
            trace (dragclip);
        }
    }else{
        trace("communicatie niet succesvol");
    }
}

Hi,

the result is :
communicatie succesvol
undefined
undefined

and the movieclips are not draggable

this ‘undefined’ wories me somehow

What did it trace before? and why does the name of the object have to be the value of that array item?

AnDo = new LoadVars()
AnDo.load("http://www.maartenlierop.nl/janv/janv.php") 
AnDo.onLoad = function(succes){
    if(succes){
        trace("communicatie succesvol");
        for(var i=0; i<this.cant; i++){
// loading the movieclips, and put them on their place
            var dragclip:MovieClip = createEmptyMovieClip ("dragger"+i, i)
            var link:String = eval(AnDo["link"+i])
            dragclip.loadMovie(link);
            dragclip._x = Ando["xpos"+i];
            dragclip._y = Ando["ypos"+i];
// this part shopuld make the loaded movieclip draggable, but this won't work
            dragclip.onPress = function () {
                this.startDrag();
            }
            trace (dragclip);
        }
    }else{
        trace("communicatie niet succesvol");
    }
}

My previous trace actions did show “undefined”, that’s why i think something is wrong with the names, but i don’t know what.

When i change the trace-action as below


            trace ("dragclip : " + dragclip);
            trace ("name : " + AnDo[instance]);

the result becomes

communicatie succesvol
dragclip :
name : anekdote03
dragclip :
name : anekdote04

dragclip is empty, and anekdotexx is the name, but i also have a varible wich has this name in it, and whan i use this variable, i wouldn’t need the i anymore:


AnDo = new LoadVars()
AnDo.load("http://www.maartenlierop.nl/janv/janv.php")
AnDo.onLoad = function(succes){
    if(succes){
        trace("communicatie succesvol");
        for(var i=0; i<this.cant; i++){
// loading the movieclips, and put them on their place
            var dragclip:MovieClip = createEmptyMovieClip (AnDo[instance], i)
            loadMovie(AnDo["link"+i], AnDo[instance]);
            setProperty (AnDo[instance], _x, Ando["xpos"+i]);
            setProperty (AnDo[instance], _y, Ando["ypos"+i]);
// this part shopuld make the loaded movieclip draggable, but this won't work
            dragclip.onPress = function () {
                this.startDrag();
            }
            trace ("dragclip : " + dragclip);
            trace ("name : " + AnDo[instance]);
        }
    }else{
        trace("communicatie niet succesvol");
    }
}

with this script the movies are again not draggalbe, and i only see one of them (I’ve got two movies in the database now)

did you copy and paste my above code?

yes i did, the movieclips did not show up at all
output was:

communicatie succesvol
undefined
undefined

try traceing it more specifically to see where it looses it’s value:

AnDo = new LoadVars()
AnDo.load("http://www.maartenlierop.nl/janv/janv.php") 
AnDo.onLoad = function(succes){
    if(succes){
        trace("communicatie succesvol");
        for(var i=0; i<this.cant; i++){
// loading the movieclips, and put them on their place
            var dragclip:MovieClip = createEmptyMovieClip ("dragger"+i, i)
            trace (dragclip+" has been created")
            var link:String = eval(AnDo["link"+i])
            trace ("Link: "+link)
            dragclip.loadMovie(link);
            trace (dragclip)
            dragclip._x = AnDo["xpos"+i];
            trace (dragclip._x)
            dragclip._y = AnDo["ypos"+i];
            trace (dragclip._y)
// this part shopuld make the loaded movieclip draggable, but this won't work
            dragclip.onPress = function () {
                trace ("you clicked")
                this.startDrag();
            }
            trace (dragclip);
        }
    }else{
        trace("communicatie niet succesvol");
    }
}

You need to make sure the movies are loaded before using function

dragclip.onPress = function () {
                this.startDrag();
            }

ouptu for your script is:
communicatie succesvol
has been created
Link:
undefined
undefined
undefined
undefined
has been created
Link:
undefined
undefined
undefined
undefined

I tried to implement the trace actions also to your first script because in that script the mc’s did show up


AnDo = new LoadVars()
AnDo.load("http://www.maartenlierop.nl/janv/janv.php")
AnDo.onLoad = function(succes){
    if(succes){
        trace("communicatie succesvol");
        for(var i=0; i<this.cant; i++){
// loading the movieclips, and put them on their place
            var dragclip:MovieClip = createEmptyMovieClip (AnDo["instance"+i], i)
              trace (dragclip+" has been created")
            loadMovie(AnDo["link"+i], AnDo["instance"+i]);
              trace ("Link: "+link)
              trace (dragclip)
            setProperty (AnDo["instance"+i], _x, Ando["xpos"+i]);
            setProperty (AnDo["instance"+i], _y, Ando["ypos"+i]);
              trace (dragclip);
            dragclip.onPress = function () {
                this.startDrag();
                trace ("you clicked")
            }
              trace (dragclip);
        }
    }else{
        trace("communicatie niet succesvol");
    }
}

the output is here not much more hopegiving:
communicatie succesvol
has been created
Link:
undefined
undefined
undefined
has been created
Link:
undefined
undefined
undefined

AnDo = new LoadVars();
AnDo.load("http://www.maartenlierop.nl/janv/janv.php");
AnDo.onLoad = function(succes) {
	if (succes) {
		trace("communicatie succesvol");
		for (var i = 0; i<this.cant; i++) {
			// loading the movieclips, and put them on their place
			var dragclip:MovieClip = _root.createEmptyMovieClip("dragger"+i, i);
			dragclip.loadMovie(this["link"+i]);
			checkload(dragclip);
			dragclip._x = Ando["xpos"+i];
			dragclip._y = Ando["ypos"+i];
			// this part shopuld make the loaded movieclip draggable, but this won't work
			trace(dragclip);
		}
	} else {
		trace("communicatie niet succesvol");
	}
};
var i = 1000;
function checkload(clip) {
	var clap = this.createEmptyMovieClip("checker"+i, i);
	clap.onEnterFrame = function() {
		if (clip._width) {
			clip.onPress = function() {
				this.startDrag();
			};
			this.removeMovieClip();
		}
	};
	i++;
}

thanx Stringy, didn’t think we’d have to break out a function :slight_smile:

For Stringy:

I think it goes wrong far before the startdrag command is assigned.
I tried to place the startdrag inside an onload together with a trace “movie loaded.” But although the movies showed up on screen, the trace Movies loaded never showed up.

oke, i think i understand what you did (but this is starting to look far more complicated).
But still; in my window i do not see the mc’s
do they show up on your screens?

hmm seems to work ok for me-maybe i am missing something
This just uses code by Defective + my checkload thingy
http://www.fmx6.com/teststuff/flash1.zip

:pa: Wich version are you using?

I have Flash MX 2004 prof. and i cannot open your fla file

flash 8
here in mx2004
http://www.fmx6.com/teststuff/flash.rar

Thank you guys! it works!:thumb:
I spent four days changing this code again and again, but it finaly works!
I need it for my final project on art school, When i’ve finished my project i will show it to you (takes a couple of weeks)

Thanks very much for your time!