ActionScript 3.0 :: Custom Properties To A Sprite?
Sep 18, 2009since I cant create a custom property on a sprite if extend a sprite, should be able to make a custom property then or do I need to use a movieClip?
View 14 Repliessince I cant create a custom property on a sprite if extend a sprite, should be able to make a custom property then or do I need to use a movieClip?
View 14 RepliesI created a class, extended the sprite class, and now in the constructor I am trying to set the Sprite's width and height properties which are inherited from the DisplayObject. However, after I set this.width and this.height, and print the values, I get 0 for both.
What the heck is going on? When I view the livedocs I see that DisplayObject has width and height listed as public properties. I have been able to instantiate a Sprite directly, and set the width and height after it's been instantiated, so I don't get it.
package {
import flash.display.*;
public class ScrollBar extends Sprite {[code].....
I have a sprite in which I have added other sprites. Something like:
var sp_main:Sprite = new Sprite();
var sp_group:Sprite = new Sprite();
for(i:int = 0; i < 10; i++)
[Code]....
I'm trying to make a textfield inside a sprite zoom upon mousing over the sprite. I'm instantiating tweens on the x, y, scaleX, and scaleY properties of the sprite. The x and y tweens are needed due to the top left registration. Also, the tweens are added to an array to ensure they finish. Sometimes it works as I intended, but when I mouse over from the bottom right corner, the sprite jumps haphazardly towards the top left and back until I mouse out, instantiating another set of tweens to return the sprite to it's original state. I'm not sure what to do other than using a custom tweening engine such as Tweener. I'm using the built in tweening classes and I'm hoping to find a solution within these parameters.
View 5 RepliesThrough searching the various forums I have found that Loaders are not dynamic and hence you can not apply custom properties to each instance of them. I miss the old way (as2 way of attachingMovieClip) that you load dynamic content, at least you can apply custom properties, and you can always reference them for each object.
What I'm trying to do is load a group of Images via XML. Each one of those images have a set of information that is associated with them (name, description, etc). I have the images loading in and positioning just fine, however when trying to have a tooltip show the name on Mouse Over, I'm not able to achieve this...
In short. I want to be able to store information for each item so that I can access it. Is there a way to do this in AS3 with a Loader or is there another route I can go? If I do this with Arrays, how do I store the Index of the specific item so I can use that in reference to the position in each array?
[Code]...
Looking to see if anyone has examples of adding custom properties to the CheckBox object. I'm trying to pass a few other parameters to the click handler to extend the functionality of the cb. [code]
View 1 RepliesCan't get Sprite to respond to custom event
View 3 RepliesI've got an app where numerous Sprite objects are being placed on the stage, and then when an event occurs (mouse click most likely) I want all the Sprites to move, independently, based upon an algorithm that each Sprite has. I can't get the Sprite objects to respond to the event; I get no errors.
Here's my Event class:
package {
import flash.events.Event;
public class MyCustomEvent extends flash.events.Event {
public static const CONTROL_TYPE:String = "moveThem";
[Code] .....
Basically I have lot of text fields that are rendered dynamically, and I want the user to be able to right click on one and edit it.
Is it good practise to use the right-click bring up custom menu on a sprite. And is the method guaranteed to work accross all browsers? Do mac mice have right mouse click buttons?
[URL]
And if not, what would be a good work around. Maybe bringing up a yahoo astra message box with the two options one for left mouse click, one for right click and edit text field?
I am writing a class button that extends Sprite. I use graphic fill to draw button and then use addEventListener to add Tween to MouseOver event. Problem is:
1) If I use MOUSE_OVER event, the tween became sometimes corrupt when Mouse is INSIDE the button.
2)If I use ROLL_Over event, the tween became sometimes corrupt when Mouse is NEAR the button BUT ok WHEN mouse is far enough.
Basiclally a simple thing, however i dont get an idea on how to solve this one:
Say I have a sprite which is already existing during runtime and at some certain point I want to attach some custom data to it, say, in a string.
How would I do that?
s:Sprite = new Sprite();
s["extra"] = .... gives me an error, so i got exactly that far till here.
s.name is already reserved for another string and for sure I thought about just adding a TextField with the string inside to it, like
s.addChild(myStringTf);
But I know there is a better way, I just cant find it. hasOwnProperty() just returns a boolean true in case i match the value already assigned to it, right? Isn't there a way to attach an annonymouse object to it?
I can't use a "for in " loop to enumerate public properties of a custom class. So I have a class "ClassA" , which has some public properties. if I try :
PHP Code:
trace(classInstace.hasOwnProperty('property1'));// true
trace(classInstace.property1) // traces the property correctly
trace(classInstance.propertyIsEnumerable('property1')); // traces false ????
I am very new to AS3, and I'm confused about how things that would have been simple in AS2 are so complex and tricky now. For example, I want to create a bunch TextField objects that, for some reason, rise up every frame (as in : object.y-=1; ).However, I also need each TextField to reference the TextField that was created just before it.
I tried creating a variable that would hold such a reference : ThisTextField.Ref=LastTextField; but - this returns an "Access of possibly undefined property..." error. It seems I can only have custom properties on mere Objects ! This is annoying because an Object doesn't seem to accept event listeners (remember, I need them to do something every frame). Is there a way to simply set custom properties on my TextFields, without having to use custom packages ? Or is there a way to use event listeners on Objects ? I've read something about strict mode which could allow setting properties on other objects - what are the risks of turning it off ?
I have been stuck on this problem for a while, and wonder if anyone knows the answer. It is concerning accessing some properties of a custom component. I marked the problem with the keyword [PROBLEM] in the following snippets of code.
components/State1UI.mxml
--------------------------------
<?xml version="1.0" encoding="utf-8"?>
[code].....
Through searching the various forums I have found that Loaders are not dynamic and hence you can not apply custom properties to each instance of them. I miss the old way (as2 way of attachingMovieClip) that you load dynamic content, at least you can apply custom properties, and you can always reference them for each object.What I'm trying to do is load a group of Images via XML. Each one of those images have a set of information that is associated with them (name, description, etc). I have the images loading in and positioning just fine, however when trying to have a tooltip show the name on Mouse Over, I'm not able to achieve this.
In short. I want to be able to store information for each item so that I can access it. Is there a way to do this in AS3 with a Loader or is there another route I can go? If I do this with Arrays, how do I store the Index of the specific item so I can use that in reference to the position in each array?** Should I use getChildIndex() in the function for the Event Listener to reference the data stored in the arrays for each item? If so, how do I do so? ***
PHP Code:
num = 0;var titleArray:new Array();function createImage(){ var thumb:Loader = new Loader; thumb.load(new URLRequest(url);
[code].....
Is it possible to dynamically name properties on a custom object ?
something like:
Code:
o:Object = new Object();
s:String = 'abcd'; // the name I want for my objects property
o.[s] = '1234'; // 1084: Syntax error: expecting identifier before leftbracket.
trace(o.abcd) // 1234
EDIT I want to do this as an associative array, so if there is a better alternative then I'd be happy with that as well.
In AS2 we can not add methods n properties to built-in classes in the way we do in AS1. Like we would -say- write the custom "isNatural" method on the "Math" class as follows : * The following code is valid in AS1 but not in AS2
[Code]...
As the "Math class" is static internally. We know why we can not add custom methods n properties to every class, as the way we do in AS1. Later I came up with senocular' s very nice tutorial on OOP in AS2. And now i know how we can do it in AS2 style in an efficient n organised way. But i have a problem with the following code. It should not work ! but it does... * Following code is valid for both in AS1 and AS2.
[Code]...
I have a sprite A which has a child, sprite B.Sprite B has a variable, instance of class C which only extends EventDispatcherIn class C, I dispatch a custom Event. The eventlistener in sprite B reacts on the event.The same eventlistener in class A doesn't respond.If I dispatch the same custom event in the eventhandler in class / sprite B, this event is seen in class / sprite A.Is there a difference in events going through the displaylist and those who are from an EventDispatcher?
View 6 RepliesHow do I access Stage Class properties in Custom Class?
Class:
package {
import Main;
import flash.events.*;
import flash.display.Sprite;
import flash.display.Stage;
public class Run extends Sprite {
[Code] ....
Output:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
I've written the following custom component, SubNavBar.mxml:
<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" height="100" width="300"
creationComplete="init()">
<mx:Script>
[Code]...
Whenever the trace function runs in init(), the property menuItems returns null. I don't seem to have this problem with other variable types, like Boolean or String. Is this due to the size of the XMLListCollection object? How can I set up this SubNavBar custom component with XMLListCollection property and bind it to a control in the component?
I am implementing a scrollbar using a custom embedded image using my CSS stylesheet. This is a very simple, thin scrollbar. I would like to configure this scrollbar using CSS properties at runtime, but so far I have been unable to do so. I know it can be done because I've seen examples of it in the net, but no code to review.
View 1 RepliesI'm trying to make a simple flash application providing interface for taking tests as a high school assignment. One of the requirements is to use an XML file as data source.Now, having a List component bound to the XML file with questions consisting of data such as question body, question type (ie. single choice, multiple choice, open, image etc.) and possible answers (where applicable), I was wondering if I could add some additional data (and what is the best possible way to do so) to each question upon its transfer to the List component.
I am trying to achieve two main goals with this: firstly, to mark the questions to which an answer has already been given, like with such code in ItemRenderer class:
<s:Label color="{data.color}" text="{data.label}"/>
Where data.color would be set whenever the user gives an answer to a question.
Secondly, while at it, I thought of such possibility as a great way to store answers given to particular questions. In this case, the Class of the answer object would have been Object, since there has to be many type of questions (where the answer could also be a Bitmap for example).
Given this:public namespace foo;foo var bar:String = "baz";We can access the property "bar" like so:[code]It gives me the following error: ReferenceError: Error #1069: Property foo::bar not found on MyClass and there is no default value.On further inspection of the foo namespace I can see (in the debugger) that the URI is in the format {package}:{type}/{name}. If I try to replicate this by doing the following:[code]Does anyone know if it is possible to get access to namespaced members like this? I don't have compile time access to the namespace, but I can look up it's uri (and prefix) dynamically at run time.
View 1 RepliesI have just created a custom AS3 Component to use in an MXML project.[code]but then i lose some re usability.What do i need to do to be able to set properties from mxml?
View 3 RepliesI am following this page to create a custom preloader extending Sprite to load an animation SWF, but it is not working (the animation SWF is not displaying): [URL]. I know the Animation.swf file is okay, because if I load it into the main app it displays and runs. The preloader works if an image is loaded by the preloader instead of the animation SWF.
test.mxml (main app)
BTW, I typically have many more lines of ComboBox in the app to force the preloader to display, but limiting number of lines here.
CustomPreloaders.SparkAnimationProgressBar.as
package customPreloaders {
import flash.display.;
import flash.events.;
import flash.net.;
import flash.utils.;
[Code] .....
I've made a simple package that creates a custom textfield and a circle sprite. pressing the circle sprite is supposed to update the textfield text with some sent string. The string is being sent by using a custom event. The problem is, for some reason the script never reaches the function that handles the custom event....why isn't the updateText event firing??
[Code]...
I need to create a custom Object that basically stores some custom parameters (properties?), which I have successfully done, and the code below works fine.
PHP Code:
myObject = new Object();
myObject.nameLabel = "New Releases";
myObject.artOrientation = "portrait";
myObject.artAmount = 5;
I find the new compiler and debugger capabilities very useful, since I'm not the most detail-oriented, so I (usually) like that Flash forces me to strict-type my variables and such. Anyway, I was wondering if it's a "best practice" to strict data type a custom objects' properties, and if so, how to do it in the logic above? I kept getting syntax errors when I just tried it initially.
I know if I created a custom Class .AS file, I would be forced to data type the properties... but I'd rather just do it "in-line" in my main .FLA file. Also, I know I can just pass typed VARIABLES to the properties... but I'd rather have the properties strict-typed themselves... so if I try to pass a variable as the wrong type, then I would still get an error.
i wonder why i am unable to access the public properties of this custom class the public var w:Number; and the Public var h:Number; i am tracing them and on an instance of the PreLoader() Class.. and ia m getting NAN;
View 12 RepliesI'm trying to pass some properties to a component I've created in Flash Builder 4. In my example below I want to pass the "label" property to update the label property of the Button.
// MyApp.mxml
<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="[URL]"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
xmlns:local="*">
[Code] .....
I wrote a simple class called CustomTextField.as as follows:
package{
import flash.text.TextField;
public class CustomTextField extends TextField{
[code].....