Write Property In A Class
hi all,
i want to write a class that will allow or restrict typing the "0" key in a TextField. i mean
i want to use it like this:
ActionScript Code: myTxt.allowZero = true or false
ActionScript.org Forums > ActionScript Forums Group > ActionScript 2.0
Posted on: 04-24-2007, 08:08 AM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
ReferenceError: Error #1074: Illegal Write To Read-only Property Array
I'm really sorry if this ends up a no brainer. I'm new to both AS3 and OOP and have spent the last 4 hours getting nowhere.
the code is being used as a document class in an fla (nothing else in the fla yet).
the boiled down code is:
package
{
import flash.display.Sprite;
public class SimpleMenu extends Sprite
{
public var btnData:Array;
public function SimpleMenu():void;
{
btnData:Array=new Array("Home","About us","Projects","Clients","Press","Brochure");
trace (btnData);
}
}
}
the output says:
ReferenceError: Error #1074: Illegal write to read-only property Array on global.
at SimpleMenu$cinit()
at global$init()
I've tried every way round that I can think off including the stupid ones.
I've googled it but the errors reported there seem much more complex.
How To Write A Static Class?
Hi, im familiar working with classes.
Like this:
Code:
package {
public class ClassA {
public function ClassA() {
}
public function doSomeThing() {
}}}
And then to use it:
Code:
var c:ClassA = new ClassA();
c.doSomeThing();
Problem is, I want a class i can use like this, with no instanciation:
Code:
ClassA.doSomeThing();
I believe its called a static class, can someone help med with this?
Thanks in advance...
How Do I Write The Listener In A Class?
I want to add a listener to two textfields in an mc, not sure how to change the function to work properly in a class. The mc has a class associated to it. I have included the code below.
Thanks for any help
The error I get for each function
Code:
Line 23: '(' expected
function description.onChanged(textfield_txt:TextField) {
Line 20: The same member name may not be repeated more than once.
function titlename.onChanged(textfield_txt:TextField) {
Code:
class Note extends MovieClip {
var x:Number;
var y:Number;
public var titlename:TextField;
public var description:TextField;
public var txtListener:Object = new Object();
public function Note() {
titlename.value = "Enter Your Title";
description.value = "Enter Your Description";
trace("+++++++");
titlename.addListener(txtListener);
description.addListener(txtListener);
}
function setInfo() {
}
function getInfo() {
}
function titlename.onChanged(textfield_txt:TextField) {
trace(textfield_txt._name+" changed");
};
function description.onChanged(textfield_txt:TextField) {
trace(textfield_txt._name+" changed");
};
function txtListener.onChanged(textfield_txt:TextField) {
trace(textfield_txt._name+" changed and notified myListener");
};
}
How Do I Write The Listener In A Class?
I want to add a listener to two textfields in an mc, not sure how to change the function to work properly in a class. The mc has a class associated to it. I have included the code below.
Thanks for any help
The error I get for each function
Code:
Line 23: '(' expected
function description.onChanged(textfield_txt:TextField) {
Line 20: The same member name may not be repeated more than once.
function titlename.onChanged(textfield_txt:TextField) {
Code:
class Note extends MovieClip {
var x:Number;
var y:Number;
public var titlename:TextField;
public var description:TextField;
public var txtListener:Object = new Object();
public function Note() {
titlename.value = "Enter Your Title";
description.value = "Enter Your Description";
trace("+++++++");
titlename.addListener(txtListener);
description.addListener(txtListener);
}
function setInfo() {
}
function getInfo() {
}
function titlename.onChanged(textfield_txt:TextField) {
trace(textfield_txt._name+" changed");
};
function description.onChanged(textfield_txt:TextField) {
trace(textfield_txt._name+" changed");
};
function txtListener.onChanged(textfield_txt:TextField) {
trace(textfield_txt._name+" changed and notified myListener");
};
}
1195: Error Trying To Write A Class.
I have just started to write a class in AS3 and have hit a snag straight away. Here is the code:
package{
import flash.net.LocalConnection
public class Tpanel
{
public var lc:LocalConnection = new LocalConnection();
public var MasterDomain:String = lc.domain();
public var port:Number = 10101
}
}
I get the following error:
1195: Attempted access of inaccessible method domain through a reference with static type flash.net:LocalConnection.
Can some please decode and tell me why this does not work in AS3 as it works fine in AS2. I will be having this issue often unless I learn what I am trying to do incorrectly.
Thanks in Advance
Button Effects - Write A Class Or Not?
Hi all,
in building a prototype, I took the easy path for animating a button and simply attached movie clips to the up/over/down/hit states (no chuckles from the peanut gallery). I decided I to go ahead with the style, but don't want to leave clips on the hit states for various reasons. In general, I use movie clips instead of buttons.
Now that I'm going to convert to movie clips for production, I wonder if it might be better to create a custom class to handle some complicated actions, e.g., things that would take multiple functions if scripted in the FLA itself. For example, I'd like the button to have an animation that fades out on rollout, and picks up where it left off if rolled over before the fade completes. This can't be done with typical button states (the clip disappears as expected).
I imagine the class would allow me to react to mouse events on the button, as well as choose a particular animation/effect from my library, and have some kind of persistence for the down state.
Any thoughts on approaching this? I am starting to work on this as a set of functions, but have not had any experience actually writing classes.
Help In Write An ActionScript Class Which Overloads SetMovie
Hi,
I Need help in write an ActionScript class which overloads setMovie.
I am trying to write a class which overload setMovie. But I can't get the following code to compile, can you please help me?
Thank you.
class Rectangle extends MovieClip {
private var _nWidth:Number;
private var _nHeight:Number;
static var app : Rectangle;
// Declare the nested instance
// as a property.
private var mcShape:MovieClip;
function Rectangle() {
trace("A Rectangle");
}
public function setDimensions(nWidth:Number,
nHeight:Number):Void
{
trace("setDimensions");
_nWidth = nWidth;
_nHeight = nHeight;
// Since you've declared mcShape as a
// property, you can then reference it.
mcShape._width = nWidth;
mcShape._height = nHeight;
}
public function toString():String {
trace("toString");
var sDescription:String = "A Rectangle ";
sDescription += "with dimensions: ";
sDescription += String(_nWidth) + " X ";
sDescription += String(_nHeight);
return sDescription;
}
// entry point
static function main(mc) {
app = new Rectangle();
app.prototype.setMovie = function (_video_id, image_url, movie_url, l, _track_id, eurl, append_vars) {
trace("setMovie");
}
app.setMovie("1234", "abc", "def", "1234", "abc", "def", "efg");
}
}
How To Add New Property To Exsiting Class?
Hi people,
I know how to extend classes and add new methods.. but can't seem to figure out how I can add a new property to the movie clip constructor.. any ideas?
Thnx,
Mc
As2.0 - Class Property Problem
I'm having problems with a class I have created to handle some web service interaction in a flash movie.
Basically, I call the web service, pass it in to the class. The class gathers all the properties defined in the service, then I simpy use the class to perform actions within my flash movie.
The code for the class is:
Code:
class Portal
{
private var sCopyLine:String;
private var sLogoURL:String;
public function Portal(ws:Object)
{
var obj = ws.GetPortal();
obj.onResult = _setObj;
}
public function _setObj(result:Object)
{
sCopyLine = result.CopyrightLine;
sLogoURL = result.Logo;
}
public function getCopyrightLine():String
{
return sCopyLine;
}
public function getLogo():String
{
return sLogoURL;
}
public function toString():Void
{
}
}
The code within my .fla file is:
Code:
import mx.services.*;
// selection of wsdl URI's
function getWSDL(uri:String)
{
trace("within getWSDL calling on '" + uri + "'");
if(uri == "portal")
wsdlSelect = "http://mywebservice.aspx";
return wsdlSelect;
}
// create web service
var wsdl:String = getWSDL("portal");
var wsPortal:WebService = new WebService(wsdl);
var objPortal:Portal = new Portal(wsPortal);
When I call:
Code:
var logo:String = objPortal.getLogo();
Or the same format for 'getCopyrightLine()', the returned string is always 'undefined'. I can't understand why because I've tried tracing the value of the web service passed in to the class and everything shows up right, but when I try to call the method on the class from my .fla file (outside of the class), the return value for 'sCopyLine' or 'sLogo' is - again - 'undefined'.
Any ideas?
AS2 Class: Method Don't See Property
If have a MusicFile class that I'll use to control sound from mp3-file. I work in FAME SDK.
Code:
class game.MusicFile extends game.MusicObject {
private var mp3file:Sound
public function MusicFile () {
}
/*
* loading file (not finished yet)
*/
public function load(mp3fileLocation:String):Void {
TRACE(Flashout.INFO + "mp3 started loading");
var z = scopeRef.createEmptyMovieClip("mp3fileContainer", scopeRef.getNextHighestDepth());
mp3file = new Sound(scopeRef.mp3fileContainer);
TRACE(Flashout.DEBUG + "setting onLoad");
mp3file.onLoad = this.onLoad;
TRACE(Flashout.DEBUG + "onLoad set");
mp3file.loadSound("music.mp3", false);
}
public function startPlay():Void {
TRACE(Flashout.DEBUG + "this is mp3file="+mp3file);
mp3file.start();
TRACE(Flashout.DEBUG + "mp3 playing");
}
private function onLoad(success:Boolean):Void {
var suc = success ? "successfully" : "not successfully";
TRACE(Flashout.DEBUG + "onLoad called. loaded "+suc);
TRACE(Flashout.DEBUG + scopeRef);
if (success) {
TRACE(Flashout.DEBUG + instanceof(this));
TRACE(Flashout.INFO + "mp3file=" + mp3file);
this.startPlay();
} else {
TRACE(Flashout.ERROR + "mp3 not loaded");
}
}
}
When I try to compile it, it traces:
[45:14:786] info: game.Game.Game()
Application started
[45:14:786] info: game.MusicFile.load()
mp3 started loading
[45:14:786] debug: game.MusicFile.load()
setting onLoad
[45:14:786] debug: game.MusicFile.load()
onLoad set
[45:14:997] debug: game.MusicFile.onLoad()
onLoad called. loaded successfully
[45:14:997] debug: game.MusicFile.onLoad()
_level0
[45:14:997] debug: game.MusicFile.onLoad()
undefined
[45:15:007] info: game.MusicFile.onLoad()
mp3file=undefined // what da f#ck???
why this method don't see 'mp3file' property? where am I wrong?
please, help me. work had stuck and I have no idea, how to solve this problem.
Easing As A Property In A Class
I'm curious how I would be able to use easing as a property.
As it stands I have:
Code:
public var transType = Strong.easeOut
I was thinking that I would be able to access it with:
Code:
someVar.transType = Elastic.easeIn;
Unfortunately I get the error "1120: Access of undefined property Elastic."
The idea is that if I choose to use a different easing method, I just change the transType rather than rewriting or changing the class.
Easing As A Property In A Class
I'm curious how I would be able to use easing as a property.
As it stands I have:
Code:
public var transType = Strong.easeOut
I was thinking that I would be able to access it with:
Code:
someVar.transType = Elastic.easeIn;
unfortunately I get the error "1120: Access of undefined property Elastic."
UrlLoad To Class Property
I'm attempting to load data from a url into a variable. I've created the following custom class:
ActionScript Code:
package {
import flash.events.*;
import flash.net.*;
public class ten {
private var dataLoader:URLLoader;
public var dats:String;
public function ten():void {
dataLoader = new URLLoader();
dats = new String();
dataLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
dataLoader.addEventListener(Event.COMPLETE, dataLoadHandler);
dataLoader.addEventListener(IOErrorEvent.IO_ERROR, dataIOErrorHandler);
dataLoader.load(new URLRequest("myurlhere"));
}
private function dataLoadHandler(event:Event):void {
var loader:URLLoader = URLLoader(event.target);
dats = dataLoader.data;
}
}
}
And I'm calling it in my fla as follows:
ActionScript Code:
var t:ten = new ten();
trace(t.dats);
But t.dats doesn't return any data. The only exception is if I trace t.dats from within the dataLoadHandler function. What am I doing wrong?
Sound As Property In Class?
I have a class where a property is a sound variable, but it doesn't work.
Is this possible and I'm doing something wrong or will this never work?
Here is an example:
ActionScript Code:
class exampleClass{
private var _sound:Sound
function exampleClass(){
this._sound = new Sound()
}
function loadSong(s:String){
this._sound.loadSound(s)
}
}
Anyonegot any ideas?
Class Instance Name Property
is there any way, within a class definition, to access the instance name of the class?
as in, say you have a class "playerObject", and you instantiate an instance of it like usual
player:playerObject = new playerObject();
is there an inbuilt property or variable i can access within the playerObject class code to return "player"?
if, in the constructor, i trace(this) it returns [object Object], i tried things like this.name, this._name etc, of course they didnt work...
any help would b appreciated
Easing As A Property In A Class
I'm curious how I would be able to use easing as a property.
As it stands I have:
Code:
public var transType = Strong.easeOut
I was thinking that I would be able to access it with:
Code:
someVar.transType = Elastic.easeIn;
Unfortunately I get the error "1120: Access of undefined property Elastic."
The idea is that if I choose to use a different easing method, I just change the transType rather than rewriting or changing the class.
[F8] Proper Class Property Reference
I rarely work on anything large enough to justify using AS2.0 so my classes could definitely be written better.
Lets say I have a class assign an onEnterFrame function to a movieclip who's name was passed to the class during instantiation.
If as part of that enterFrame, I want the clip to reference a property of the class, I normally attach a reference to the class to the clip.
For example
Code:
class myClass{
private var __someClip:MovieClip;
private var __someNumber:Number;
public function myClass(someClip, someNumber){
this.__someClip = someClip;
this.__someNumber = someNumber;
init();
}
private function init(){
__someClip.boss = this;
__someClip.onEnterFrame = function(){
trace(this.boss.__someNumber);
}
}
}
Is assigning a reference back the class the best way to do this?
[F8] Help Please Can A Class Have An Array As A Property? Having Troubles.
Okay, the pertinent information at the start of the class:
PHP Code:
class Ship extends MovieClip {
//private variables
private var _gridsize
private var _gridrow:Number = 0;
private var _gridcol:Number = 0;
private var _health:Number = 9;
//public variables
public var movequeue:Array = Array();
public var beingmoved = false;
public var _facing:Number = 90;
.....
I left in a bunch of the internal variables just so people can see how I was declaring and initializing them.
The problem is with the movequeue property/variable. I have tried declaring it with 'new Array()' at the end as well.
What is happening is that later on in the class file I have method that pushes a value into the moveque. Stripped down, the problem part is:
PHP Code:
private function move1() {
this.movequeue.push("somevalue")
}
In my main code the problem is that after this function call, all my classes of type 'Ship' are assigned the same movequeue.
So if I had ship objects 'playership' and 'playership2', if I did this:
PHP Code:
playership.move1()
trace(playership.movequeue)
trace(playership2.movequeue)
They would both trace "somevalue".
Is my error that you just can't have an array as a property in a class? Because it is a class itself? But a string and a number are classes in AS as well, aren't they?
I am confused and very annoyed.
I was debugging the wrong part of the code for about 2 hours over this issue until I found out that it was the rather simple act of doing the push itself was where the problem was cropping up.
Please help, this is driving me nuts!
Access Of Undefined Property From A Class
PHP Code:
package {
import flash.display.MovieClip;
import flash.events.Event;
public class DumbClass extends MovieClip {
var dumbXS:Number = 0;
var dumbYS:Number = 0;
var dumbACC:Number = 0.6;
var dumbDEC:Number = 0.92;
public function DumbClass() {
this.addEventListener(Event.ENTER_FRAME, DumbMove);
}
public function DumbMove(evt:Event):void {
//Increases Speed
this.x += dumbXS;
this.y += dumbYS;
//Reference to a MovieClip on stage called "user".
if (user.y < this.y) {
dumbYS -= dumbACC;
}
//Reference to a MovieClip on stage called "user".
if (user.y > this.y) {
dumbYS += dumbACC;
}
//Reference to a MovieClip on stage called "user".
if (user.x < this.x) {
dumbXS -= dumbACC;
}
//Reference to a MovieClip on stage called "user".
if (user.x > this.x) {
dumbXS += dumbACC;
}
///Decrease Speed
dumbYS *= dumbDEC;
dumbXS *= dumbDEC;
}
}
}
I get an error that "user" is an undefined property even though its on the stage any ideas how I can fix this? :crying:
How To Access Property Of A Defined Class For Swf
I have a car.fla file. I created a class called Car inside car.as, which handles the manipulation of the symbols in library of car.fla. So car.fla is linked to car.as.
Class Car is extended from MovieClip.
In my main code, I am loading up car.swf by doing this:
var url = new URLRequest(xampp://directory/to/car.swf);
var carSWF = new Loader();
carSWF.contentLoaderInfo.addEventListener(Event.IN IT, this.onURLLoaded);
carSWF.load(url);
But here is my problem. I want to be able to access a property of Car. Say I have a property called var backWheel.
class Car{
var backWheel:Number;
}
How do I access this property?
I tried doing:
var url = new URLRequest(xampp://directory/to/car.swf);
var carSWF = new Loader();
carSWF.contentLoaderInfo.addEventListener(Event.IN IT, this.onURLLoaded);
carSWF.load(url);
var myCar:Car = carSWF.content;
trace("myWheel: "+myCar.backWheel);
This returned an error "Cannot access a property or method of a null object reference." Any suggestions?
Object Property Via A Class, Is There A Tutorial?
I am less than 3 weeks into both Flash and AS3. My main problem is that when I try to apply what I read or see in a video to a class I get lots of problems if I don't have the exact setup they did.
Can someone make a tutorial that shows what needs to be added to the class and timeline to target specific movieclips? For example, with the information I provide below, what would need to be added to target each level of the hierarchy:
FLA file: Geometry.fla [b]document class:[/B] none, left field blank
AS file: MoveMC.as package: lesson
1st MovieClip: (library name) mRect base class: lesson.MoveMC class: Rectangle instance names(3):mRect1, mRect2, mRect3 nesting: all are nested in a MovieClip that is on the stage with an instance name of mBorder
2nd MovieClip: (library name) mTri base class: lesson.MoveMC class: Triangle instance names(3):mTri1, mTri2, mTri3 nesting: all are nested in a MovieClip that is on the stage with an instance name of mBorder
So what I would love to know is the following:
What needs to go in the MoveMC.as (and timeline?) file in order to change the .x property of all movieclips with:
note: answer 1)-3) seperately please
1) base class of lesson.MoveMC
2) class name of Rectangle
3) instance name of mRect3
please mention any variable declaration and importing that would be needed along with the actual property assignment code
How Do I Access A Property Of Document Class?
Hi
I have a document class and I declare a public variable in it. I want to access this from another class. I thought that there was a way but I cannot seem to find it.
Thanks in advance
Pedro.
GetSet ID Property In Thumnail Class
Hi Everybody!!
I'm building a portfoliosite in AS 3.0 with images loaded from a XML file and I found a really good script which I adapted for my needs; I still have one problem to solve; When you click on the thumbnail the big photo opens; so far so good; but now I want to go from this big photo to the next big photo without going back to the thumbnails; so I want to add buttons (no problems there) to navigate. But I have to know on which photo I am to go on from there; so I know I have to declare the getSet method in the thumbnail class to get the ID property of the image I'm on and go on from there but I never did this before and I wouldn't know where to start! Any suggestions??? ideas??? help???
Thanks!!!!
here's the code with the thumbnailclass;
ActionScript Code:
package {
import flash.display.Sprite;
import fl.containers.UILoader;
import caurina.transitions.*;
import flash.events.MouseEvent;
public class Thumbnail extends Sprite {
private var nume:String;
private var url:String;
private var id:int;
private var loader:UILoader;
function Thumbnail(source:String,itemNr:int,numeThumb:String):void {
url = source;
id = itemNr;
this.nume = numeThumb;
drawLoader();
/*addEventListener(MouseEvent.MOUSE_OVER,onOver);
addEventListener(MouseEvent.MOUSE_OUT,onOut);*/
/*scaleThumb();*/
}
private function drawLoader():void {
loader = new UILoader();
loader.source = url;
loader.mouseEnabled = false;
loader.x = -50;
loader.y = -50;
addChild(loader);
}
And this is the complete as code;
ActionScript Code:
import fl.containers.UILoader;
import caurina.transitions.*;
//---------loading the external xml file-------
var urlRequest:URLRequest = new URLRequest("portraits.xml");
var urlLoader:URLLoader = new URLLoader();
var myXML:XML = new XML();
var xmlList:XMLList;
myXML.ignoreWhitespace = true;
urlLoader.addEventListener(Event.COMPLETE,fileLoaded);
urlLoader.load(urlRequest);
//--------holds the paths to the thumbnails-------
var arrayURL:Array = new Array();
//--------holds the paths to the big photos-------
var arrayName:Array = new Array();
//--------holds the thumbnail objects-------
var holderArray:Array = new Array();
//--------represents the number of collumns-------
var nrColumns:uint = 5;
//-------represents the container of our gallery
var sprite:Sprite = new Sprite();
addChild(sprite);
var thumb:Thumbnail;
//-------- the thumbnails container-------
var thumbsHolder:Sprite = new Sprite();
sprite.addChild(thumbsHolder);
//-------- the photoLoader container-------
var loaderHolder:Sprite = new Sprite();
loaderHolder.graphics.beginFill(0xffffff,1);
loaderHolder.graphics.drawRect(0,0,900,600);
loaderHolder.graphics.endFill();
loaderHolder.x = 1000;
loaderHolder.y = 120;
sprite.addChild(loaderHolder);
//-------- loads the big photo-------
var photoLoader:UILoader = new UILoader();
photoLoader.width = 900;
photoLoader.height = 600;
photoLoader.y = 0;
photoLoader.x = 0;
photoLoader.buttonMode = false;
loaderHolder.addChild(photoLoader);
//-----loads a button???test by MAD-------
var nextButton:Sprite = new Sprite();
nextButton.graphics.beginFill(0x00ffff);
nextButton.graphics.drawCircle(100,100,50);
nextButton.graphics.endFill();
nextButton.alpha = 0;
nextButton.buttonMode = true;
nextButton.addEventListener(MouseEvent.CLICK,onClickBack);
sprite.addChild(nextButton);
/* we loop through the xml file
populate the arrayURL, arrayName and position the thumbnails*/
function fileLoaded(event:Event):void {
myXML = XML(event.target.data);
xmlList = myXML.children();
for (var i:int=0; i<xmlList.length(); i++) {
var picURL:String = xmlList[i].url;
var picName:String = xmlList[i].big_url;
arrayURL.push(picURL);
arrayName.push(picName);
holderArray[i] = new Thumbnail(arrayURL[i],i,arrayName[i]);
holderArray[i].addEventListener(MouseEvent.CLICK,onClick);
holderArray[i].name = arrayName[i];
holderArray[i].buttonMode = true;
if (i<nrColumns) {
holderArray[i].y = 200;
holderArray[i].x = i*120+200;
} else {
holderArray[i].y = holderArray[i-nrColumns].y+90;
holderArray[i].x = holderArray[i-nrColumns].x;
}
thumbsHolder.addChild(holderArray[i]);
}
}
//----handles the Click event added to the thumbnails--
function onClick(event:MouseEvent):void {
photoLoader.source = event.currentTarget.name;
Tweener.addTween(thumbsHolder, {x:0, time:0, transition:"linear"});
Tweener.addTween(loaderHolder, {x:0, y:0, time:0, transition:"linear"});
Tweener.addTween(thumbsHolder, {alpha:0, time:0, transition:"linear"});
Tweener.addTween(loaderHolder, {alpha:1, time:0, transition:"linear"});
Tweener.addTween(nextButton, {x:0, y:0, time:1, transition:"linear"});
Tweener.addTween(nextButton, {alpha:0.3, time:10, transition:"linear"});
}
//----handles the Click event added to the photoLoader----
function onClickBack(event:MouseEvent):void {
Tweener.addTween(thumbsHolder, {x:0, time:0, transition:"linear"});
Tweener.addTween(loaderHolder, {x:1000, time:0, transition:"linear"});
Tweener.addTween(thumbsHolder, {alpha:1, time:0, transition:"linear"});
Tweener.addTween(loaderHolder, {alpha:0, time:0, transition:"linear"});
Tweener.addTween(nextButton, {alpha:0, time:0, transition:"linear"});
Tweener.addTween(nextButton, {x:0, time:0, transition:"linear"});
}
How To Detect If A Property Of A Class Is Dynamic?
Hi
I have a datagrid that has a column for each property of a given object. This is a dynamic class and properties get added to this object. I need to be able to tell which properties are dynamic and which are not. I have the object and the fieldName, as a String. Anyone know how to do this?
thanks
craig
Accessing Text Property In Class
I'm having problems accessing the .text property of text fields in my object. When I try to reference the text field outside of function responsible for creating the text field I get "1120: Access of undefined property titleField." Any insight is appreciated. Thanks!
Attach Code
//constructor function
public function Panel(panelTitle:String,
panelWidth:Number,
panelHeight:Number,
panelX:Number,
panelY:Number,
panelType:String = "",
panelText:String = ""):void {
this.panelTitle = panelTitle;
this.panelWidth = panelWidth;
this.panelHeight = panelHeight;
this.panelX = panelX;
this.panelY = panelY;
this.panelType = panelType;
this.panelText = panelText;
}
//add/format the title field
protected function addTitle():void {
var titleFormat = new TextFormat();
titleFormat.font = "Helvetica";
titleFormat.bold = true;
titleFormat.color = 0x444444;
titleFormat.size = 11;
titleFormat.letterSpacing = 2;
var titleField:TextField = new TextField();
titleField.defaultTextFormat = titleFormat;
titleField.x = getPanelX() + 5;
titleField.y = getPanelY() + 5;
titleField.autoSize = TextFieldAutoSize.LEFT;
titleField.name = "titleField";
setPanelTitle(titleField, getPanelTitle());
addChild(titleField);
}
protected function addTextArea():void {
var panelTextArea = new TextArea();
panelTextArea.setSize(getPanelWidth() - 10, getPanelHeight() - 25);
panelTextArea.move(getPanelX() + 5, getPanelY() + 20);
panelTextArea.editable = false;
setPanelText(panelTextArea, getPanelText());
addChild(panelTextArea);
}
//declare get/set methods
public function getPanelTitle():String {
return panelTitle;
}
public function setPanelTitle(theTextField:TextField, theText:String = ""):void {
theTextField.text = theText;
}
public function getPanelText():String {
return this.panelText;
}
public function setPanelText(theTextArea:TextArea, theText:String = ""):void {
theTextArea.text = theText;
}
Class Instance Property Disappears....
Hi, I'm having a problem with some disappearing instance properties... That is, when another instance is created, previous is lost somewhere (:
Actually after intensive debugging, all I can say is that instance is there, but the movie clip attached to one of it's properties is gone. Well, not gone In debugger window everythig is still there, but on screen last movieclip disappears when next one is created /I've marked that spot in code as 'PROBLEM LOCATION'/ tracing values gives me no clue about what's going on - everithig looks as it shoud. All the values are correct, structure is good, yet my MovieClips ain't showing, except the last one...
If someone could find what's wrong with this, I'd be greatfull...
Sasxa
Here's the code. I reduced it as much as I could, 'though I left something more then it's needed to isolate problem - maybe someone gets inspiration ((:
Code:
// Class definition...
dynamic class Engine {
static var mcHolder:MovieClip;
// constructor function
function Engine(nDepth:Number, nStageDepth:Number) {
Engine.nDepth = nDepth;
Engine.nFocalLength = 350;
Engine.mcHolder = _root.createEmptyMovieClip("Stage3D", Engine.nDepth);
Engine.mcHolder._x = Stage.width / 2;
Engine.mcHolder._y = Stage.height / 2;
//
}
}
// Class definition...
dynamic class Object3D extends Engine {
static var nInstances:Number;
var sType:String;
var mcContent:MovieClip;
// constructor function
function Object3D() {
// insertation point
this.nX = 0;
this.nY = 0;
this.nZ = 0;
Object3D.nInstances++;
this.mcContent = mcHolder.attachMovie("soemthing", "soemthing" + Object3D.nInstances, Object3D.nInstances);
}
function setPosition() {
var nScaleRatio:Number = Engine.nFocalLength / (Engine.nFocalLength + this.nZ);
// adjusting screen X and Y values based on object coordinates
this.mcContent._x = (this.nX - Engine.nCameraX) * nScaleRatio;
this.mcContent._y = (this.nY - Engine.nCameraY) * nScaleRatio;
// adjusting scale X and Y values
this.mcContent._xscale = 100 * nScaleRatio;
this.mcContent._yscale = 100 * nScaleRatio;
}
}
// Stage,,,,
myStage = new Engine(50, 500);
Engine.nCameraX = 0;
Engine.nCameraY = 0;
//
Object3D.nInstances = 0;
myObjects = new Array();
var nObjects = 3;
for (i = 0; i < nObjects; i++) {
// PROBLEM LOCATION //
myObjects[i] = new Object3D();
// PROBLEM LOCATION //
myObjects[i].nX = 20 * i;
myObjects[i].nY = 50 * i;
myObjects[i].nZ = 75 * i;
myObjects[i].setPosition();
}
Update A Property Of All Instances From A Class
Would that be as simple as updating a class's static property value? Or would you have to regenerate all the instances to receive and utilize the new value (assuming some instances had already been created)?
Access Of Undefined Property From A Class
PHP Code:
package { import flash.display.MovieClip; import flash.events.Event; public class DumbClass extends MovieClip { var dumbXS:Number = 0; var dumbYS:Number = 0; var dumbACC:Number = 0.6; var dumbDEC:Number = 0.92; public function DumbClass() { this.addEventListener(Event.ENTER_FRAME, DumbMove); } public function DumbMove(evt:Event):void { //Increases Speed this.x += dumbXS; this.y += dumbYS; //Reference to a MovieClip on stage called "user". if (user.y < this.y) { dumbYS -= dumbACC; } //Reference to a MovieClip on stage called "user". if (user.y > this.y) { dumbYS += dumbACC; } //Reference to a MovieClip on stage called "user". if (user.x < this.x) { dumbXS -= dumbACC; } //Reference to a MovieClip on stage called "user". if (user.x > this.x) { dumbXS += dumbACC; } ///Decrease Speed dumbYS *= dumbDEC; dumbXS *= dumbDEC; } }}
I get an error that "user" is an undefined property even though its on the stage any ideas how I can fix this?
Setting Property Of An Object In Another Class
Hello,
I have a little problem of understanding on how to set properties of an object that is in another class. The firstclass draws a circle and set's it's alpha to a random number.
from the secondclass i call the public function in the fristclass which sets a new random alpha. i can trace the call of the function but the alpha is still the same.
can me anyone explain what i do wrong?
Code:
package {
import flash.display.Sprite;
public class FirstClass extends Sprite{
private var _cont:Sprite;
public function FirstClass() {
_cont = new Sprite();
_cont.graphics.beginFill(0xFF0000, 1);
_cont.graphics.drawCircle(30, 30, 10);
_cont.graphics.endFill();
addChild(_cont);
setAlpha();
}
public function setAlpha():void {
trace(_cont);
_cont.alpha = Math.random() * 1;
}
}
}
and the second class:
Code:
package {
import flash.display.Sprite;
import flash.events.MouseEvent;
import FirstClass;
public class secondClass extends Sprite{
private var _btn:Sprite;
private var _first:FirstClass;
public function secondClass() {
_first = new FirstClass();
_btn = new Sprite();
_btn.graphics.beginFill(0x00FF00, 1);
_btn.graphics.drawCircle(30, 80, 10);
_btn.graphics.endFill();
_btn.addEventListener(MouseEvent.CLICK, onClick);
addChild(_btn);
}
public function onClick(e:MouseEvent):void {
_first.setAlpha();
}
}
}
Returning The Class Object That A Property Belongs To
Hi all,
say I have a class with a sprite as one of its properties...
ActionScript Code:
public class PropertiesClass
{
internal var _sprite:Sprite;
internal var _someOtherProp:Number;
public function PropertiesClass():void
{
_sprite = new Sprite();
_someOtherProp = 42;
}
}
in another class I instantiate this class & add the sprite property to the display list & an event listener to it...
ActionScript Code:
public class DisplayClass extends Sprite
{
public function DisplayClass():void
{
var obj:PropertiesClass = new PropertiesClass()
this.addChild(obj._sprite);
obj._sprite.addEventListener(MouseEvent.CLICK, clickHandler);
}
private function clickHandler(e:MouseEvent):void
{
trace(e.target.parent);
// I want to be able to get to the _someOtherProp value in the first class
}
}
the click handler trace refers to the display list of the DisplayClass, I would like to be able to access the other properties in the PropertiesClass object that _sprite is a member of.
My solution would be to make _sprite a movieclip instead (not a sealed class) then add a dynamic property to it which gives a reference back to the original class - seems to be a bit heavy handed tho with lots of un-needed overhead.
Thanks,
PMF
Assistance With _rotation Property For Tween Class
I know, I know, this is my first post, but I just found out about Kirupa a little while ago, and have really grown to appreciate what I have been learning from the site.
Here's my dilema, does anybody know if there is a way to use the _rotation property with the Tweening class to make a movie clip continually to rotate from it's current position instead of starting back at the original position and doing the same rotation again.
I'm trying to make an movie object rotate 90 degrees by clicking on a button and then when you click the button again, the movie rotates 90 more degrees. I don't want it to start over and do that same 90 degree rotation with the Tween class. Thanks.
MXML Component As Actionscript Class Property
I am trying to create a custom actionscript component that has an HTTPService property that I define in MXML and pass to the "service" property of a DatabaseNavigator component. However I keep getting null object errors. Here is my code:
index.mxml
Code:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:db="database.containers.*" layout="absolute" width="700" height="700">
<mx:Style source="assetscss
scsadmin.css"></mx:Style>
<mx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.events.IndexChangedEvent;
import database.containers.DatabaseNavigator;
]]>
</mx:Script>
<mx:Fade id="fader" duration="1000" alphaFrom="1.0" alphaTo="0.0"/>
<mx:HTTPService id="databaseService" resultFormat="xml" method="POST" />
<db:DatabaseNavigator service="{databaseService}" host="localhost"/>
</mx:Application>
DatabaseNavigator.as
Code:
package database.containers
{
import mx.containers.TabNavigator;
import mx.controls.Alert;
import mx.events.FlexEvent;
import mx.rpc.events.ResultEvent;
import mx.rpc.http.mxml.HTTPService;
public class DatabaseNavigator extends TabNavigator
{
private var _host:String;
private var _username:String;
private var _password:String;
private var _database:String;
private var _service:HTTPService;
private var metaData:XMLList;
private var params:Object;
public function DatabaseNavigator()
{
super();
params = new Object();
addEventListener(FlexEvent.INITIALIZE, superInitHandler);
}
public function get host():String {
return _host;
}
public function set host(value:String):void {
_host = value;
}
public function get username():String {
return _username;
}
public function set username(value:String):void {
_username = value;
}
public function get password():String {
return _password;
}
public function set password(value:String):void {
_password = value;
}
public function get database():String {
return _database;
}
public function set database(value:String):void {
_database = value;
}
public function get service():HTTPService {
return _service;
}
public function set service(value:HTTPService):void {
_service = value;
}
private function superInitHandler(event:FlexEvent):void {
params.host = host;
params.username = username;
params.password = password;
params.database = database;
try {
if(!service) {
throw(new Error("Error: Databse service not specified"));
} else {
service.addEventListener(ResultEvent.RESULT, serviceResultHandler);
service.send(params);
}
} catch (error:Error) {
Alert.show(error.message);
}
}
private function serviceResultHandler(event:ResultEvent):void {
Alert.show(event.result.toString());
}
}
}
How Do You Make A Movieclip On The Stage A Property Of A Class?
I have a class with a movieclip as one of it's properties. In a FLA if I dynamically add the property to the class it works fine but if I explicitly declare it as a property in the class it throws a null object reference exception when I try and access it.
What am I missing or misunderstanding here?
Class Declaration Problem (an Array Property Issue)
Hello!
How to declare Array property in Class definition?
for example:
class book {
var title: String;
var number_of_pages: Number;
var pages: Array;
}
In debug, I can see title, number_of_pages, but no pages array?
There is some way to declare object's property that is array, but i just can't figure out by my own!
Thanks in advance!
Flash Can Write To Txt? [FLfile.write]? :confused:
Okay, a while ago I started a project for one computer. I needed a little database to store information. When I started out I was informed that flash cannot write to a txt file and that I would have to use php to do my bidding. Well.... I just found in F8 the FLfile.write command that says otherwise. I haven't tested it, but will. So what is the deal with this? What advantages are there to flash vs. php with writing to a txt file?
Code:
var URI = "file:///c|/temp/mydata.txt";
if (FLfile.write(URI, "xxx")) {
alert("Wrote xxx to " + URI);
}
if (FLfile.write(URI, "aaa", "append")) {
alert("Appended aaa to " + fileURI);
}
"Access Of Undefined Property" Error From Custom Class
I am trying to create a custom class of my AS3 XML News Ticker. I am getting the error "1120: Access of undefined property" for references to objects which are already on the stage i.e. not dynamically created. I am pretty sure that it is an encapsulation issue.
Please view the attached files. I will appreciate assistance with this problem as I will be providing the class on my blog once it is working.
"Access Of Undefined Property" Error From Custom Class
I am trying to create a custom class of my AS3 XML News Ticker. I am getting the error "1120: Access of undefined property" for references to objects which are already on the stage i.e. not dynamically created. I am pretty sure that it is an encapsulation issue.
Please view the attached files. I will appreciate assistance with this problem as I will be providing the class on my blog once it is working.
"Access Of Undefined Property" Error From Custom Class
I am trying to create a custom class of my AS3 XML News Ticker. I am getting the error "1120: Access of undefined property" for references to objects which are already on the stage i.e. not dynamically created. I am pretty sure that it is an encapsulation issue.
Please view the attached files. I will appreciate assistance with this problem as I will be providing the class on my blog once it is working.
Setting "onEnterFrame" Property With Class.
To my understanding, the following should create a continuous loop that traces "Looping" on every frame. Currently it doesn't work. Can anyone explain why?
I've got an external class DrawEngine.as like so:
PHP Code:
class DrawEngine extends MovieClip {
private function DrawEngine() {
this.onEnterFrame = this.main(); //- start main loop
}
private function main() {
trace("Looping");
}
}
In a new FLA file, I attach a movieclip from the library which has a linkage indentifier "test" and class instance of "DrawEngine."
PHP Code:
var myMc = this.attachMovie("test", "DrawEngineMc", 1);
Since the movieclip I've attached has a class instance of DrawEngine, the onEnterFrame property should (but doesn't) run main() on every frame tracing "Looping." Help!
Can't Write To A File Using File Class
hi every body
I wanna write into a file for logging purpose, but I always got an error when I write to the file ...
the code is:
--------------------------------------------------------
if(!logFile.isOpen)
logFile.open("text", "write")
var date = new Date();
if(logFile.canWrite){
trace(">> I will write ...");
var message = "TIME >> " + date.getDate().toString() + " : ERROR CODE >> " + infoObject.code + " : LINE NO >> " + infoObject.lineno.toString();
logFile.write(message);
logFile.flush();
}
logFile.close();
--------------------------------------------------------
I got an error says: File operation writeln failed
and also may say: File operation flush failed
thanx
Is Sound.position Even A Property Of The Sound Class?
i found tons of AS3 tutorials on how to make an mp3 player and all of them have playingSound.position which is supposed to return the current song position.. but when i try to use it i get an undefined property error.. and i expect that error cuz i didnt find any sound.position property in the official documentation.. or is there?
Get Property Visibility Set Property Visibilty
I am trying to work out some navigation on a site to make it more user friendly.
I have a number of buttons which when clicked set their correspoding graphic to visible and all the other relevant graphics to invisible.
This is so I can get the graphics to appear in the same place but only one visible at any time so no overlap.
What I already have is a rollover so that when the user rolls over the buttons the corresponding graphic will appear. Then dissappear on rollout. And the script to place my graphic in the right place and make it visible. Here is the script.
on (rollOver) {
setProperty("_root.drag0", _visible, "1");
setProperty("_root.drag1", _visible, "0");
setProperty("_root.drag2", _visible, "0");
}
on (rollOut) {
setProperty("_root.drag0", _visible, "0");
setProperty("_root.drag1", _visible, "0");
setProperty("_root.drag2", _visible, "0");
}
on (release) {
setProperty ("_root.drag0", _x , 323.4);
setProperty ("_root.drag0", _y , 360);
setProperty("_root.drag0", _visible, "1");
}
The bit I can't work out is how to get the graphic which has last been clicked and locked visible (rather than temporaly visible on rollover/out)to revert to being visible on the rollout of the other buttons.
I think I need to use the get property and set property but can't quite work out how to link the two so that it checks which graphic is visible before the rollover on a different button, makes it invisble on the rollover and reverts it back to being visible on the roll out.
Sorry That was long finding it hard to explain.
Thanks for any help you can offer. I am using flash mx 6.0.
Preloder ScaleX Property And X Property
Hi!
within the loader listener's progressevent I had my preloader mc update the scaleX property and works fine, thus, it moves and scales just like a preloader does until it reaches 100. My only concern is when scaleX updates the preloader mc 'x' location seems to be moving as well making the preloader clip looked liked it scales on both sides (both ends of the line). As i examined the preloader mc 'x' property it stays the same all throughout. This is weird.
anyone?
thank you in advance.
Tween Class: Can One Tween More Than One Property Using The Same Tween
I want to scale both the _xscale and the _yscale properties of a clip, using a single execution of the Tween Class. See example below:
Code:
import mx.transitions.Tween;
var myTween:Tween = new Tween(myMovieClip_mc, "_xscale", Strong.easeOut, myMovieClip_mc._xscale, 300, 5, false);
Since one property at a time must be passed as a string to the constructor, I tried the following code, but it does not work quite as flawless as I expected:
Code:
myTween.onMotionChanged = function() {
//trace( this.position );
myMovieClip_mc._yscale += (300 - myMovieClip_mc._yscale)/12;
};
Any suggestions?
Object.property.property ?
I'm making a movie that will read data from an object and build some rows and columns of radio buttons, but I'm having some trouble dealing with the objects that I'm using to store data on the _root.
Here's what I'm trying to test:
I have the following code on the root of my movie:
PHP Code:
radio_button_object = new Object ();
radio_button_object.row_2 = 2;
radio_button_object.row_2.radio_button_1 = true;
radio_button_object.row_2.radio_button_3 = true;
Within a movie clip named "radio_button", I've got the following code:
PHP Code:
myObj = eval ("_root." + this._name + "_object");
// inside a for loop I'm going through rows
// inside that for loop, I have another for loop that goes through columns
for (i...) {
for (j...) {
if (myObj ["row_" + i]) {
if (myObj ["row_" + i + ".radio_button_" + j]) {
(eval ("row_" + i + ".radio_button_" + j)).gotoAndStop ("selected");
}
}
}
}
I've tried:
PHP Code:
myObj ["row_" + i ["radio_button_" + j]]
and:
PHP Code:
myObj ["row_" + i] ["radio_button_" + j]
But I've had no luck.
Essentially, I'm looking for object.property.property, except that the object name and all property names are variables.
Can anyone help me out?
Thanks!
cooper
www.pigdogtoad.com
My Property Is Your Property.thankyou.
im trying to create a drag and drop where you drag the image to the left of the screen and if dropped more than half way across the stage the image has a word,but once dropped can also be dragged back to how it was originally. I was thinking its something to do with getting thexproperty(as its all horizontal)
I'm new to flash so would really appreciate anyones help,
ta.
Write To .txt
alright probably heard this before.
but i want to the user type their name in on my flash web site, and i want to store it into a .txt file or something. how do i get flash to write to a file.
don't make me switch to director.
thanks. =)
Better Way To Write This?
thanks in advance to those who offer help.
k. question is:
is there a better way to write the following:
// any one of 3 pieces on drop target cause visibility change
if (getProperty("/piece" add 1, _droptarget) eq "/target") {
setProperty ("/target", _visible, 0);
} else if (getProperty("/piece" add 2, _droptarget) eq "/target") {
setProperty ("/target", _visible, 0);
} else if (getProperty("/piece" add 3, _droptarget) eq "/target") {
setProperty ("/target", _visible, 0);
} else if (getProperty("/piece" add 1, _droptarget) ne "/target") {
setProperty ("/target", _visible, 1);
} else if (getProperty("/piece" add 2, _droptarget) ne "/target") {
setProperty ("/target", _visible, 1);
} else if (getProperty("/piece" add 3, _droptarget) ne "/target") {
setProperty ("/target", _visible, 1);
}
|