将 Actionscript 2 代码转换为 Actionscript 3

发布于 2024-10-17 07:43:46 字数 2691 浏览 2 评论 0原文

最近我遵循并在 AS2 中制作了 3d 轮播,但我希望使用它并在 AS3 中制作它。有没有可能的方法来转换代码,以便轮播可以在 AS3 中工作?

下面是 AS2 轮播的代码:

import mx.utils.Delegate;

var numOfItems:Number;
var radiusX:Number = 300;
var radiusY:Number = 75;
var centerX:Number = Stage.width / 2;
var centerY:Number = Stage.height / 2;
var speed:Number = 0.05;
var perspective:Number = 130;
var home:MovieClip = this;

var tooltip:MovieClip = this.attachMovie("tooltip","tooltip",10000);
tooltip._alpha = 0;

var xml:XML = new XML();
xml.ignoreWhite = true;

xml.onLoad = function()
{
   var nodes = this.firstChild.childNodes;
   numOfItems = nodes.length;
   for(var i=0;i<numOfItems;i++)
   {
      var t = home.attachMovie("item","item"+i,i+1);
      t.angle = i * ((Math.PI*2)/numOfItems);
      t.onEnterFrame = mover;
      t.toolText = nodes[i].attributes.tooltip;
      t.icon.inner.loadMovie(nodes[i].attributes.image);
      t.r.inner.loadMovie(nodes[i].attributes.image);
      t.icon.onRollOver = over;
      t.icon.onRollOut = out;
      t.icon.onRelease = released;
   }
}

function over()
{
   home.tooltip.tipText.text = this._parent.toolText;
   home.tooltip._x = this._parent._x;
   home.tooltip._y = this._parent._y - this._parent._height/2;
   home.tooltip.onEnterFrame = Delegate.create(this,moveTip);
   home.tooltip._alpha = 100;
}

function out()
{
   delete home.tooltip.onEnterFrame;
   home.tooltip._alpha = 0;
}

function released()
{
   trace(this._parent.toolText);
}

function moveTip()
{
   home.tooltip._x = this._parent._x;
   home.tooltip._y = this._parent._y - this._parent._height/2;
}

xml.load("icons.xml");

function mover()
{
   this._x = Math.cos(this.angle) * radiusX + centerX;
   this._y = Math.sin(this.angle) * radiusY + centerY;
   var s = (this._y - perspective) /(centerY+radiusY-perspective);
   this._xscale = this._yscale = s*100;
   this.angle += this._parent.speed;
   this.swapDepths(Math.round(this._xscale) + 100);
}

this.onMouseMove = function()
{
   speed = (this._xmouse-centerX)/2500;
}

当我在 AS3 中添加此代码时,出现以下错误:

场景 1,层“层 1”,帧 1,第 1 行 1172:定义 mx.utils:找不到代表。 场景 1,层“第 1 层”,第 1 帧,第 1 行 1172:定义 mx.utils:找不到代表。 场景 1,层“层 1”,帧 1,第 41 行 1120:访问未定义的属性委托。 场景 1,层“层 1”,帧 1,第 6 行 1119:通过静态类型 Class 的引用访问可能未定义的属性宽度。 场景 1,层“层 1”,帧 1,第 7 行 1119:通过静态类型 Class 的引用访问可能未定义的属性高度。

我对 AS2 和 AS3 很陌生,但经过一些研究,我了解到 AS3 中不再需要 import mx.utils.Delegate; 因为它已经有委托,并且它们已经内置在代码,所以我删除了第 1 行和第 41 行的委托,并收到两个错误:

场景 1,层“层 1”,第 1 帧,第 6 行 1119:通过静态类型 Class 的引用访问可能未定义的属性宽度。 场景 1,层“层 1”,帧 1,第 7 行 1119:通过静态类型 Class 的引用访问可能未定义的属性高度。

现在我不知道该怎么做,有人可以帮我将此代码从 AS2 转换为 AS3 吗?

Recently I followed and made the 3d carousel in AS2, but I'm looking to use it and make it in AS3. Is there any possible way of converting the code so the carousel can work in AS3?

Below is the code for the AS2 carousel:

import mx.utils.Delegate;

var numOfItems:Number;
var radiusX:Number = 300;
var radiusY:Number = 75;
var centerX:Number = Stage.width / 2;
var centerY:Number = Stage.height / 2;
var speed:Number = 0.05;
var perspective:Number = 130;
var home:MovieClip = this;

var tooltip:MovieClip = this.attachMovie("tooltip","tooltip",10000);
tooltip._alpha = 0;

var xml:XML = new XML();
xml.ignoreWhite = true;

xml.onLoad = function()
{
   var nodes = this.firstChild.childNodes;
   numOfItems = nodes.length;
   for(var i=0;i<numOfItems;i++)
   {
      var t = home.attachMovie("item","item"+i,i+1);
      t.angle = i * ((Math.PI*2)/numOfItems);
      t.onEnterFrame = mover;
      t.toolText = nodes[i].attributes.tooltip;
      t.icon.inner.loadMovie(nodes[i].attributes.image);
      t.r.inner.loadMovie(nodes[i].attributes.image);
      t.icon.onRollOver = over;
      t.icon.onRollOut = out;
      t.icon.onRelease = released;
   }
}

function over()
{
   home.tooltip.tipText.text = this._parent.toolText;
   home.tooltip._x = this._parent._x;
   home.tooltip._y = this._parent._y - this._parent._height/2;
   home.tooltip.onEnterFrame = Delegate.create(this,moveTip);
   home.tooltip._alpha = 100;
}

function out()
{
   delete home.tooltip.onEnterFrame;
   home.tooltip._alpha = 0;
}

function released()
{
   trace(this._parent.toolText);
}

function moveTip()
{
   home.tooltip._x = this._parent._x;
   home.tooltip._y = this._parent._y - this._parent._height/2;
}

xml.load("icons.xml");

function mover()
{
   this._x = Math.cos(this.angle) * radiusX + centerX;
   this._y = Math.sin(this.angle) * radiusY + centerY;
   var s = (this._y - perspective) /(centerY+radiusY-perspective);
   this._xscale = this._yscale = s*100;
   this.angle += this._parent.speed;
   this.swapDepths(Math.round(this._xscale) + 100);
}

this.onMouseMove = function()
{
   speed = (this._xmouse-centerX)/2500;
}

When I add this code in AS3 I get the following error:

Scene 1, Layer 'Layer 1', Frame 1, Line 1 1172: Definition mx.utils:Delegate could not be found.
Scene 1, Layer 'Layer 1', Frame 1, Line 1 1172: Definition mx.utils:Delegate could not be found.
Scene 1, Layer 'Layer 1', Frame 1, Line 41 1120: Access of undefined property Delegate.
Scene 1, Layer 'Layer 1', Frame 1, Line 6 1119: Access of possibly undefined property width through a reference with static type Class.
Scene 1, Layer 'Layer 1', Frame 1, Line 7 1119: Access of possibly undefined property height through a reference with static type Class.

I'm quite new to AS2 and AS3 but after some research I understand that import mx.utils.Delegate; is no longer need in AS3 as it already has delegate and they are already built in so in the code so I delete the delegate which are line 1 and line 41 and got two errors:

Scene 1, Layer 'Layer 1', Frame 1, Line 6 1119: Access of possibly undefined property width through a reference with static type Class.
Scene 1, Layer 'Layer 1', Frame 1, Line 7 1119: Access of possibly undefined property height through a reference with static type Class.

Now I cant figure out what to do so can someone help me convert this code from AS2 to AS3?

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

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

发布评论

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

评论(1

咋地 2024-10-24 07:43:46

这里有很多事情需要解决:

您的鼠标事件需要更改为 as3 调用
t.icon.onRollOver = over,在as3中看起来更像t.icon.addEventListener(MouseEvent.ROLL_OVER, over);

attachMovie 不是在as3中使用时间更长。
您需要使用唯一的类名导出为动作脚本想要从库中获取的电影,然后使用new someName();来创建它。然后必须用addChild添加到显示列表中

onEnterFrame在as3中没有使用,你需要创建一个enterframe事件更像这样:**addEventListener(Event.ENTER_FRAME , 一些函数);

as3 中不使用委托

_x、_y、_parent、_alpha 等上的标志已在 as3 中删除。只需使用x,y,parent,alpha等即可。

swapDepths已从as3中删除,您需要使用显示列表来添加/删除/交换级别。

听起来你可能需要先研究一下 as3,然后才能正确解决这个问题!尝试查看此链接以比较 as2 和 as3 功能。

http://www.actionscriptcheatsheet.com/downloads/as3cs_migration.pdf

You have quite a few things to address here:

Your mouse events need to be changed to as3 calls
t.icon.onRollOver = over, in as3 looks more like t.icon.addEventListener(MouseEvent.ROLL_OVER, over);

attachMovie is no longer used in as3.
you need to export for actionscript the movie you want to get from the library with a unique class name, then use new someName(); to create it. Then it must be added to the display list with addChild

onEnterFrame is not used in as3, you need to create an enterframe event more like this: **addEventListener(Event.ENTER_FRAME, someFunction);

delegate is not used in as3.

flags on _x, _y, _parent, _alpha etc have been removed in as3. just use x,y, parent, alpha etc.

swapDepths has been removed from as3, You need to use the display list to add/remove/swap levels.

sounds like you might need to study up a little on as3 before you can properly tackle this one! try checking out this link for comparisons between as2 and as3 functionality.

http://www.actionscriptcheatsheet.com/downloads/as3cs_migration.pdf

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