【问题标题】:How to get .x and .y from random movie clip?如何从随机影片剪辑中获取 .x 和 .y?
【发布时间】:2014-12-19 04:11:17
【问题描述】:

例如,我在场景中有 "b1"-"b24" mc 实例,以及“cross”影片剪辑。 所以,我想实现这样的目标:

cross.x="b"+Math.ceil(1+Math.random()*23).x;
cross.y="b"+Math.ceil(1+Math.random()*23).y;

这是错误的,因为它是“数字”,如果我尝试的话

aaa="b"+Math.ceil(1+Math.random()*23);
cross.x=Object(aaa).x;

它也失败了,

在 String 上找不到属性 x,并且没有默认值。

顺便说一句。 round,而不是 ceil

数学.round

【问题讨论】:

    标签: actionscript-3 random actionscript movieclip


    【解决方案1】:

    你可以这样写

    cross.x = this["b" + Math.ceil(1 + Math.random() * 23)].x;
    cross.y = this["b" + Math.ceil(1 + Math.random() * 23)].y;
    

    【讨论】:

    • 我会在 1 分钟内 %)
    • 但是也提示了一些奇怪的滞后,“A term is undefined and has no properties”?这是什么?
    • 你能告诉我案例吗?
    • 我不明白,显然如果缺少元素会导致此错误,并且它还提示我不知道为什么在元素上。只需删除它们并放置另一个时间,它就可以完美运行。我猜只是奇怪的错误。
    猜你喜欢
    • 2017-08-23
    • 2012-05-01
    • 2015-07-07
    • 2016-07-02
    • 1970-01-01
    • 2010-12-01
    • 2013-08-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多