0

//Create the URLLOader instance var myLoader:URLLoader = new URLLoader();

//the data will come as URL-encoded variables
myLoader.dataFormat = URLLoaderDataFormat.VARIABLES

//Load using an URLRequest, even beeing local
myLoader.load(new URLRequest("flash/index.php"))

//onLoad handler listener
myLoader.addEventListener(Event.COMPLETE, onDataLoad)

//add a listener for the complete event
function onDataLoad(evt:Event){
    for(var i:uint=0; i<evt.target.data.cant; i++){
            var mc_holder:MovieClip = new MovieClip();
                mc_holder.name = "mc_holder"+i;
                mc_holder.x = 30;
                mc_holder.y = mc_holder.height+10;
                //trace(mc_holder.y = mc_holder.height*i)
                addChild(mc_holder);
        var loader:Loader = new Loader()

        loader.load(new URLRequest(evt.target.data["Image"+i]))
           mc_holder.addChild(loader)
        mc_holder.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);

        function mouseDownHandler(e:MouseEvent):void {
            var my_thumb = e.target.name;
            trace(my_thumb);
            my_thumb.startDrag();

            }

This gives me error Error #1006: value is not a function. when i click on drag

2 Answers 2

0

There are a lot of errors in your code. You're also trying to do too much with one single method. You parse your data, create a movie clip , add a loader , load an image then call a function on the loader... I've tried to get rid of the obvious mistakes , but there's no doubt your code could be improved by separating concerns.

If you split your code into separate methods, your code will be more flexible & much easier to debug too... You could load & parse your variables , in another function prepare your XML data for your designs , then leave the display logic to another method.

In the meantime, here's your code with less mistakes

    function onDataLoad(evt:Event)
    {

        for(var i:uint=0; i< evt.target.data.cant; i++)
        {
            var mc_holder:MovieClip = new MovieClip();
            mc_holder.name = "mc_holder"+i;
            mc_holder.x = 30;
            mc_holder.y = mc_holder.height+10;

             //trace(mc_holder.y = mc_holder.height*i);
            addChild(mc_holder);

            var loader:Loader = new Loader();

            loader.load(new URLRequest(evt.target.data["Image"+i]));

            mc_holder.addChild(loader)
            mc_holder.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);

        }
    }

    function mouseDownHandler(e:MouseEvent):void 
    {
        var my_thumb:MovieClip = e.target as MovieClip;
        trace(my_thumb);
        my_thumb.startDrag();

    }  
0

You posted code seems to have syntactical errors, but I think the solution for your problem should be the call of e.target.startDrag();. With your call of my_thumb.startDrag(); you are trying to call a function startDrag on e.target.name which doesn't exists.

Alternativly you can replace

var my_thumb = e.target.name;

with

var my_thumb = e.target;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.