我真的迷失在这里。 我已经检查了许多答案“如何在不在文档类的代码上添加某些东西”,但我找不到一个简单的答案。
好吧,我有两节课:
文件类,在FLA上声明:
package
{
import as3isolib.display.scene.IsoGrid;
import as3isolib.display.IsoView;
import as3isolib.display.primitive.IsoBox;
import as3isolib.display.scene.IsoScene;
import flash.display.Sprite;
import com.sb.*;
import com.sb.services.*;
import as3isolib.geom.Pt;
//[SWF(width='760', height='600', backgroundColor='#000000', frameRate='30')]
public class iso extends Sprite
{
private var grid:IsoGrid;
private var scene:IsoScene;
private var view:IsoView;
//Script de Execução do jogo, depois do preloader.
public function iso()
{
trace("It's Alive!");
var map = new Map();
map.IsoStarter();
trace("Ending Loader.");
}
}
}
和班级地图,我正在打电话:
package com.sb
{
import as3isolib.display.scene.IsoGrid;
import as3isolib.display.IsoView;
import as3isolib.display.primitive.IsoBox;
import as3isolib.display.scene.IsoScene;
import flash.display.MovieClip;
import com.sb.*;
import com.sb.services.*;
import as3isolib.geom.Pt;
public class Map extends MovieClip
{
private var grid:IsoGrid;
private var scene:IsoScene;
private var view:IsoView;
public function Map()
{
//Loading ISO
}
public function MakeMap()
{
}
public function EnableScrolling()
{
}
public function IsoStarter()
{
//Load ISO + Iso Configuration
var box:IsoBox = new IsoBox();
box.moveTo(15, 15, 0);
var grid = new IsoGrid();
grid.setGridSize(400, 400, 5);
grid.cellSize = 25;
grid.showOrigin = false;
var scene = new IsoScene();
scene.addChild(box);
scene.addChild(grid);
scene.render();
var view = new IsoView();
view.setSize(760, 600);
view.centerOnPt(new Pt(150,150,0));
view.addScene(scene);
super.addChild(view);
}
}
}
顺便说一句:这个很好用(文件类),但对我来说不够有条理:
package
{
import as3isolib.display.scene.IsoGrid;
import as3isolib.display.IsoView;
import as3isolib.display.primitive.IsoBox;
import as3isolib.display.scene.IsoScene;
import flash.display.Sprite;
import com.sb.*;
import com.sb.services.*;
import as3isolib.geom.Pt;
//[SWF(width='760', height='600', backgroundColor='#000000', frameRate='30')]
public class iso extends Sprite
{
private var grid:IsoGrid;
private var scene:IsoScene;
private var view:IsoView;
//Script de Execução do jogo, depois do preloader.
public function iso()
{
trace("It's Alive!");
IsoStarter();
trace("Ending Loader.");
}
/* *
* Iso não pode ser chamado de outra classe senão a Document Root
* Se for encontrado um jeito para fazer isso, transferir essas
* funções para outro script, afim de manter a ordem.
*/
public function IsoStarter()
{
//Load ISO + Iso Configuration
var box:IsoBox = new IsoBox();
box.moveTo(15, 15, 0);
var grid = new IsoGrid();
grid.setGridSize(400, 400, 5);
grid.cellSize = 25;
grid.showOrigin = false;
var scene = new IsoScene();
scene.addChild(box);
scene.addChild(grid);
scene.render();
var view = new IsoView();
view.setSize(760, 600);
view.centerOnPt(new Pt(150,150,0));
view.addScene(scene);
super.addChild(view);
}
}
}
感谢。
答案 0 :(得分:2)
在Map类中,super.addChild(view);
正在将您的视图添加到movieclip。尝试parent.addChild(view)
或stage.addChild(view)
。如果这些都不起作用,请尝试将对文档类的引用传递给Map:
更改文档类以将对自身的引用传递给Map:
public function iso()
{
trace("It's Alive!");
var map = new Map(this);
map.IsoStarter();
trace("Ending Loader.");
}
并更改Map类中的构造函数:
public class Map extends MovieClip
{
private var grid:IsoGrid;
private var scene:IsoScene;
private var view:IsoView;
private var parentRef:iso; // <-----------
public function Map(parentClass:iso) // <-----------
{
this.parentRef = parentClass;
//Loading ISO
}
public function MakeMap()
{
}
public function EnableScrolling()
{
}
public function IsoStarter()
{
//Load ISO + Iso Configuration
var box:IsoBox = new IsoBox();
box.moveTo(15, 15, 0);
var grid = new IsoGrid();
grid.setGridSize(400, 400, 5);
grid.cellSize = 25;
grid.showOrigin = false;
var scene = new IsoScene();
scene.addChild(box);
scene.addChild(grid);
scene.render();
var view = new IsoView();
view.setSize(760, 600);
view.centerOnPt(new Pt(150,150,0));
view.addScene(scene);
parentRef.addChild(view); // <-----------
}
}