热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

mc内的按钮影响代码-buttonsinsidemcaffectingthecode

IhaveamovieClipwithtwobuttonsinside.我有一个带有两个按钮的movieClip。Theproblemisthatwhenthemous

I have a movieClip with two buttons inside.

我有一个带有两个按钮的movieClip。

The problem is that when the mouse is over these two buttons, the code that manages the movieClip stops working, as if the mouse is not over the MC (the buttons are children of the MC, shouldn't it work regardless?).

问题是,当鼠标悬停在这两个按钮上时,管理movieClip的代码将停止工作,就像鼠标不在MC上一样(按钮是MC的子代,不管它不管怎么办?)。

Could you please share some advice? Thanks

你能分享一些建议吗?谢谢

/*mc follows mouse. I can't click btns because when mouse rollover  btns the mc moves*/
function showImgOptions (e:Event):void{
    if (mc.hitTestPoint(mouseX,mouseY,false)){
        mc.y = mc.y;
        mc.x = mc.x;
    }else{
        var delayX:int = mc.x - mouseX;
        var delayY:int = mc.y - mouseY;
        mc.x -= delayX / 6;
        mc.y -= delayY/6;
    }
}
mc.btn1.addEventListener (MouseEvent.CLICK, closeClick);
mc.btn2.addEventListener (MouseEvent.CLICK, zoomClick);
function closeClick (e:MouseEvent):void{}
function zoomClick (e:MouseEvent):void{}
stage.addEventListener (Event.ENTER_FRAME, showImgOptions);
addChild (mc);

Changed the code to:

将代码更改为:

var mc:menuMC = new menuMC();

addChild(mc);

var p:Point = mc.localToGlobal(new Point(mc.mouseX,mc.mouseY));

/*mc follows mouse. I can't click btns because when mouse rollover  btns the mc moves*/
function showImgOptions (e:Event):void
{

    if (! mc.hitTestPoint(p.x,p.y,false))
    {
        mc.y = mc.y;
        mc.x = mc.x;
    }else{
        //move mc towards mc.parent's mouseX and mouseY
        var delayX:int = mc.x - mouseX;
        var delayY:int = mc.y - mouseY;
        mc.x -= delayX / 6;
        mc.y-=delayY/6;
    }
}

mc.btn1.addEventListener (MouseEvent.CLICK, closeClick);
mc.btn2.addEventListener (MouseEvent.CLICK, zoomClick);
function closeClick (e:MouseEvent):void
{
}
function zoomClick (e:MouseEvent):void
{
}
stage.addEventListener (Event.ENTER_FRAME, showImgOptions);

And now I get this error:

现在我收到这个错误:

TypeError: Error #1010: A term is undefined and has no properties.

Here you can download an FLA. Test it and try to click on the buttons 1 and 2, inside the MC following the mouse

在这里,您可以下载FLA。测试它并尝试单击鼠标内MC后面的按钮1和2

2 个解决方案

#1


0  

hitTestPoint expects stage coordinates:

hitTestPoint需要阶段坐标:

The x and y parameters specify a point in the coordinate space of the Stage, not the display object container that contains the display object (unless that display object container is the Stage).

x和y参数指定舞台坐标空间中的一个点,而不是包含显示对象的显示对象容器(除非该显示对象容器是舞台)。

Use localToGlobal to get the stage coordinates:

使用localToGlobal获取舞台坐标:

var p:Point = mc.localToGlobal(new Point(mc.mouseX, mc.mouseY));
if(!mc.hitTestPoint(p.x, p.y,false))
{
  //move mc towards mc.parent's mouseX and mouseY
}

#2


0  

Solved it!!

Changed the code. I don't know if this helps anybody, but I hope so. Thanks to you all.

更改了代码。我不知道这对任何人都有帮助,但我希望如此。谢谢大家。

stage.addEventListener(Event.ENTER_FRAME, moveMC);

var mc:menuMC = new menuMC();

addChild(mc);

function moveMC(e:Event):void {
 if (mc.hitTestObject(big_mc)) {
  mc.visible = true;
 } else {
  mc.visible = false;
 }
 if (mc.hitTestPoint(mouseX,mouseY,false)) {
  mc.y = mc.y;
  mc.x = mc.x;
 } else {
  var delayX:int = mc.x - mouseX;
  var delayY:int = mc.y - mouseY;
  mc.x -= delayX / 6;
  mc.y-=delayY/6;
 }
}


mc.btn1.addEventListener(MouseEvent.CLICK, onBtn1);
mc.btn2.addEventListener(MouseEvent.CLICK, onBtn2);


function onBtn1(e:MouseEvent):void {
 trace("do something");
}
function onBtn2(e:MouseEvent):void {
 trace("do something else");
}

推荐阅读
  • Linux重启网络命令实例及关机和重启示例教程
    本文介绍了Linux系统中重启网络命令的实例,以及使用不同方式关机和重启系统的示例教程。包括使用图形界面和控制台访问系统的方法,以及使用shutdown命令进行系统关机和重启的句法和用法。 ... [详细]
  • 移动传感器扫描覆盖摘要:关于传感器网络中的地址覆盖问题,已经做过很多尝试。他们通常归为两类,全覆盖和栅栏覆盖,统称为静态覆盖 ... [详细]
  • 微软头条实习生分享深度学习自学指南
    本文介绍了一位微软头条实习生自学深度学习的经验分享,包括学习资源推荐、重要基础知识的学习要点等。作者强调了学好Python和数学基础的重要性,并提供了一些建议。 ... [详细]
  • 生成式对抗网络模型综述摘要生成式对抗网络模型(GAN)是基于深度学习的一种强大的生成模型,可以应用于计算机视觉、自然语言处理、半监督学习等重要领域。生成式对抗网络 ... [详细]
  • Iamtryingtomakeaclassthatwillreadatextfileofnamesintoanarray,thenreturnthatarra ... [详细]
  • 在Android开发中,使用Picasso库可以实现对网络图片的等比例缩放。本文介绍了使用Picasso库进行图片缩放的方法,并提供了具体的代码实现。通过获取图片的宽高,计算目标宽度和高度,并创建新图实现等比例缩放。 ... [详细]
  • 向QTextEdit拖放文件的方法及实现步骤
    本文介绍了在使用QTextEdit时如何实现拖放文件的功能,包括相关的方法和实现步骤。通过重写dragEnterEvent和dropEvent函数,并结合QMimeData和QUrl等类,可以轻松实现向QTextEdit拖放文件的功能。详细的代码实现和说明可以参考本文提供的示例代码。 ... [详细]
  • 本文讨论了在Windows 8上安装gvim中插件时出现的错误加载问题。作者将EasyMotion插件放在了正确的位置,但加载时却出现了错误。作者提供了下载链接和之前放置插件的位置,并列出了出现的错误信息。 ... [详细]
  • CSS3选择器的使用方法详解,提高Web开发效率和精准度
    本文详细介绍了CSS3新增的选择器方法,包括属性选择器的使用。通过CSS3选择器,可以提高Web开发的效率和精准度,使得查找元素更加方便和快捷。同时,本文还对属性选择器的各种用法进行了详细解释,并给出了相应的代码示例。通过学习本文,读者可以更好地掌握CSS3选择器的使用方法,提升自己的Web开发能力。 ... [详细]
  • android listview OnItemClickListener失效原因
    最近在做listview时发现OnItemClickListener失效的问题,经过查找发现是因为button的原因。不仅listitem中存在button会影响OnItemClickListener事件的失效,还会导致单击后listview每个item的背景改变,使得item中的所有有关焦点的事件都失效。本文给出了一个范例来说明这种情况,并提供了解决方法。 ... [详细]
  • Python正则表达式学习记录及常用方法
    本文记录了学习Python正则表达式的过程,介绍了re模块的常用方法re.search,并解释了rawstring的作用。正则表达式是一种方便检查字符串匹配模式的工具,通过本文的学习可以掌握Python中使用正则表达式的基本方法。 ... [详细]
  • JDK源码学习之HashTable(附带面试题)的学习笔记
    本文介绍了JDK源码学习之HashTable(附带面试题)的学习笔记,包括HashTable的定义、数据类型、与HashMap的关系和区别。文章提供了干货,并附带了其他相关主题的学习笔记。 ... [详细]
  • Python中的PyInputPlus模块原文:https ... [详细]
  • Apple iPad:过渡设备还是平板电脑?
    I’vebeenagonizingoverwhethertopostaniPadarticle.Applecertainlydon’tneedmorepublicityandthe ... [详细]
  • 开发笔记:加密&json&StringIO模块&BytesIO模块
    篇首语:本文由编程笔记#小编为大家整理,主要介绍了加密&json&StringIO模块&BytesIO模块相关的知识,希望对你有一定的参考价值。一、加密加密 ... [详细]
author-avatar
淘气111006
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有