Creating My Own Class, Or Not?
Hi everyone,
I'm working on my first actionscript test project.
I want to make a picture gallery.
So far, I can read the imagelinks from an xml file.
Also I read the description from those images from the xml file.
Then, I place a movieclip (with a picture) and a label (with the description on my movie, for all entry's in the xml file.
So far so good...
My question is:
Is it better to create my own component/class for each image?
So I can easily say where to put for example a date?
So it would be a component/class containing a movieclip and at least one label.
Or should I just build the gallery peace by peace, by just placing movieclips and labels?
What would you advice me to do?
Thanks in advance.
FlashKit > Flash Help > Flash ActionScript
Posted on: 07-04-2004, 10:18 AM
View Complete Forum Thread with Replies
Sponsored Links:
[AS2 Class] Creating Extended Class Of Intrinsic
Okay,
This has been causing me a few problems lately, so I'm begging for someone to help.
I'm building an extended Date class, containing some features I use constantly in calendar, date parsing, and formatted output operations.
What's causing problems is the constructor, and passing parameters to the original Date constructor. Because the Date class allows multiple constructor formats, simply calling "super()" fails (or rather calls the Date() constructor with no parameters). I also can't pre-check and pass parameters to super() as AS requires that super be called before any other constructor code.
ANy ideas?
View Replies !
View Related
Creating Instances Of On Class In Another Class
Hi
I am using MX04Pro, and just starting out using external class files. i have used C++ in the past so may be expecting a bit much of AS2.
I have a class called 'channel' and one called 'Fade'
i want to create an array of Fade instances within the channel class.
ie
fadeArr[i] = new Fade(param);
i have read that i cannot use #include within a class definition, but is there a way to do what i want to?
Any help would be welcomed
Silent Bob
View Replies !
View Related
Instatiating Class Vs Creating Class
OK - this is a pedantic question but it has me bothered. Makes it difficult to ask questions and understand answers if I am not sure how people are using words.
When creating a instance of a class. Is "creating an instance of a class" the same as "instantiating a class"?
What I mean is - I always thought that saying
new Ship();
was "creating" the class, - the class is available but not linked to any named instance - and
var mothership:Ship = new Ship();
was "instatiating" it, as it now has the name motherShip.
?
View Replies !
View Related
Help, Creating A Class From An .fla
Hi,
I've created a movie that loads a swf and has buttons to control the zooming/panning of the loaded swf. I want to create a class file to allow the reuse of these buttons. Is there an easy way to do this? Does anyone know of any good tutorials on how to do this.
I'm new to object oriented actionscripting so any help would be greatly appreaciated.
View Replies !
View Related
Creating Class
how to emplement this... every i load an object from xml file the object loaded will become a member of a class i called ItemStorage... anybody have ny idea... sorry just a beginer here...
View Replies !
View Related
Help Creating Class.
Hi!
I am creating a helloWorld example here with actionscript 3.0 but I am having some dificulties.
Here is my class :
Code:
package
{
public class Greeter
{
public function sayHello():String
{
var greeting : String;
greeting = "Say Hello!";
return greeting;
}
}
}
and here is my code at flash:
Code:
var mygreeter : Greeter = new Greeter();
mainText.text = mygreeter.sayHello();
And here are the error messages I am getting:
1180: Call to a possibly undefined method Greeter.
1046: Type was not found or was not a compile-time constant: Greeter.
What am I doing wrong?
thank you
View Replies !
View Related
Failed Creating A Class
I've defined my class in an .as file. I've followed the naming rules for the class and the file ('I've done this before guys)
but then I create another project and tried to use the class but it seems that the class is invisible to the script.
I can't create a new instance of the class and I can't debug it.
I've allready moved my .as file containing the class definition to the new project's directory..
but nothing works..
what happened ??
View Replies !
View Related
Creating A Callback For A Class
Hi,
Im trying to create an AS2 class that I can register a call back with. In short hand, I want to be able to do the following on my main timeline:
Code:
var obj:MyClass = new MyClass();
obj.callBack = function(){
trace("this function was called by an object of type MyClass ");
}
obj.doYourThing(); //this function sets off the internal workings of the class... and ultimately results in callBack() getting called.
How do I create a class like this? I want to be able to use my custom class like i can use the XML or LoadVars classes - by defining my own callbacks - like they have onData() / onLoad() call backs.
I really hope someeone can help with how it should look inside my class!
Thanks.
Tim.
View Replies !
View Related
Creating A Member Of A Class Which Also Is An Mc?
hi.
im making classes to create different things which i mainly draw with the drawing-API.
right now, when i create a member of the class, the constructor gets called, which creates a new mc with the things i want. and to be able to use methods of the class for the mc, i have to target the member of the class, which has a reference to the mc. and when i want to change props like _x and _y of the mc, i have to target it directly instead (unless i make a method for that) and this gets very confusing.
so in short, how can you kind of make an instance of a class, which also is an mc? oh, and i dont want to have to have an mc in the library which links to the class.
any answer apreciated. thanks
View Replies !
View Related
Custom Class - Creating Box
Hi everyone,
I've been playing around with custom classes.
My objective was to create a custom class (Testing) that would create a box when an instance of the class is created. I've tried three different approaches, however only (3) seems to be showing up.
I'm just curious why (1) or (2) doesn't work?
Also is there a better approach than (3)? Since at the moment it's been created on _root. I hope the box can only be accessible through the instance. Since I'd like to incorporate the whole idea of public, private, encapsulation, etc.
Any opinions or suggestions would be most helpful.
regards,
Mike
Code:
// AS2 testing line creation in classes.
class Testing extends MovieClip {
// Constructor
function Testing() {
// (1)
// Doesn't work
// Nothing shows up.
/*
lineStyle(2, 0xff0000, 100);
moveTo(0,0);
lineTo(0,200);
lineTo(200,200);
lineTo(200,0);
lineTo(0,0);
*/
// (2)
// Doesn't work
// Nothing shows up.
/*
this.createEmptyMovieClip("abc",this.getNextHighestDepth());
abc.lineStyle(2, 0xff0000, 100);
abc.moveTo(0,0);
abc.lineTo(0,200);
abc.lineTo(200,200);
abc.lineTo(200,0);
abc.lineTo(0,0);
*/
// (3)
// Works, but I don't think it's the best approach.
/*
var tmp = _root.createEmptyMovieClip("abc",_root.getNextHighestDepth());
tmp.lineStyle(2, 0xff0000, 100);
tmp.moveTo(0,0);
tmp.lineTo(0,200);
tmp.lineTo(200,200);
tmp.lineTo(200,0);
tmp.lineTo(0,0);
*/
}
}
View Replies !
View Related
[F8] Problem Creating A Class
Maybe it's cos I'm a java-monkey, and AS 2.0 is new to me, but I'm trying to create a new class in an external .as file, but I'm getting a load of errors when I test a Movie with it included.
Here's the DisPlat.as file source:
class DisPlat {
var _platX;
var _platY;
var _platId;
function DisPlat(valX:Number,valY:Number,valId:String) {
setPlatX(valX);
setPlatY(valY);
setPlatId(valId);
}
function setPlatX(value:Number):Void {
this._platX = value;
}
function getPlatX():Number {
return this._platX;
}
function setPlatY(value:Number):Void {
this._platY = value;
}
function getPlatY():Number {
return this._platY;
}
function setPlatId(value:Number):Void {
this._platId = value;
}
function getPlatId():String {
return this._platId;
}
}
and here are the console messages:
**Error** DisPlat.as: Line 1: Syntax error.
class DisPlat {
**Error** DisPlat.as: Line 12: '{' expected
function setPlatX(value:Number):Void {
**Error** DisPlat.as: Line 16: '{' expected
function getPlatX():Number {
**Error** DisPlat.as: Line 18: Unexpected '}' encountered
}
I have put #include "DisPlat.as" at the start of the script for the frame I'm working in. Am I just being dozy, but I'm used to more meaningful error detection in my Java IDE!
cheers
View Replies !
View Related
Class Is Not Creating New Instances
Hello,
I have created a class called surverySlide in which I have linked to a bunch of slides. each slide registers how many questions it has to the class (itself). The problem is I need each movieclip to be its own instance of SurveySlide ( I have a surveyManager class built to deal with each. I am using attachmovie to show them in sequence on the stage (loading one after the other). I assumed by linking each movie clip to the class a new instance would be created each time but only one instance is created. I.e. the questions are put into an array that should be only for that instance but everytime a new instance is loaded it is added on to the array.
I don't know if I am explaining this clear enough so.....
in each instance of the class (which is a movie clip) I will register the question to that slide...
i.e.
slide instance 1
this.registerQuestion(1);
this.registerQuestion(2);
//if I output the array here I get 1,2
slide instance 2
this.registerQuestion(3);
//if I output the array here I get 1,2,3
//I want it to only output 3
Does anyone know off hand why this is happening?
View Replies !
View Related
Creating Events In A Class
I'm a newbie to OOP. I have been trying to understand this on my own to no avail. Hence, this post.
I am using a Class written by Colin Moock from his AS 2.0 book and I'm just starting to get the hang of it. I was able to intantiate an object of a class that I named ClickViewer. It is the same as Colin's ImageViewerDeluxe class except I added one property and I tried to apply an event as so ...
Code:
class ClickViewer extends ImageViewer{
//New variables
//Reference to picture that will be diplayed in main viewing area.
private var picReference:Number;
//Flag to allow sizing to actual size of the image. Important for thumbnails that are clickable.
private var showFullImage:Boolean = false;
public function ClickViewer (target:MovieClip,
depth:Number,
x:Number,
y:Number,
w:Number,
h:Number,
borderThickness:Number,
borderColor:Number,
picReference:Number) {
super(target, depth, x, y, w, h, borderThickness, borderColor);
//Assign property. I added this.
this.picReference = picReference;
//I also added this.
container_mc.onRelease = function(){
trace(picReference);
}
}
Now the trace works when I use this code in the .FLA...
Code:
function buildMenu(){
step = 85;
for (depth=0; depth<picPaths.length; depth++){
thumbs[depth] = new ClickViewer(this, depth, x, y, w, h, borderThickness, borderColor, depth);
thumbs[depth].loadImage(picPaths[depth]);
thumbs[depth].setShowFullImage = true;
if(depth>0){
yPos = yPos + step;
thumbs[depth].setPosition(xPos, yPos);
}
}
}
The problem ... Not sure how to state it ... Usually when I work with a component, for example, I can write this ...
Code:
my_component.onXXXXX = function(){
some code;
}
This way I can do something based on it. The code that I have in the class "container_mc.onRelease" does not seem to really do anything for me. So my question is ... How do I write code into the class that will allow me to write a listener on my ClickViewer object? I already tried writing something like the above -thumbs[depth].onXXXXX ... - but it did not work.
Any help will be appreciated.
View Replies !
View Related
Problem Creating A Class
Hi,
i made a series of functions and decided to make a class out of them. but when i crated a class it started to behave a little bit different.
please somebody help.
Here is the starting code:
Code:
import mx.transitions.Tween;
import mx.transitions.easing.*;
var nDestination:Number = 30;
var nDim:Number = 5*nDestination;
var nX:Number = 0;
var nY:Number = 0;
var mcPiece:MovieClip;
mcImage._width = 400;
this.createEmptyMovieClip("mcMask", this.getNextHighestDepth());
mcImage.setMask(mcMask);
mcMask._x = mcImage._x-25;
mcMask._y = mcImage._y;
var nStageWidth:Number = Stage.width;
var nAddMaskInterval:Number = setInterval(addToMask, 10);
//
function addToMask():Void {
var nDepth:Number = mcMask.getNextHighestDepth();
//mcPiece = mcMask.attachMovie("mask", "mcPiece" + nDepth, nDepth);
mcPiece = mcMask.createEmptyMovieClip("mcPiece" + nDepth, nDepth);
with (mcPiece) {
beginFill(0x000000, 100);
moveTo(0, -50);
curveTo(0, 0, -50, 0);
curveTo(0, 0, 0, 50);
curveTo(0, 0, 50, 0);
curveTo(0, 0, 0, -50);
endFill();
}
mcPiece._x = nX;
mcPiece._y = nY;
var popTweenX:Tween = new Tween(mcPiece, "_width", Regular.easeIn, 0, nDim, 1, true);
var popTweenY:Tween = new Tween(mcPiece, "_height", Regular.easeIn, 0, nDim, 1, true);
nX += nDestination;
if (nX>=mcImage._width+nDim) {
nX = 0;
nY += nDestination;
}
if(nY - nDim > mcImage._height){
clearInterval(nAddMaskInterval);
}
}
and here is the class i created out of it:
Code:
import mx.transitions.Tween;
import mx.transitions.easing.*;
class AnimateMask {
var nDestination:Number;
var nDim:Number;
var nX:Number;
var nY:Number;
//var mcPiece:MovieClip;
var nStageWidth:Number = Stage.width;
var nAddMaskInterval:Number;
var mcTarget:MovieClip;
var mcTargetHeight:Number;
var mcTargetWidth:Number;
//
function AnimateMask(mcTarget, nDestination) {
this.nDestination = nDestination;
this.nDim = nDim = 5*nDestination;
this.nX = nX = 0;
this.nY = nY = 0;
//this.mcPiece = mcPiece;
this.nStageWidth = nStageWidth;
this.nAddMaskInterval = nAddMaskInterval;
this.mcTarget = mcTarget;
this.mcTargetHeight = mcTargetHeight = mcTarget._height;
this.mcTargetWidth = mcTargetWidth = mcTarget._width;
init();
}
function init() {
var nDepth:Number = this.mcTarget.getNextHighestDepth();
var mcMask = this.mcTarget.createEmptyMovieClip("mcMask", nDepth);
this.mcTarget.setMask(mcMask);
mcMask._x = this.mcTarget._x-25;
mcMask._y = this.mcTarget._y;
this.nAddMaskInterval = setInterval(this, "addMask", 10);
}
function addMask() {
var nDepth:Number = this.mcTarget.mcMask.getNextHighestDepth();
var mcPiece:MovieClip = this.mcTarget.mcMask.createEmptyMovieClip("mcPiece"+nDepth, nDepth);
with (mcPiece) {
beginFill(0x000000, 100);
moveTo(0, -50);
curveTo(0, 0, -50, 0);
curveTo(0, 0, 0, 50);
curveTo(0, 0, 50, 0);
curveTo(0, 0, 0, -50);
endFill();
}
mcPiece._x = this.nX;
mcPiece._y = this.nY;
mcPiece._alpha = 50;
var popTweenX:Tween = new Tween(mcPiece, "_width", Regular.easeIn, 0, nDim, 1, true);
var popTweenY:Tween = new Tween(mcPiece, "_height", Regular.easeIn, 0, nDim, 1, true);
this.nX += this.nDestination;
//trace(this.nDim);
if (this.nX>=this.mcTargetWidth+this.nDim) {
this.nX = 0;
this.nY += this.nDestination;
}
if (this.nY-this.nDim>this.mcTargetHeight) {
clearInterval(this.nAddMaskInterval);
}
}
}
the problem seems to be in nX variable but i dont get what it is.
View Replies !
View Related
Creating New Class Properties
Hello,
I'm writing a little script to make balls bounce around on the stage and change velocity and acceleration as they bump into the sides(just to learn animating and stuff:P). So, I can set a ball's x and y properties by just using "this.x = " and "this.y = ". But I'd like to create a new property for the class called "speed", and I guess I can't just write "this.speed = ". How would I go about this?
Thanks in advance!
View Replies !
View Related
Creating A Class Question
basically i am trying to make my own simple class.
ActionScript Code:
class org.scoobasteve.window {
function window(colorBox:String, posX:Number, posY:Number, widthBox:Number, heightBox:Number) {
_root.createEmptyMovieClip("square", square.1);
square.beginFill(colorBox,100);
square.moveTo(posX, posY);
square.lineTo((posX+widthBox), posY);
square.lineTo((posX+widthBox), (posY+heightBox));
square.lineTo(posX, (posY+heightBox));
square.lineTo(posX, posY);
}
}
what i am trying to do is create a class that creates a box with a certain width, height, and position on the artboard.
what i am getting errors with is the square lines. how would i go about creating a movie clip in a class and making a shape in it?
View Replies !
View Related
Creating A Class Array
Hey I have a class called Tile and I want to make a 2d array with it, but it gives me an error.
Code:
var map:Array = new Array()();
map[0][0] = new Tile(0, 0, tileSize, gridOffset, "");
Code:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at fso/refresh()
at fso/initClient()
at fso/initGame()
at fso/frame6()
View Replies !
View Related
Creating A Class Using Other Classes...
Ok i am creating a class that includes file Reference but i cant make it to
start working... What do i do wrong???
//file starts here:
import flash.net.FileReference
//System.security.allowDomain(path);
class fileUploader
{
private var fileUpload : FileReference = new FileReference ();
this line throws me an error.
is a lot more of code but i need to fix this only....
Thank you
View Replies !
View Related
Creating And Using Custom Class
Can someone point me towards any good tutorials on creating custom classes? I have created some code to move a character around in a game. I would like to set it up as a custom class so that I can import it when I need it again. I have (sort of) a theoretical idea of how this works but not the practical knowledge to execute it. Thank you.
View Replies !
View Related
Dynamically Creating Class's
Hi,
Recently I've been investigating some open source code as a learning exercise. There are one or two things about it that i'm uncertain about so I thought Id ask here.
Im curious to know if the attached code is used to dynamically create a class named "wavesound"?
Also, when I'm running the code I get an error that says
"TypeError: Error #2023: Class wavesound$ must inherit from Sprite to link to the root."
If i'm right about the code dynamically creating a class how can I get that class to inherit from Sprite?
Any assitance in improving my understanding on this is greatly appreciated!
Thanks,
-dub
Attach Code
var SymbolClass:Class =loader.contentLoaderInfo.applicationDomain.getDefinition("de.benz.wavesound") as Class;
View Replies !
View Related
Creating A Class Instance
Hi, trying to create a class instance and keep getting this error:
Error: Error #2136: The SWF file file:///Kenny/Workspaces/Jim/flashVideo/src/FlashVideo.swf contains invalid data.
at FlashVideo()
Below is the code for the 2 as files I'm using. FlashVideo is supposed to call MousePosition
Attach Code
// .................................FlashVideo.as
package
{
import flash.display.Sprite;
import flash.display.*;
import flash.events.*;
public class FlashVideo extends Sprite {
public function FlashVideo () {
trace ("FlashVideo has run");
var position = new MousePosition();
}
}
}
//......................... MousePosition.as
package
{
public class MousePosition extends FlashVideo {
public function MousePosition ()
{
trace ("MousePosition has run");
}
}
}
View Replies !
View Related
Dynamically Creating A Class
Version: Flash CS4, AS3
Hi - is it possible to turn a given sprite into a Class with a given string as its name?
The resulting class should then be available under that name in the current domain's definitions.
ie.
createClass(someSprite, "someName");
....
var someClass:Class = getDefinitionByName("someName") as Class;
Thanks,
Rick
View Replies !
View Related
Creating A Filter Class
I have been up all night trying to get this to work and thought maybe there was a working version on the net somewhere.
I'm trying to create some script that will connect to my PHP script, which has searched the database for whatever I told it to....and it will right the results to XML that I send to Flash...
What I've been up all night doing is trying to make some kind of class that will allow me to filter those results ACTIVELY...
If you don't know what I mean then I can show you
If you're running Firefox
go to the address bar and type about:config
when you get there you can filter them by typing any letter
it will return all the results that have that/those letters in them
Notice how it does it for every letter
and if you're not using Firefox....you should...lol
Actually you can see you preview of it by using the iTunes search feature
I've had enough of these undefined messages in my test output..the same XMLNode object whatever selections worked without the class and now I'm going crazy
Anyone have an idea where I could find such a Class
or perhaps know better search keywords than
iTunes search filter Actionscript Flash Class
Thanks for any help
View Replies !
View Related
Creating A Buttons Class
So here's my AS for my buttons:
ActionScript Code:
missionTab.onRollOver = function() { if (_root.currentTab == missionTab) { // } else { this.gotoAndPlay(2); }};missionTab.onRollOut = function() { if (_root.currentTab == missionTab) { // } else { this.gotoAndPlay(8); }};missionTab.onRelease = function() { if (_root.currentTab == missionTab) { // it wont be } else { // put the current tab back to position _root.currentTab.gotoAndPlay(8); // set the new current tab trace(_root.currentTab); _root.currentTab = missionTab; _root.xmlPage = "xml/vision/mission.xml"; _root.mainStage.loadXML(); }};
And, I've got like a million of these buttons throughout my movie... So, I figured that it would be smarter to put this into a class so that I can reuse it all I want and not have a trillion lines of code to have to sift through. They're all going to be doing the exact same thing, other than the names and associated xml files, etc.
Can someone please break this down for me... I've never been comfortable with Classes, yet I see so many instances of where a Class would be useful.
Thank you.
View Replies !
View Related
Creating Class For Preloader.How?
Hi!
I am new to Actionscript 3.0 and to create classes but I am trying to create a class to preload every swfFile I have on my site.How would I do this?
I was trying this:
Code:
Package
{
public class Carregador
{
public function loadSwf(swfFile:String):void
{
var request:URLRequest = new URLRequest(swfFile);
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, loadProgress);
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadComplete);
loader.load(request);
addChild(loader);
}
public function loadProgress(event:ProgressEvent):void {
var percentLoaded:Number = event.bytesLoaded/event.bytesTotal;
percentLoaded = Math.round(percentLoaded * 100);
trace("Loading: "+percentLoaded+"%");
}
function loadComplete(event:Event):void {
trace("Complete");
}
}
}
How would I show a progress bar(MC) that is on my stage?Would I have to send the name of a bar so that my class could increment its _x property?How does It work?
And how would I load my swf file into an empty MC like usual?
View Replies !
View Related
Help Creating A Self Animating Class...
Hey everyone, my goal here is to create a class that will display and animate a small square in size and color. My problem is that nothing is showing up on the screen and I'm not sure why... here is the class code:
Code:
package {
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.events.Event;
import flash.geom.ColorTransform;
import flash.display.Shape;
import flash.display.MovieClip;
public class AbstractSquare extends MovieClip {
private var scolor:uint;
private var sTrans:ColorTransform;
private var sShape:Shape;
private var flashT:Timer;
private var hideT:Timer;
private var showT:Timer;
public function AbstractSquare(sx:int, sy:int, swidth:int, sheight:int, col:uint){
this.x = sx;
this.y = sy;
this.width = swidth;
this.height = sheight;
scolor = col;
sShape = new Shape();
flashT = new Timer(30, 10);
flashT.addEventListener(TimerEvent.TIMER, animStep);
flashT.addEventListener(TimerEvent.TIMER_COMPLETE, resetTimers);
this.addEventListener(Event.ADDED_TO_STAGE, squareInit);
}
private function squareInit(e:Event){
addChild(sShape);
beginAnimation();
}
private function beginAnimation(){
trace("in beginAnimation");
sShape.graphics.beginFill(scolor);
sShape.graphics.drawRect(0, 0, this.width*1.25, this.height*1.25);
sTrans.redOffset = 255;
sTrans.greenOffset = 255;
sTrans.blueOffset = 255;
sShape.transform.colorTransform = sTrans;
this.x -= 2.5;
this.y -= 2.5;
flashT.start();
}
private function animStep(e:Event):void {
this.width -= .5;
this.height -= .5;
this.x += .75;
this.y += .75;
sTrans.redOffset -= (256/10);
sTrans.blueOffset -= (256/10);
sTrans.greenOffset -= (256/10);
sShape.transform.colorTransform = sTrans;
}
private function resetTimers(e:Event):void {
flashT.reset();
}
}
}
On frame 1 of my movie I have:
Code:
import AbstractSquare;
var asq:AbstractSquare = new AbstractSquare(50,60,40,40,0xff0000);
addChild(asq);
There are no compile errors and the trace works in beginAnimation. Any help would be appreciated!
Justin
View Replies !
View Related
Custom Class - Creating Box
Hi everyone,
I've been playing around with custom classes.
My objective was to create a custom class (Testing) that would create a box when an instance of the class is created. I've tried three different approaches, however only (3) seems to be showing up.
I'm just curious why (1) or (2) doesn't work?
Also is there a better approach than (3)? Since at the moment it's been created on _root. I hope the box can only be accessible through the instance. Since I'd like to incorporate the whole idea of public, private, encapsulation, etc.
Any opinions or suggestions would be most helpful.
regards,
Mike
Code:
// AS2 testing line creation in classes.
class Testing extends MovieClip {
// Constructor
function Testing() {
// (1)
// Doesn't work
// Nothing shows up.
/*
lineStyle(2, 0xff0000, 100);
moveTo(0,0);
lineTo(0,200);
lineTo(200,200);
lineTo(200,0);
lineTo(0,0);
*/
// (2)
// Doesn't work
// Nothing shows up.
/*
this.createEmptyMovieClip("abc",this.getNextHighestDepth());
abc.lineStyle(2, 0xff0000, 100);
abc.moveTo(0,0);
abc.lineTo(0,200);
abc.lineTo(200,200);
abc.lineTo(200,0);
abc.lineTo(0,0);
*/
// (3)
// Works, but I don't think it's the best approach.
/*
var tmp = _root.createEmptyMovieClip("abc",_root.getNextHighestDepth());
tmp.lineStyle(2, 0xff0000, 100);
tmp.moveTo(0,0);
tmp.lineTo(0,200);
tmp.lineTo(200,200);
tmp.lineTo(200,0);
tmp.lineTo(0,0);
*/
}
}
View Replies !
View Related
[AS3] Creating N Instances Of A Class
Hi,
i learned something about classes, constructors and instances. The following Problem occurred to me then:
Let there be a class, MyClass, that extends the MovieClip class, and puts, say, a circle on the stage, x-Position, y-Position and radius being constructors' parameters.
For example
Code:
new Circle:MyClass = new MyClass(100,100,50);
addChild(Circle);
Puts a circle at 100, 100 with the radius of 50. How would i write a code, that creates any given number of instances with specified parameters, for example 100 Circles, all radius 5, but their Position altered slightly?
Gz TWERP
View Replies !
View Related
Help Creating A Button Class
This is my first try at creating a class. It's still unfinished and I could use some hints and advice for debugging. I'm not really sure if I even have everything set up
By the way - Thank you Rob for such a wonderful book...
Code:
#include "shape_drawing_basic.as"
//MakeButon Class
/* PARAMETERS
butPosX =X button position
butPosY= Y button position
butFont= font used for the buton text
butPoints=size of the font
butText=text for the button
butTextColor=text color
*/
/* DEPENDENCIES
drawRectRel - R. Penner
*/
_global.MakeButon=function (butPosX,butPosY,butFont,butPoints,butText,butTextColor){
//properties
this.butPosX=butPosX;
this.butPosY=butPosY;
this.butFont=butFont;
this.butPoints=butPoints;
this.butText=butText;
this.butTextColor=butTextColor;
//initialize
this.MakeButonHolder();
this.MakeHitarea();
}
//buton holder method
MakeButon.prototype.MakeButonHolder=function(){
this.depthCounter=0;
// this.butDepth.push=i;
this.createEmptyMovieClip("BH"+depthCounter,this.depthCounter);
x=BH._x=butPosX; //posicion x
y=BH._y=butPosY;//posicion y
this.depthCounter++;
};
//buton text method
MakeButon.prototype.MakeButonText=function(){
this.createTextField("text"+depthCounter,this.depthCounter,0,0,0,0);
//PROPERTIES
dc=depthCounter;
text[dc].selectable=false;
text[dc].embedFonts=true;
text[dc].autoSize=true;
text[dc].background=0xFF0000;
//METHODS
formatoBoton=new TextFormat(butFont,butPoints,butTextColor,true,null,null,null,null,null,null,null,null,null);
text[dc].setNewTextFormat(formatoBoton);
};
//Hitarea method button will have same size as text(autosize)
MakeButon.prototype.MakeHitarea=function(){
this.createEmptyMovieClip("hitarea",this.depthCounter++);
this.hitarea.beginFill(0,0);
this.hitarea.drawRectRel(x,y,dentrode._width,dentrode._height);
this.hitarea.endFill();
this._listners= new Array(); //to substitue the one created by Asbroadcaster.initialize()
//not sure of how to make the button work...
this.hitarea.onRelease=function(){
trace("onrelease");
};
this.hitarea.onRollOver=function(){
trace("onrollover");
};
};
Asbroadcaster.initialize (MakeButon.prototype);
...
View Replies !
View Related
Creating And AS2.0 Class That Imports Mx.Services.*
Hello all, simple question. Can you import or extend the WebService classes....because everytime I try I get complie errors. Here is an simple example of what I want to do.
import mx.services.*
class dummyWeb{
private var myWebService:WebService;
public function dummyWeb(url:String){
myWebService = new WebService(url)
}
}
I searched on the net but all information refers to dragging either the XMLConnector Class or WebService Class to the canvas then deleting it. The only problem there is that I cannot drag anything cause I am creating a class in the ActionScript editor.
Is there any way to do this?
Thanks.
View Replies !
View Related
Creating Objects Inside A Class?
Hey everyone
I have maked a really simple class called myObject, which has one public variable:
Code:
class com.runemadsen.myObject
{
public var myVar:String;
}
Then I have another class called ObjectOutputter. In that class I have a for loop that loops 10 times, creating 10 myObjects, and assigns the loop number to myVar in each object. The i store the new object in an array:
Code:
import com.runemadsen.myObject;
class com.runemadsen.ObjectOutputter
{
var myArray:Array = new Array();
public function go()
{
for(i=0;i<10;i++)
{
var newObject:myObject = new myObject();
newObject.myVar = i;
myArray.push(newObject);
}
}
}
My question now is this: When i use the ObjectOutputter in a fla file like this:
Code:
import com.runemadsen.*;
var OO:ObjectOutputter = new ObjectOutputter;
OO.go();
... how can I target myArray?
I have tried: return myArray; after the loop, but it doesn't work.
I'm not sure I understand where all the objects are made. In my fla where I make my instance of the ObjectOutputter or somewhere else?
Can't figure it out :-(
thanx anyway
View Replies !
View Related
[F8] Creating Empty Movieclip In An AS Class
hello
i'm starting to play around with actionscript classes, and i'm wondering if someone could help me for a second
I want to make a class that creates a movieclip and then uses the drawing API to draw a box in this movieclip
eventually i want to make it so all i have to do is say
var box1 = new box
var box2 = new box
etc
so then to make them animate according to what action i say, so say i could do
box1.action = "down"
box2.action = "up"
which would be done dynamically due to other things in the final flash file, using functions and such was starting to get messy :P
so to start with i'm trying to create a simple box with a class file, but as it is i'm still very much learning and this just won't work for me
this is a test.as i have so far (not much, but i'm sure it'll get better )
Code:
class Objects.test extends MovieClip
{
private var theMc:MovieClip;
public function test(depth:Number, __left:Number, __height:Number, __color:Number)
{
theMc.createEmptyMovieClip("bar"+depth, depth);
with (theMc)
{
beginFill(__color, 20);
moveTo(__left, 0);
lineTo(__left+100, 0);
lineTo(__left+100, __height);
lineTo(__left, __height);
lineTo(__left, 0);
endFill();
}
}
}
which is in a folder called "objects" on the same directory level as my main fla file.
thankyou for your help
View Replies !
View Related
Creating Class Fron Scratch
I want to create a new class from scratch.
this class will be put on the stage.
it will store all the common function and variables like:
gravity
frame elapsed
time elapsed
and many other variable that are access by many different things.
So I created this class:
Code:
package {
import flash.display.DisplayObject;
public class utama extends DisplayObject {
var gravitasi:Number = 0;
public function utama():void {
}
}
}
I make it inherit DisplayObject so that it can be put on stage.
and I use this code to put it on stage
Code:
var con:utama = new utama();
addChild(con);
con.name="con";
trace(con.adabingkai);
and it returned an error:
ArgumentError: Error #2012: utama class cannot be instantiated.
at testas3lalat$iinit()
and when i put that piece of code out, it work just fine.
can anyone help me, thank you.
View Replies !
View Related
Problem With Creating Instances Of One Class In Another
I've created a class called RotatingLine. Basically it draws a line from a centerpoint to a radius and rotates that line clockwise around the center point.
I then created another class call RotatingLines. What I want to do hear is the add 10 instances of RotatingLine to the stage at the same x,y pos to create something like spokes.
Both .as files are in the same directory.
When I test the move I get the following error:
Code:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at RotatingLine/init()
at RotatingLine()
at RotatingLines/init()
at RotatingLines()
Here are my classes:
RotatingLine
Code:
package{
import flash.display.Sprite;
import flash.events.Event;
public class RotatingLine extends Sprite{
var sprite1:Sprite;
var sprite2:Sprite;
var radius:Number = 50;
var speed:Number = .1;
var angle:Number = 0;
var centerX:Number;
var centerY:Number;
public function RotatingLine():void{
init();
}
public function init():void{
sprite1 = new Sprite();
this.addChild(sprite1);
sprite1.graphics.beginFill(0x000000);
sprite1.graphics.drawRect(-2,-2,0,0);
sprite1.graphics.endFill();
sprite1.x = stage.stageWidth/2;
sprite1.y = stage.stageHeight/2;
centerX = sprite1.x;
centerY = sprite1.y;
sprite2 = new Sprite();
this.addChild(sprite2);
addEventListener(Event.ENTER_FRAME,onEnterFrame);
}
public function onEnterFrame(evt:Event):void{
sprite2.x = centerX + Math.cos(angle) * radius;
sprite2.y = centerY + Math.sin(angle) * radius;
angle += speed;
graphics.clear();
graphics.lineStyle(1,0,1);
graphics.moveTo(sprite1.x,sprite1.y);
graphics.lineTo(sprite2.x,sprite2.y);
}
}
}
RotatingLines
Code:
package{
import flash.display.Sprite;
import flash.events.Event;
public class RotatingLines extends Sprite{
var Xpos:Number = stage.stageWidth/2;
var Ypos:Number = stage.stageHeight/2;
var numLines:int = 10;
public function RotatingLines():void{
init();
}
public function init():void{
for(var i:int;i<numLines;i++){
var line:RotatingLine = new RotatingLine();
addChild(line);
line.x = Xpos;
line.y = Ypos;
}
}
}
}
Thanks in advance for any help.
View Replies !
View Related
Error 1136 When Creating Class.
It seems like it would be a pretty simple error to fix, but I have been looking around for hours and haven't found anything...
There's a Main.as file calling an external file, PerpetratorMaker.as which creates a new Perpetrator object, which is a movie clip I drew which is exported for actionscipt in the .fla file's library.
here is the code:
PHP Code:
package
{
import flash.display.MovieClip;
public class PerpetratorMaker extends MovieClip
{
public var willbeshot:Perpetrator = new Perpetrator;
public function PerpetratorMaker ()
{
//Do stuff
}
}
}
The exact error I get is this:
Code:
1136: Incorrect number of arguments. Expected 1.
Any ideas?
View Replies !
View Related
Creating An Instance Of A Custom Class
Hey!
I'm quite new to OOP in AS3 (I've worked alot with OOP in VB.Net but it's a bit different). I wonder how I can import a custom class to my flash file. I think it shouldn't be too hard, but I've looked at alot of forums but none have given me a solution.
I have a main file (it's supposed to become my photo gallery).
I also have a folder, named "classes".
In the "classes" folder, I have a file named "claAlbum.as". It looks like this:
Quote:
package {
class Album{
import flash.display.Sprite;
public var strTittel:String;
public var dteDatoate;
public var intAntall:int;
}
}
Now what I am trying to achieve is to make an instance of this object in my main file (one level up).
Does anybody have any suggestions on how to do this? (Am I structuring things the wrong way?)
View Replies !
View Related
Creating Functions With The Tween Class
I'm working with the Tween class in Flash 8. It's great stuff, except I find my ActionScript is getting excessively lengthy. For example, I have ten instances of buttons on stage. They all utilize this particular bit of code, which makes the buttons pop upward:
ActionScript Code:
button1.onRollOver=function(){
//initailizing the Tween
var popBtn:Tween=new Tween(button1, "_y", mx.transitions.easing.Elastic.easeOut, 0, -20, 2, true);
//calling the tween object
popBtn.start();
}
The only difference for any of the buttons in the script is the name of the instance. When i set this up as a global function, using "this" instead of a specific instance name, the script fails to execute. So I have to hammer out all those lines of code for each button instance.
Thanks in advance for any help!
View Replies !
View Related
Creating Intrinsic Class Files
Okay, I'm trying to add some .as files with my custom functions that I plan on using in a lot of my flashes to the standard library, but I'm having some problems. The biggest one is that I can't find the main library. I've found the folder of class files with as files that are a list of the functions and variables in that class.
The lists are basically a bunch of "static function functionname(parameter:type):type;" and similar for variables, but I've looked everywhere and failed to find the actual definitions of these functions!
Does anyone know where those files would be?
EDIT: and by the way, the folder in which the files I HAVE found is here:
C:Documents and SettingsdefaultLocal SettingsApplication DataMacromediaFlash 8enConfigurationClassesFP8
View Replies !
View Related
Creating Class Instances Dynamically
I'm working on a soundboard application in AS3 and I have imported over 50 sounds into Flash and every single one has their own Linkage Class name. The problem is, how to create an instance of each sound dynamically?
Let's say that the Class names are sound1, sound2, etc. Using loop and calling new sound + i (where "i" is the number) doesn't seem to work, but flash throws an error: "Instantiation attempted on a non-constructor". Is there a way to convert Class name-strings into some sort of constructor?
OR is there easier/other way to create instances of sounds with AS?
View Replies !
View Related
Problem With Creating Instances Of One Class In Another
I've created a class called RotatingLine. Basically it draws a line from a centerpoint to a radius and rotates that line clockwise around the center point.
I then created another class call RotatingLines. What I want to do hear is the add 10 instances of RotatingLine to the stage at the same x,y pos to create something like spokes.
Both .as files are in the same directory.
When I test the move I get the following error:
Code:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at RotatingLine/init()
at RotatingLine()
at RotatingLines/init()
at RotatingLines()
Here are my classes:
RotatingLine
Code:
package{
import flash.display.Sprite;
import flash.events.Event;
public class RotatingLine extends Sprite{
var sprite1:Sprite;
var sprite2:Sprite;
var radius:Number = 50;
var speed:Number = .1;
var angle:Number = 0;
var centerX:Number;
var centerY:Number;
public function RotatingLine():void{
init();
}
public function init():void{
sprite1 = new Sprite();
this.addChild(sprite1);
sprite1.graphics.beginFill(0x000000);
sprite1.graphics.drawRect(-2,-2,0,0);
sprite1.graphics.endFill();
sprite1.x = stage.stageWidth/2;
sprite1.y = stage.stageHeight/2;
centerX = sprite1.x;
centerY = sprite1.y;
sprite2 = new Sprite();
this.addChild(sprite2);
addEventListener(Event.ENTER_FRAME,onEnterFrame);
}
public function onEnterFrame(evt:Event):void{
sprite2.x = centerX + Math.cos(angle) * radius;
sprite2.y = centerY + Math.sin(angle) * radius;
angle += speed;
graphics.clear();
graphics.lineStyle(1,0,1);
graphics.moveTo(sprite1.x,sprite1.y);
graphics.lineTo(sprite2.x,sprite2.y);
}
}
}
RotatingLines
Code:
package{
import flash.display.Sprite;
import flash.events.Event;
public class RotatingLines extends Sprite{
var Xpos:Number = stage.stageWidth/2;
var Ypos:Number = stage.stageHeight/2;
var numLines:int = 10;
public function RotatingLines():void{
init();
}
public function init():void{
for(var i:int;i<numLines;i++){
var line:RotatingLine = new RotatingLine();
addChild(line);
line.x = Xpos;
line.y = Ypos;
}
}
}
}
Thanks in advance for any help.
View Replies !
View Related
Creating Multipe Units In Same Class
hey all,
I'm still trying to get a solid handle on classes, so bear with me.
I am making a wargame where there are multpile units (each with different strengths and location). Now, I have a Unit class, with each unit being created using and array and loop. BUT, when I go to the document class (aka stage?) , I still have to addChild for all those unts,thus needing to make another array and loop. Is there a more efficient [read: no need to repeat code] to do this, or should there be no Unit class per se (where all the unit creation is done in the document class)?
Thx
View Replies !
View Related
Creating A Library Class Name From A String
Hello,
If anyone can help me with this i'll be really grateful. So, i have these sprites in the library called item0 - item6, each of them having the class Item0 - Item6.
what i'm trying to do is create an instance of one of them depending on a current index i have and which is changing from 0 to 6.
what i did is the following:
Quote:
var className:String = "item" + this.itemCounter;
var item:Sprite = new (getDefinitionByName(className) as Class)();
[...]
addChild(item);
this.itemCounter++;
this works fine on the first iteration (when this.itemCounter = 0) but it breaks when it becomes 1. the error i get is "ReferenceError: Error #1065: Variable Item1 is not defined." i don't get it though, the class name IS Item1 on the 2nd iteration.
can anyone explain this, please?
EDIT: nevermind >.< i apparently typo-ed the classname with lowercase "i". it works! ;D *joy*
View Replies !
View Related
Creating Buttons From A Document Class
the code below works in that it sends the button you click on to it's selected state ( send it to gotoAndPlay("selected"); )
now what happens when i roll off any button after I click it is it snaps back to it's null state (frame 1)
all the buttons have a stop action at the end of the "selected" frames
any help is greatly appreciated.
ActionScript Code:
package classes {
import flash.display.*
import flash.events.*
public class Main extends MovieClip{
public var buttons:Array;
public var BTN_Home:MovieClip;
public var BTN_News:MovieClip;
public var BTN_Projects:MovieClip;
public var BTN_Contact:MovieClip;
public var BTN_Bio:MovieClip;
public var BTN_Music:MovieClip;
public function Main():void {
trace("hi");
initButtons();
}
public function initButtons():void
{
buttons = [BTN_Home, BTN_News, BTN_Projects, BTN_Contact, BTN_Bio, BTN_Music];
var i:int = buttons.length;
while (i--)
{
trace("buttons[i] = " + buttons[i]);
buttons[i].buttonMode = true;
buttons[i].id = i;
buttons[i].addEventListener(MouseEvent.CLICK, onClick);
buttons[i].addEventListener(MouseEvent.ROLL_OVER, onOver);
buttons[i].addEventListener(MouseEvent.ROLL_OUT, onOut);
}
}
private function onClick(event:MouseEvent):void {
event.target.gotoAndPlay("selected");
}
private function onOut(event:MouseEvent):void {
trace("rolled out of " + event.target);
}
private function onOver(event:MouseEvent):void {
trace("rolled over " + event.target);
}
}
}
View Replies !
View Related
Creating Custom Button Class In AS3.
Hi Guys,
I'm having a problem with creating some custom buttons and wondered if anyone would be able to help?
Basically I am trying to create some buttons that look like hyperlinks, so white background with coloured writting, and on mouseover, click etc. I would like the text to change transparency and so have created functions to do this (see below). HOWEVER, it doesn't appear to be working....there are no compiling errors but the button isnt appearing on the stage at runtime. I am trying to make the custom functions generic as I am going to have to create 4 buttons. Can anyone point me in the right direction?
Thanks
Code:
var homeBtnText:String = "Home";
var btnHome:SimpleButton = createBtn(homeBtnText);
btnHome.x = 500;
btnHome.y = 500;
addChild(btnHome);
function createBtn(btnText:String):SimpleButton
{
var ovCol:uint = Color.interpolateColor(thirdColour,0xFFFFFF,0.3);
var dnCol:uint = Color.interpolateColor(thirdColour,0x000000,0.3);
var btn:SimpleButton = new SimpleButton();
btn.upState = createLabel(thirdColour,btnText);
btn.overState = createLabel(ovCol,btnText);
btn.downState = createLabel(dnCol,btnText);
btn.hitTestState = btn.upState;
return btn;
}
function createLabel(colour:uint, btnText:String):TextField
{
var txt:TextField = new TextField();
txt.width = 20;
txt.height = 5;
var navButton:TextFormat = new TextFormat();
navButton.font = "Arial";
navButton.color = colour;
navButton.size = 14;
navButton.align = TextFormatAlign.CENTER;
txt.defaultTextFormat = navButton;
txt.text = btnText;
txt.selectable = false;
return txt;
}
View Replies !
View Related
Creating A Global Function In A Class
I want to create a function inside a class that can be accessed globaly. I have tried this:
Code:
public function myFunction(){
//do stuff
}
I have created some code for a button:
Code:
btn_theButton.onRelease = function() {
myFunction()
}
It does not work. I tried to add _global to the front of the function too, but it caused a syntax error.
View Replies !
View Related
Creating Class Instances At Different Depths
I have a custom class called line that takes two sets of co ordinates and draws a line between them.
The class uses _root.createEmptyMovieClip() to make a container to draw in to but I need it to draw in to other movies on the stage in a similar way to createEmptyMovieClip() eg _root.childClip1.childClip2.line=new Line(x1,y1,x2,y2);
I have tried createEmptyMovieClip(), this.createEmptyMovieClip(), _parent.createEmptyMovieClip() etc but with no joy.
How can my Line constructor function get the path information from the declaration or do I have to pass it as a parameter?
View Replies !
View Related
Creating A Dynamic Button Class
Hi all. I'm trying to create a button class that has some properties such as scale that can be coded at runtime. The tutorial I found hard codes the scale amount into the class, but I would like to be able to create a new instance of the button class in Flash, and say on the main timeline, define my variables for scale...and pass these to the class file. I'm running into an "1120" error message. I have attached the original working code.
Thanks.
Attach Code
package scott.buttons
{
import flash.display.MovieClip;
import flash.events.MouseEvent;
public class scaleButton extends MovieClip
{
private var _origXScale:Number;
private var _origYScale:Number;
public function scaleButton()
{
_origXScale = this.scaleX;
_origYScale = this.scaleY;
this.addEventListener(MouseEvent.ROLL_OVER, grow);
this.addEventListener(MouseEvent.ROLL_OUT, shrink);
}
public function grow(event:MouseEvent):void
{
this.scaleX *= 1.5;
this.scaleY *= 1.5;
}
public function shrink(event:MouseEvent):void
{
this.scaleX = _origXScale;
this.scaleY = _origYScale;
}
}
}
View Replies !
View Related
Creating Custom Class MovieClips
Hi --
I make classes that extend movie clip, but I want to dynamicaly create instances of this class, so I really create MovieClips, but with the added features of the class. How should I create this instances? I want 'this' to be the root of this new movieclip with added features--- It's really giving me a headache, so please help.
View Replies !
View Related
Creating A Class To Extend Math
i have a function that i wrote in flash mx, and now that i'm using flash mx 2004, i'm going to have to use a class.
the function is like this:
ActionScript Code:
//as 1.0:function formatNumber(numberToFormat, decimalPlaces) {//}
how would i format that to put it into a class that extends the Math setion of as 2.0?
View Replies !
View Related
|