错误#1006:值不是函数

发布于 2024-09-25 20:25:44 字数 1263 浏览 5 评论 0原文

//创建URLLOader实例 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();

            }

这给了我错误 Error #1006: value is not a function。当我点击拖动时

//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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

海螺姑娘 2024-10-02 20:25:44

您的代码中有很多错误。您还试图用一种方法做太多事情。您解析数据,创建影片剪辑,添加加载器,加载图像,然后调用加载器上的函数...我试图消除明显的错误,但毫无疑问,您的代码可以通过分离来改进的担忧。

如果您将代码拆分为单独的方法,您的代码将更加灵活&调试起来也容易得多...你可以加载&解析变量,在另一个函数中为设计准备 XML 数据,然后将显示逻辑留给另一个方法。

与此同时,这是错误较少的代码

    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();

    }  

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();

    }  
攀登最高峰 2024-10-02 20:25:44

您发布的代码似乎有语法错误,但我认为您的问题的解决方案应该是调用 e.target.startDrag();。通过调用 my_thumb.startDrag();,您尝试在 e.target.name 上调用不存在的函数 startDrag

或者你可以替换

var my_thumb = e.target.name;

var my_thumb = e.target;

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;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文