简体   繁体   English

如何在Haxe / HTML5中的数组中动态存储动画片段?

[英]How do I store dynamically a movieclip in a array in Haxe/HTML5?

This is my code: 这是我的代码:

var buttons:Array<Dynamic> = new Array<Dynamic>();
var mc2:flash.display.MovieClip = new MovieClip();
mc2.graphics.beginFill(0xFF0000);
mc2.graphics.moveTo(50,50);
mc2.graphics.lineTo(100,50);
mc2.graphics.lineTo(100,100);
mc2.graphics.lineTo(50,100);
mc2.graphics.endFill();

buttons.push(addChild(mc2));

buttons[0].x = 1000;

And my question is why this work in Flash but not work in HTML5 when I compile it? 我的问题是,为什么在编译时在Flash中起作用但在HTML5中不起作用? How do I solve the problem? 我该如何解决这个问题? The last line “buttons[0].x = 1000;” is not working in HTML5… :/ 最后一行“ buttons [0] .x = 1000;”在HTML5中不起作用…:/

Sorry for my english... 对不起我的英语不好...

Because you use in "flash.display.MovieClip" class that does not available from HTML5. 因为您在HTML5中无法使用的“ flash.display.MovieClip”类中使用。

In Haxe, if you use in class that belongs to specific target (like MovieClip) you can compile it only to that target. 在Haxe中,如果您在属于特定目标(例如MovieClip)的类中使用,则只能将其编译为该目标。 Maybe you will found OpenFl library useful, It's library that let you develop with Flash API and target to almost any device(and also for HTML5) from same base code! 也许您会发现OpenFl库很有用,该库使您可以使用Flash API进行开发,并以相同的基本代码定位到几乎所有设备(也适用于HTML5)!

see Here for more 看到这里更多

Are you using a framework? 您正在使用框架吗? Maybe it works if you split the addChild and the push into separate lines? 如果将addChildpush分成单独的行,也许可以正常工作? Not sure if addChild returns a MovieClip? 不确定addChild返回MovieClip?

Otherwise, try to trace the array trace(buttons) and observe the browser console. 否则,尝试跟踪数组trace(buttons)并观察浏览器控制台。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM