Flash :: ActionScript 3 - Returning / Inspecting Class Value On Declaration
Jul 26, 2010I'm wondering if is there any way to mimic the same behaviour we have for top level classes in AS3 for example:
[Code]...
I'm wondering if is there any way to mimic the same behaviour we have for top level classes in AS3 for example:
[Code]...
I am new to AS3 and I want to organize my code as what I did in C++, which I can have a .h and .cpp file. Is there any way to organize code like this in AS3? [code]....
View 2 RepliesI 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{
[code]....
I need it to create "pieceName1" and "pieceName2" etc.I tried:var this["pieceName" + i]: PieceName = new PieceName();But that didn't work.I tried googling Array Notation but I also couldn't find anything that would help in class declarations.
View 3 RepliesI have an SWC which includes a number of Assets for my project. Within this SWC is also a static AS file which contains Class declarations for each image in the library. For example, the SWF contains these images:
[CODE]...
Possible Duplicate: Where is the "proper" place to initialize class variables in AS3
Whether its better to instantiate class on it's variable declaration or within a constructor? For example, this:
protected var _errorHandler:ErrorHandler = new ErrorHandler();
or this:
protected var _errorHandler:ErrorHandler;
public function someClass() {
_errorHandler = new ErrorHandler();
}
example:
var c : Class = Sprite;
//This can be random class such as movieclip/etc
var o = getDefintionByName(getQualifiedClassName(c));
this works, but in flash develop, it says that the variable 'o' has no type declaration
which basically means
var o : SOMETHING = getDefintionByName(getQualifiedClassName(c));
but how do i put that something there when i do not know what its coming because of random classes?
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:
[Code]...
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.
View 5 RepliesI 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:
package com.src
{
import flash.display.Sprite;
import flash.net.URLRequest;
[Code]....
I keep getting the following error however:
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 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)
I want to make class which will import picture into UILoader and then will show it. It looks like that:
ActionScript Code:
package mob.kopertownik
{
import fl.containers.UILoader;
[code]....
And into the *.fla file I have got something like this:
ActionScript Code:
var myPicture:Picture = new Picture();
myPicture.CreatePicture(fileRef.name);
When I have got everything ready and the all requirements are fulfilled there is nothing happening.
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;
[code]......
I am developing in Flash Builder 4.5 using as3.
I have created a class to connect, write and read to a TCP Socket using 'import flash.net.Socket;'
Within this class is an event listener which reads the incomming data:
Code:
socket.addEventListener(ProgressEvent.SOCKET_DATA, readSocketData);
private function readSocketData(progressEvent:ProgressEvent):void {var response:String = socket.readUTFBytes(socket.bytesAvailable);
trace response;}
My problem is how to output this data back to my main application. Ultimately I want to process the data and output it in a text box.
I'm building a Flex/Flash Builder 4 application that loads data using E4X/XML, like this:I originally build an application that was a single MXML file which loaded this XML file and built a form from the data.I've now build a main menu screen with a button to load the form screen as a seperate module. How do I get the XML declaration to work in this module without loading it again.
View 1 RepliesIn Flex you can use Declarations tags fo non UI elements.Problem:The order of classes inside the Declaration is sorted ascending or something...Meaning that in this example, AClass will be instantiated before BClass:
<fx:Declarations>
<local:AClass />
<local:BClass />
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.
[Code]...
i want to put all variables of an object into ByteArray in declaration order. the object can be a extends one. here is my code:
private static function getVariables( packet:*): Array
{
var vars:Array = new Array();
[Code]....
what does the "pos" for ?
i try to print the xml, but i can not find the meaning of "pos"....
I am trying to print a string with html formatting. Part of the formatting includes font face. I have found that my print job will not print any string that includes a font face declaration. I'm guessing because the font isn't embedded, but I'm not positive.
This works:
string = "<b>bold</b> not bold";
Doesn't work:
string = "<TEXTFORMAT LEADING="2"><P ALIGN="LEFT"><FONT FACE="Arial" SIZE="12" COLOR="#000000" LETTERSPACING="0" KERNING="0">this is my string</font></p></textformat>";
How can I get around this. I need the ability to print any font on a users computer.
this should be easy, but I can't figure it. How do I get an XML declaration in AS3? I need to get any encoding= parameter. For example this XML:
<?xml version="1.0" encoding="UTF-8"?>
<some>
<thing>...</thing>
</some>
It's XML text that loads externally from a URL using URLLoader. I create the XML object by doing var xml:XML = new XML(evt.target.data) upon load complete. I've tried XML.ignoreProcessingInstructions = false and no effect. xml.children()[0] is the first node, not the declaration. Do I need to manually parse the raw string data that is returned from URLLoader?
I'm currently working on a project where I'm having to deal with a lot of different variables and am wondering if there would be a way to cut down on my declaration ones (there are currently 152 variables dedicated to one small portion of the project.)What I have is a type, which has some subtypes(4), which have even more subtypes(subtype 1a-c: 7 types, subtype 1d: 13), which have yet another set of subtypes(which are basically subtype 1a-c's + few more, and are all applied to subtype 1d.)
View 5 RepliesActionScript Code:
mc.addEventListener(MouseEvent.CLICK,clic);
function clic(evt:MouseEvent){
var clip:MovieClip=evt.target as MovieClip;
removeChild(clip);
}
1) Why it's also possible write removeChild(DisplayObject(clip)) and for what? In which case it's necessary?
2) if I write var clip=evt.target it's works too but if I write var clip:MovieClip=evt.target it doesn't work. Why? It's a movieClip that should go in the variable var.
I'm having trouble reading an XMLDocument object that has an xml declaration. When I try to trace the first child of the document I get nothing. I've run into this before but it wasn't a problem because previously I was in control of the format of the xml, so it was no problem to just not have an xml declaration, but for this project I don't have that control.
View 2 Repliesi am having a multiple empty movie clip with dynamic loaded swf.now the swf path may change frequently by day by day.how to make it as static with out change ip address
View 4 RepliesIm trying to fetch some data from PHP and use it in a link in flash AS3. flash code:
[Code]...
know if it is possible to use PHP/mySQL or using just actionscript to save current status of the flash file section that you were currently viewing and returning to the same section at a later stage when you log back onto the website. What I mean is using a log in/log out script. e.g. > I am at a website (flash of course):> I sign in> start at section one of the website (homepage)> Use website> get to section seven of the website> log off> return later and log on to the website with my user id and password again.
View 1 RepliesI know this doesn't work, but basically, I'm looking at something like this:
robot_mc.skullplate_mc._visible = false;$skull = String(robot_mc.skullplate_mc._visible = false);
because I know I can abbreviate stuff like
yellow = Key.KeyisDown(Key.RIGHT);
blue = Key.KeyisDown(Key.UP);
green = yellow && blue;
if(green){ball_mc._x += 5; ball_mc._y -= 5;}
I want to create a function pointer object:
private var func:Object = { Class.Constant: function };
What is the clean way of doing this? I did the above and got
Error: Syntax error: expecting colon before dot.
And I'm not even sure that's right. The goal is that I can just do
func[ Constants ]();
How do you add an XML declaration - < ?xml version="1.0" encoding="UTF-8"? > - to a Flex XML object? The same thing you could do with the old XML - new XMLDocument class and the xmlDecl property.
View 1 Replies