The Enchanted Cave 2
Delve into a strange cave with a seemingly endless supply of treasure, strategically choos
4.39 / 5.00 38,635 ViewsGhostbusters B.I.P.
COMPLETE edition of the interactive "choose next panel" comic
4.09 / 5.00 15,161 ViewsWhile I was reading an AS3 book, there was an example of a dynamic class. I know other classes can create new vars for the dynamic class at runtime, but somehow it doesn't need to be imported in order to be used in another classes.
EX: There are two classes: one called main and another dynamic class named card. Main can use card as if it had been imported but without importing it.
Any idea of how this works?
In my script I create a textbox and in a function later on I am atempting to read the text of the text box. Is the only way to do this is to put a reference inside of an array so I can use that to get the data? Or is there some other method of saving references to be used later on?
Please tell me if I'm not being clear. :P Thanks
problem solved.
here is my code:
package {
import flash.display.MovieClip;
import flash.display.
import fl.controls.TextInput;
public class Main extends MovieClip {
function Main() {
var key:TextInput=new TextInput();
stage.addChild(key)
key.move(60,78)
key.setSize(430,22)
key.text="Insert key here"
var code:TextInput=new TextInput();
stage.addChild(code)
code.move(60,110)
code.setSize(430,231)
code.text="Insert code here"
var encode:Button = new Button();
encode.label="Encode";
stage.addChild(encode);
encode.move(60,350);
encode.addEventListener(MouseEvent.CLICK,encode);
var decode:Button = new Button();
decode.label="Decode";
stage.addChild(decode);
decode.move(390,350);
decode.addEventListener(MouseEvent.CLICK,decode);
}
function encode() {
}
function decode();
}
}
some how the components are screwing up the document class or something. Any help?
At 1/1/10 08:48 PM, Montycarlo wrote: The filter method returns a new array, and leaves the old one unchanged. Set the value of the variable to the result
myArray = myArray.filter(blah)
Thanks, it works. I didn't know that it doesn't change the array automatically when i put a filter on it. :P
so i have this code that will filter an array, but it doesn't work at all. What's going wrong?
var array:Array=new Array(0,1,2,3,4,5,6)
var limit:uint=6
array.filter(isAboveZero)
array.filter(isBelowLimit)
trace(array)
function isAboveZero(element:int,index:int,array:Array):Boolean{
return(element>0)
}
function isBelowLimit(element:int,index:int,array:Array):Boolean{
return(element<limit)
}
Also, is there a better way to do this?
Thanks for any responses or help.
Thanks for the help, but it didn't solve the problem. I'll look on google to program a better way to create a 2d array.
When working through some of my code, I kept on coming across this 1010 runtime error: "A term is undefined and has no properties." I figured out which line of code it is, but i can't seem to fix it because I don't know what's wrong:
package {
import flash.display.*;
import flash.events.MouseEvent;
import Tile;
public class Main extends MovieClip {
var dimensions:Array;
var colors:Array;
var numColors:uint;
var tileInfo:Array;
var a:uint;
var b:uint;
public function Main() {
//# columns, # rows
//# in a row, # in a column
dimensions=new Array(27,20);
//dark green,orange,red, blue
colors=new Array(0x006400,0xFF8C00,0xCD2626,0x0033FF);
numColors=colors.length;
tileInfo=new Array(dimensions[1]);
for (a=0; a<dimensions[1]; a++) {
tileInfo[a]=new Array(dimensions[2]);
}
createGame();
}
function createGame() {
//row
for (a=1; a<=dimensions[1]; a++) {
//column
for (b=1; b<=dimensions[0]; b++) {
var tile:Tile=new Tile(b-1*20,a-1*20,colors[Math.floor(Math.random()*numColors)],a-1*dimensions[1]+b);
stage.addChild(tile);
tileInfo[a][b]=tile;//problem is here
}
}
}
}
}
Apparently its the last line of code that has to do with assigning the tileInfo array with references to all of the tiles. Any help is appreciated.
Also, if there is a better way to create a two dimensional array, please tell me.
I'm having a hard time getting my head around this. Suppose if I have Main.as that is a document class, and I also have Tile.as that is a regular class. Is it possible to put a event listener in the Tile class that links to a function in the Main class?
if your using as3, you can use the Keys class for all of your games. It is found here: http://www.emanueleferonato.com/2008/10/
27/introduction-to-as3-classes/
hope this helps
even though your comments can be harsh, your right (of course). Now, its time to go shoot myself in the head for the enormous brain fart.
so how would i be able to do this-have a class named tile and when it is created is a square?
Thanks for those wonderful comments GustTheASGuy.
Anyways...
I fixed the Tile class so that the Tile class itself is the tile and for some reason its not working yet:
package {
import flash.display.Sprite;
import flash.display.Graphics;
public class Tile extends Sprite {
public function Tile(xpos:uint, ypos:uint, color:uint) {
Tile.graphics.lineStyle(1,0x000000);
Tile.graphics.beginFill(color);
Tile.graphics.drawRect(xpos,ypos,20,20);
Tile.graphics.endFill();
}
}
}
there are 4 errors that say "graphics" is undefined. There is obviously something I am missing. Could someone help me out while trying not to criticize me? *cough*Gust*cough*
Unfortunatly, the only way to learn is from the internet. But a lot of information can be found on one site, specifically adobe's help site.
Hope this helped!!
So I have this class called Tile and I have a .fla file with this code:
import Tile
var tile:Tile=new Tile(50,50,0xFFFFFF)
stage.addChild(tile)
and the code in Tile:
package {
import flash.display.Sprite;
public class Tile extends Sprite {
public function Tile(xpos:uint, ypos:uint, color:uint) {
trace("tile")
var tile:Sprite=new Sprite()
tile.graphics.drawRect(xpos,ypos,20,20);
tile.graphics.lineStyle(1,color);
stage.addChild(tile);
}
}
}
it keeps on giving me this error:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at Tile()
at Test_fla::MainTimeline/frame1()
What am I doing wrong?
so what if my folders were set up like this?
|flafolder
|fla
|asfolder
|As
For the as file, would I put this:
package asfolder{}
What would I do for the document class in fla? Can i do this:
Parent.asfolder.As
so say I had two folders; one with the .fla in it, and one with the .as file in it which is the document class for the .fla. How would I link the .as to the .fla if they are in two differnt folders? I tried Parent.asfolder.asfile, but that didn't work.
Also, I've been seeing this on some examples:
package something1.something2{
}
How does that work? it is a subclass of the ssomething2 which is a child of something1?
Thanks for any help!
if you wante speed to decrease back to a default value after time "runs" out for the powerup, just have two vars: speed and dspeed(default speed). then using a hittest, just increase speed and after awhile decrease it to equal dspeed. If you need actually code, just say so.
Help!! Here is the as code in the as file/ timeline. It won't do anyhting . what am I doing wrong?
package {
import flash.display.Sprite;
import flash.display.MovieClip;
import back;
public class Bmanbackground extends Sprite {
var backgrnd:back;
public function bmanbackground() {
backgrnd=new back();
addChild(backgrnd);
}
}
}
var scenery:Bmanbackground=new Bmanbackground()
addChild(scenery)
what I meant is that I have this class, and I want it to be able to assign children to iteself using moveiclip that are already in the fla file. I know how to do the rest, just the linking part is what I don't know about. would I use the base class property in the mc to link it to the as file or what?
so, i have a question. Is it possible for a class to use sysmbols from the .fla's library? If it is, how would I do it?
So I know how to make classes in external files, but everyone that is really good at as3 syas that all coding should be as files and not in the frame. How would I design the file if it is not a class? Or should I make the code that goes on the frame a class?
so I have this code:
var mounwidth:Number=710;
var mouncur:Number=-100;
var mounarray:Array=new Array(3);
var mounhold:Sprite=new Sprite();
addChild(mounhold);
var lavawidth:Number=713;
var lavacur:Number=0;
var lavaarray:Array=new Array(3);
var lavahold:Sprite=new Sprite();
addChild(lavahold);
i was wondering if it would be possible to cut his code in half by having the variable "word" be first moun and then lava and use stage[word+"var"] for all the different variables. But when I tried this, all of the references to the variables failed.
Thanks, I had that script but I found a typo :P
an easier way to change the attackdone boolean is to have it become true whenever the person reaches a certain amount of frames. To do this, just put attackdone=true inside these frame(end of running animation, etc.)
i was wondering if it is possible to "mirror" all of the frames of a moveiclip with as3. If it is nnot then I will have to make two moveiclips. ex: running left, and running right; do they have to be two seperate groups of frames?
http://www.metanetsoftware.com/technique /tutorialA.html
its where I got my technique
with that code, can I change the "depth" of the array and will it change all the mc's depths inside it? or do I need to make a seperate container mc to do this?
so I have this code. it is supposed to store the references to them in an array.
for (a=1; a<=3; a++) {
var moun:mountain=new mountain();
moun.x=mouncur;
moun.y=253.7;
moun.name="moun"+a;
addChild(moun);
mounarray[(a-1)]=stage.getChildByName("moun"+a);
trace(mounarray[a])//undefined
}
only, it come out undefined. Help!!
so how can i change an mc's x value when it is in an array?