How to copy the script from a ".as" file into the main timeline of flash?
i have a program made in flash who runs well, the actions on the .fla file are empty, it has a class who makes all the the work:
This is the content of the class:
package {
import flash.events.Event;
import org.papervision3d.objects.parsers.DAE;
[SWF(width=640, height=480, backgroundColor=0xCCCCCC, frameRate=30)]
public class Earth extends PV3DARApp {
private var _earth:DAE;
public function Earth() {
addEventListener(Event.INIT, _onInit);
init('Data/camera_para.dat', 'Data/flarlogo.pat');
}
private function _onInit(e:Event):void {
_earth = new DAE();
_earth.load('model/minecraft.DAE');
//_earth.addEventListener(Event.OPEN,imageLoaded);
_earth.scale = 1.5;
_earth.rotationX = 90;
_markerNode.addChild(_earth);
//addEventLis开发者_开发知识库tener(Event.ENTER_FRAME, _update);
}
private function imageLoaded(e:Event):void { trace("HOLA"); }
private function _update(e:Event):void {
_earth.rotationZ -= 1
}
}
}
I want to pass all the script from the class to the acctions on the main timeline, i mean, i dont want to use the class, but i have no idea how to do this, eliminating the "private" string in all the functions and eliminating some other logical thinks like "package {" and others is not enough.
So please, how can i code the same program using only the actions tab from flash? Thanks!
I don't think this is a good idea. I (and most other AS3 developers) think all timeline code should be destroyed, but it should go something like this:
import flash.events.Event;
import org.papervision3d.objects.parsers.DAE;
var _earth:DAE;
function _onInit(e:Event):void {
_earth = new DAE();
_earth.load('model/minecraft.DAE');
//_earth.addEventListener(Event.OPEN,imageLoaded);
_earth.scale = 1.5;
_earth.rotationX = 90;
_markerNode.addChild(_earth);
//addEventListener(Event.ENTER_FRAME, _update);
}
function imageLoaded(e:Event):void { trace("HOLA"); }
function _update(e:Event):void {
_earth.rotationZ -= 1;
}
addEventListener(Event.INIT, _onInit);
init('Data/camera_para.dat', 'Data/flarlogo.pat');
There is no reason to not just use the document class. I would suggest learning how classes work. There are a bunch of great resources out there including:
- Kirupa.com - Classes in ActionScript3
- gotoandlearn
I have to agree with the idea that using timeline code is a bad idea.
Now, going to your code, it's hard to know for sure without knowing what the parent class does.
I'm assuming that your are using the FLARToolKit example code. I would do as @Adam Harte shows you in his answer, plus modify the PV3DARApp class so that you accommodate things a bit.
Since the whole idea is a bad one in my book, I won't bother to make things in a proper way, just suggest quick changes.
In PV3DARApp, make _markerNode public:
//protected var _markerNode:FLARBaseNode;
public var _markerNode:FLARBaseNode;
In PV3DARApp and ARAppBase, change the method init from protected to public:
public function init(cameraFile:String, codeFile:String, canvasWidth:int = 320, canvasHeight:int = 240, codeWidth:int = 80):void {
Then, it should go something like this:
import flash.events.Event;
import org.papervision3d.objects.parsers.DAE;
var _earth:DAE;
var _holder:PV3DARApp = new PV3DARApp;
function _onInit(e:Event):void {
_earth = new DAE();
_earth.load('model/minecraft.DAE');
//_earth.addEventListener(Event.OPEN,imageLoaded);
_earth.scale = 1.5;
_earth.rotationX = 90;
_holder. init('Data/camera_para.dat', 'Data/flarlogo.pat');
//_markerNode.addChild(_earth);
_holder._markerNode.addChild(_earth);
//addEventListener(Event.ENTER_FRAME, _update);
}
function imageLoaded(e:Event):void { trace("HOLA"); }
function _update(e:Event):void {
_earth.rotationZ -= 1;
}
addEventListener(Event.INIT, _onInit);
init('Data/camera_para.dat', 'Data/flarlogo.pat');
精彩评论