Actionscript 3 :: Returning A Property Of A Class Rather Than The Class Itself
Nov 30, 2011
In ActionScript 3, there are some classes that will represent a value rather than the class itself. It's hard to explain properly what I mean, so take this example:
I can use toString() to return any string desired when using trace(instance), is it possible to return other types of objects?For example, I may have this class:
public class List { private var _content:Array = []; public function add():void{} public function remove():void{} }
I normally need to make a getter that returns the _content, eg:
public function get content():Array{ return _content; }
So that I can do things like:
for each(var i:Object in myList.content)
Can I make myList in the above case actually return the value of content automatically? So that I can do like:
trace(myList); // item, item, item (similar output as tracing an array) for each(var i:Object in myList)
public class Example { public function Example () { }[code]............
You can see that the two last classes extend the first one, and both have the 'variable' property. In case that I have an instance of Example and I am sure it is also an ExtendedExample OR AnotherExtendedExample instance, is there some way to access the 'variable' property? Something like
function functionThatReceivesAnExtendedExample (ex:Example):void { if(some condition that I may need) { ex.func()
var environment:AvEnvironment = new AvEnvironment(...); addChild(environment); environment.addChild(new Terrain()); environment.addChild(new Player());
I am trying to access a public property from AvEniroments class through the Player class, however I'm getting an undefined property error (#119). I've tried the following:
this.x = AvEnvironment.xs // public property in this class this.x = parent.xs
I've also tried something like this:
var ev:AvEnvironment = AvEnvironment(parent); this.x = ev.xs
but I get a TypeError. Error #1009: Cannot access a property or method of a null object reference.
i am using xmllistcollection for displaying data in list. whenever i run my application data is display in list control, but this warning has displayed in console. How can i remove this warning warning: unable to bind to property 'xmlnode' on class 'XML' (class is not an IEventDispatcher)
now when i try to get the id form the Piece class like this it doesn't work, i've been looking at this for the better part of the past hour! what am i doing wrong?
ActionScript Code: var player1:Player = new Player("eddie"); player1.setPieces(); trace(player1.pieces[0].id);///why is this not working! getting undefined! // i tried datacasting i get null trace(Piece(player1.pieces[0].id));
I was wondering how do you access the stage property from a different class that's not the principal class tied to the fla? Essentially, I have main.as which calls another class menu.as, and I can't seem to be able to use the stage.stageWidth property from menu.as. What's the proper way to be able to use the stage property from any class? Do I have to import it separately each time?
I decided to turn this util into a class because I use it in almost all of my projects. Basically what it is is I import an XML file and it has all these HTML characters like & or and my function basically converts those strings of characters to its regular form ie: ['&' (&] or [' ' ( )]
so calling it in a FLA file would be something like this:
Code: var entity:DeEntitizeHTML = new DeEntitizeHTML("bob & jim"); and here is my class file: Code: class com.dop.DeEntitizeHTML { function DeEntitizeHTML(my_str)
[Code]....
how to return that value back to the var entity in my FLA.
Is there any method that returns the Class name of an instance as a String? I would like to then pass that String as the parameter into the getDefinitionByName() method to create a new instance of that Class (whatever it is).basically, whatever I have stored in the variable 'currentPage' (which could be any number of classes I haev written), I want to create a new instance of (therefore re-instantiating it). this will then act as the method for a 'reload' button which is designed to reload whatever the current page/activity is.
I built a class that parses JSON data, stores it in an array, and now I want to return that data so that it can be stores in an array in my root AS file. I'm eventually trying to pass the returned array to another class. My class looks like this:
1061: Call to a possibly undefined method payload through a reference with static type com.src.DataGrab.
Does anyone have advice on what might be wrong with my class, or a more logical way to write the getResults() function so that I can get retrieve the array being generated by this class?
I have this class that basically reads a json file and then places it into an array, which I then want to pass back to the var set etc, how do i go about this:I have the following at present:Heres part of my list class:
Code:
... the normal import etc of stuff above then the following.... public function loadVideoList(_videoURL:String=""):void { try{
However, on a bright note its coming!!!! So far, everything is going well and I am now seeing the light with AS3I do have a question on returning a variable from a function that loads an external CSS. This particular function is located inside a LoadStyleSheet.as class along with another public function that sets text properties to fields when accessed. What I am looking for is accessing the stylesheet after its been loaded in another class. I know in AS2 I could use the Delegate method for something similar to this situation. Not sure what the next step is for AS3. Anyhow, function script is below.
ActionScript Code: public function loadStyleSheetItem(loadStyleSheet_str:String):void { var styleSheet_css = new StyleSheet;
Lately i discovered MATE (for Flex development) and was wondering: how do i bind a property in a view (actually a navigatorcontent component) to another property in a class so that they stay in synchronization (meaning that whenever the property in the class changes the property in the view also changes).
So if we have a view called Target.mxml and a property targertProp how do we bind it to the class called SourceClass with property SourceProp?
I'm creating a custom class to retrieve some data using URLoader.My code is below, doing this from memory, plz ignore any minor typos.The challenge I'm encountering: when my custom class calls the loader, the event handler takes over. At which point the context of my code leaves the function and it's not clear to me how I then return the data retrieved by the loader. I sense that I'm breaking the rules of how ActionScript really runs by putting a loader in a separate class; at least, that's my primitive understanding based upon the reading I've done on this.So can I do this? I am trying to create a clean separation of concerns in my program so that my main program doesn't get clogged up with code concerned with retrieving remote data.
I am new to AS3, as well as Flash in general, so forgive me if this seems highly elementary. All I am trying to do is create a custom class that extends the MovieClip class and contains a custom property of "marker". I want to be able to use and change the value of this custom property on the timeline for an instance of this class and have it behave just like any other (Ex: this.x ==> this.marker).
I'm having some problems importing a class, the message that Flash gives me is this; The class being compiled, 'ImageLoader', does not match the class that was imported, '[URL]'. The only line of code in my flash movie is this: import com.martijndevisser.*; And yes, the class is in that folder The class is from here: [URL] I've used the class before and it works fine, I just dont know what to do?
This seems like it should be an easy one but I can't figure it out.I'm trying out a very simple class that, when created, loads and XML file into the class's property. I must be getting a basic concept tangled up here because I can see the XML coming in just fine in the handleComplete function, but the class property _result remains empty.What concept am I missing here?
I want to accomplish simply that MC 'Menue' follows MC 'SliderLeftVert_Panel'. I don't get it.I get this error: TypeError: Error #1009: Cannot access a property or method of a null object reference at SliderSlide/Move()
The MC 'SliderLeftVert_Panel' is linked to Class 'SliderSlide.as' below
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 usualplayer: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...
Im trying to get the value of the textWidth property in class Main from a text field created in an instantiated class Label. When I trace the value from within the Label class I have access to the values. I'm trying to use a get function to pass the value to the main class.[code]
I've got a property, var angleX:Number; declared right after my class declaration (therefore available to each function in the class). How do I go about tweening this value with Tweener? Specifically, I'm trying to do it in a mouse press event but am stumped by the object i need to pass - the keyword "this" isn't working.
I have a problem with the piece of code that's been annoying me for a week. It should be very simple but all my attempts at a solution somehow seem to get thwarted by an invisible hand that wants me to fail.Here is the scenario: I am trying to create an image strip consisting of image thumbnails. When one mousovers each image it should print its information (say a name) in a textfield.I created an image container class that loads the images through a url request, then an image strip class that receives an array with image names and urls and displays them in a row. So far so good.
However when it comes to showing the info I have no clue how to address which image is being pointed at. I put a variable called imageIndex inside my imageContainer object, then put all the created containers in imageStrip's for-loop inside an array called mgContainerArray. I created a for loop in my fla that goes through this array and assigns all those containers a mouseover event listener. What I'm stumped with is that there is no way I can access the imageIndex variable from my function to tell the code which image is currently being mouseovered. It keeps giving me an error.Here is the code: