Referencing A Instance Inside A Class
Hi --I am working on converting a movie clip to a Class so that I can more easily reuse it in later projects.I have pretty succesfully converted my AS code from my include file to a Class file. However, I have two objects on the stage, topBG and botBG and whenever I reference these items inside my code, such as botBG._y I get an error at compile time saying "There is no property with the name 'botBG'" How can I set it so these assets can be referred to inside my code?The code worked fine when it was just a movie.. Also, this is ActionScript 2.0.ThanksRich
Adobe > ActionScript 1 and 2
Posted on: 12/16/2008 10:40:17 AM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
[F8] Referencing A Static Class Inside Another Class's Instance
I've got a movie loading into a framework.
This framework has 1 instance of the class main called main.
Inside this class, another class is used, but it is used directly, not as an instance. E.g.:
code:
import com.StaticClass;
class main {
private function UseStaticClass():void {
StaticClass.init();
}
}
From my movie, I can reference the main instance as _root.main. Can I reference StaticClass at all if there's no explicit instance created or it's not assigned to a public variable?
I can't modify main to include getter/setter methods, that's why I ask.
Thanks.
Static Class Variable Referencing Class Instance
I was given the task of writing a class that would send serial requests for xml data, the idea being that the requests could be added while previous requests were still in progress, but the class would queue them and wait for the reply of one request to come back before sending the next.
The way I did this was to create a class instance for each request, and the request itself would be stored in an instance variable, waiting to be sent. A static variable called queue (accessible to all instances) was then given a reference to the instance, and when this reference got to the top of the queue, queue would call the sendRequest() method on that instance.
The reason why I am using one instance per request is so that the replies can be retrieved via the instance, so keeping each request entirely discreet.
Everything works very nicely, but the problem is my IT manager looked at the code and told me that you cannot put a reference to a class instance in a class static variable... and for this reason he has informed my line manager that he has serious reservations about the code, and recommends that it is not incorporated it into the project. However, the code works very well on my local machine and on the testsite, and no-one has experienced any problems with it.
Can someone reassure me here... I can see absolutely nothing wrong with having a class static array hold references to each of the instantiated class instances. And the proof is in the pudding.. it works. Can anyone else see a problem here?
Referencing Class Variable From Inside Self
I have a class in an external .as called CustomGroup, and it will take in and process a number of objects which I want to name.
Code:
var myGroup:CustomGroup = new CustomGroup();
var otherGroup:CustomGroup = new CustomGroup();
myGroup.storeMarkers(someArray);
otherGroup.storeMarkers(otherArray);
I would like for each marker in someArray to be indexed with the instance name of the class object (i.e. "myGroup001", "myGroup002", "myGroup003") and ("otherGroup001", "otherGroup002", "otherGroup003")... but I cannot figure out how to target the class variable name from inside itself.
Help?
Referencing An Object Inside A Class
and I'm trying to add an event listener and a function to the class, but I keep getting errors of undefined,
I tried just about everthing to be able to refference obj0 can anyone please help?
objGroup.obj0.addEventListener(MouseEvent.CLICK, onClick)
private function onClick (event:MouseEvent):void{
trace ("Click");
}
any help or advice will be greatly appreciated sincerely newwave
---------------this is my complete code - above code-------------feel free to use as you wish----------------------
Attach Code
package {
import flash.display.SimpleButton;
import flash.events.MouseEvent;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import org.papervision3d.core.proto.MaterialObject3D;
import org.papervision3d.lights.PointLight3D;
import org.papervision3d.materials.shadematerials.FlatShadeMaterial;
import org.papervision3d.objects.DisplayObject3D;
import org.papervision3d.objects.primitives.Sphere;
import org.papervision3d.view.BasicView;
public class pv3dMyRotation2 extends BasicView {
private static const ORBITAL_RADIUS:Number = 300;
private var angle:Number = 0;
private var obj0:Sphere;
private var obj1:Sphere;
private var obj2:Sphere;
private var obj3:Sphere;
private var obj4:Sphere;
private var obj5:Sphere;
private var obj6:Sphere;
private var obj7:Sphere;
private var objGroup:DisplayObject3D;
public function pv3dMyRotation2() {
super(0, 0, true, false);
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
init3D();
createScene();
startRendering();
}
private function init3D():void {
camera.x = -200;
camera.y = 0;
camera.z = 0;
}
private function createScene():void {
var light:PointLight3D = new PointLight3D(true);
light.x = 400;
light.y = 1000;
light.z = -400;
var M1:MaterialObject3D = new FlatShadeMaterial(light, 0xFF0000, 0xFFCC99);
for(var i=0; i<8; i++) {
this['obj'+i] = new Sphere(M1, 50, 10, 10);
this['obj'+i].x = ORBITAL_RADIUS * Math.cos(angle);
this['obj'+i].z = ORBITAL_RADIUS * Math.sin(angle);
angle += (360 / 8) * Math.PI / 180;
}
objGroup = new DisplayObject3D();
objGroup.addChild(obj0);
objGroup.addChild(obj1);
objGroup.addChild(obj2);
objGroup.addChild(obj3);
objGroup.addChild(obj4);
objGroup.addChild(obj5);
objGroup.addChild(obj6);
objGroup.addChild(obj7);
scene.addChild(objGroup);
scene.addChild(light);
}
override protected function onRenderTick(event:Event=null):void {
objGroup.yaw(1);
super.onRenderTick(event);
}
}
}
Edited: 02/01/2009 at 08:58:22 PM by newwaveboats
Instance Of Class Inside Of Different Class
I am trying to make an instance of a class inside of a different class. But I am getting an error:
**Error** C:Documents and SettingsOwnerDesktopSlideshowsFlashReminderE vent.as: Line 8: A class's instance variables may only be initialized to compile-time constant expressions.
var s1:Step = new Step();
**Error** C:Documents and SettingsOwnerDesktopSlideshowsFlashReminderE vent.as: Line 9: A class's instance variables may only be initialized to compile-time constant expressions.
var s2:Step = new Step();
**Error** C:Documents and SettingsOwnerDesktopSlideshowsFlashReminderE vent.as: Line 10: A class's instance variables may only be initialized to compile-time constant expressions.
var s3:Step = new Step();
**Error** C:Documents and SettingsOwnerDesktopSlideshowsFlashReminderE vent.as: Line 11: A class's instance variables may only be initialized to compile-time constant expressions.
var s4:Step = new Step();
**Error** C:Documents and SettingsOwnerDesktopSlideshowsFlashReminderE vent.as: Line 12: A class's instance variables may only be initialized to compile-time constant expressions.
var s5:Step = new Step();
**Error** C:Documents and SettingsOwnerDesktopSlideshowsFlashReminderE vent.as: Line 13: A class's instance variables may only be initialized to compile-time constant expressions.
var s6:Step = new Step();
The code for the first class is:
code:
class Event {
var type:String = new String();
var oName:String = new String();
var description:String = new String();
var steps:Number = new Number();
var dueDate:String = new String();
var percent:Number;
var s1:Step = new Step();
var s2:Step = new Step();
var s3:Step = new Step();
var s4:Step = new Step();
var s5:Step = new Step();
var s6:Step = new Step();
function createNewEvent(d1, d2, d3, d4, d5, d6, d7, d8, d9, d10, d11) {
type = d1;
oName = d2;
description = d3;
steps = d4;
dueDate = d5;
percent = 0;
if (steps == 6) {
s1.createNewStep(d6);
s2.createNewStep(d7);
s3.createNewStep(d8);
s4.createNewStep(d9);
s5.createNewStep(d10);
s6.createNewStep(d11);
} else if (steps == 5) {
s1.createNewStep(d6);
s2.createNewStep(d7);
s3.createNewStep(d8);
s4.createNewStep(d9);
s5.createNewStep(d10);
} else if (steps == 4) {
s1.createNewStep(d6);
s2.createNewStep(d7);
s3.createNewStep(d8);
s4.createNewStep(d9);
} else if (steps == 3) {
s1.createNewStep(d6);
s2.createNewStep(d7);
} else if (steps == 2) {
s1.createNewStep(d6);
s2.createNewStep(d7);
} else if (steps == 1) {
s1.createNewStep(d6);
}
}
function showPercent() {
for (var p = 1; p<=steps; p++) {
percent += this["s"+p+""].percent;
}
percent /= steps;
return percent;
}
function done(stepN) {
this["s"+stepN+""].done();
}
function setStepPercent(stepN, p) {
this["s"+stepN+""].setPercent(p);
}
}
The class being loaded is:
code:
class Step{
var completed:Boolean = new Boolean();
var sName:String = new String();
var percent:Number = new Number();
function createNewStep(d1){
completed = false;
sName = d1;
percent = 0;
}
function setPercent(tbs){
percent = tbs;
}
function done(){
completed = true;
percent = 100;
}
}
Please help!!!
Asigning An OnEnterFrame To An Instance Inside The Class's Constructor
I need to be able to add an onEnterFrame event to an object inside it's constructor.
This is what I've tried (it doesnt work obviously):
Code:
myClass = function () {
this.onEnterFrame = function () {
trace("FRAME");
}
}
//------------
myClass = function () {
this.onEnterFrame = myFunct;
}
function myFunct() {
trace("FRAME");
}
//------------
etc...
I've also tried myClass.prototype.onEnterFrame = function...
Nothing I try works, I even created a dummy file to make sure there was no outside interfearance, but nothing worked. I'm able to assign an onKeyDown event, but for some reason it wont work for onEnterFrame. It's kind of important that I'm able to do this for my latest project, so any help would be great.
[CS3] Referencing A Movieclip Inside A Movieclip From A Class File
Hello All,
I'm trying to access a movieclip inside another movie clip from a class file that is not attached to either movieclip. For instance, I'm checking hitTests for the avatar the player uses on the game, there are two enemy movieclips. Inside each enemy movieclip is another movie clip that serves as a bounding box (specifically around the mouth of the enemy so it can eat the player). Here is what I have so far that isnt working:
Code:
if (_root['otter']['obbox'].hitTest(this) && touch == false) {
trace("Otter touched Urchin");
gotoAndPlay("hit");
_root['otter'].gotoAndPlay("eat");
touch = true;
}
The class file is for the avatar. On the stage is the otter mc and inside the otter mc is another mc called obbox which is what I'm trying to hitTest against. Needless to say, it doesn't hitTest or trace or play the animation. Is there a way to reference a nested mc? Thanks in advance.
Terror.
Code In One Instance Is Referencing The Previous Instance
I have the following code in a button symbol:
on (release) {
gotoAndStop (2);
_root["answer" + this._name.substr(1)] = "true";
}
I also have an instance of the button in 2 consecutive keyframes. The first instance is named "Q5" and the second instance is "Q6".
I expected the code: this._name.substr(1)]
to reference "5" and "6" from the instance names (Q5 and Q6), but instead instance "Q6" is referencing "Q5"!
The *really* strange thing, is that when I insert a blank keyframe between the two original keyframes, the code works perfectly!
Does anyone know what's happening?
[Flash 8] Referencing Class Variables From OnEnterFrame Created Within Class
Hi,
It's been a while since my last post here, but I was hoping someone could help me with a problem I'm having. I want to reference and change a class variable from within an onEnterframe function defined within a class. I can actually do this right now, but I want to do it in a different way. Here's a code sample of what I am talking about:
Test.fla file:
Code:
var t:tester = new tester()
Working tester.as file:
Code:
class tester{
private var num:Number = 100;
function tester(){
var classObj:tester = this;
var mc:MovieClip = _root.createEmptyMovieClip("test",1);
mc.onEnterFrame = function(){
trace(classObj.num); //This traces 100 (CORRECT!!!)
}
}
}
This traces 100 to the output window, just like it should
Here is the way that I would like to do it, because I want to reuse my onEnterFrame Stuff:
Code:
class tester{
private var num:Number = 100;
function tester(){
var classObj:tester = this;
var mc:MovieClip = _root.createEmptyMovieClip("test",1);
mc.onEnterFrame = this.mcOnEnterFrame;
}
private function mcOnEnterFrame(){
trace(num) //this traces undefined (BAD!!!)
}
}
As you can see, the work around to reading the class variable in the onEnterFrame function is to create a reference to the class object, before defining that function, then using the reference you created to access the class variables.
I have tried various iterations to get the second example working, but have had no luck. Does anyone know a way to get the second method working, or am I stuck using the first method.
Referencing Instance
I'm very new to Flash and Actionscript in general, but not to programming. Here's my question: I have a class game, that's linked to my document.
Within the game classes constructor I have the following code:
ActionScript Code:
addChild(player);
player.init();
mouseInput = new mouse(this);
Within the mouse class I've created a track function:
ActionScript Code:
private function track(event:MouseEvent) {
x = event.localX;
y = event.localY;
player.applyForce(player.x + (x - player.x) / 10, player.y + (y - player.y) / 10);
}
However, I'm having problems accessing the player class from within the mouse class.
Here's a look at the mouse classes constructor:
ActionScript Code:
public function mouse(movieclip) {
movieclip.stage.addEventListener(MouseEvent.MOUSE_DOWN, buttonDown);
movieclip.stage.addEventListener(MouseEvent.MOUSE_UP, buttonUp);
movieclip.stage.addEventListener(MouseEvent.MOUSE_MOVE, track);
}
I have a hunch that I should be trying to access player via a reference to the movieclip that I pass into the mouse classes constructor (as player is a child of game). If this is the case, what's the best way to go about this? I suppose I'd want a pointer or reference as a private var within the mouse class?
Instance Referencing
Hi All,
I am new to Flash and would like some help understanding how instances on the timeline are referenced.
I have a movie that needs to load all the text via XML, this I can do. I am storing all the text values in an array and would like to update all dynamic text instances at the start of the movie (to keep all the code in one place for easy maintenance).
If I use the following code on the first frame of the movie, nothing happens:
Code:
_root.movieclip_name.instance_name.text = value;
If I use the same code on the frame where the instance is placed on the stage it works. Why can I not refer to an instance on the timeline in my first frame or am I just doing something wrong?
TIA
Phil.
P.S - I am using Flash 8 Pro
Referencing MC's Through Their Instance Name In AS3
I have no problem instantiating Movieclips fully programmatical through actionscript (linking MCs in the library with a class and then creating a new instance and adding it to the stage).
But sometimes these movieclips already have quite a lot of content that is already positioned and styled. Lets say i made a MC 'textDisplayMC' (in the library, its not on the stage), that MC has for example a button on its stage and a dynamic text field, both have instance names, 'textFld' and 'closeBtn', i link this to a class TextDisplayer that extends MovieClip.
So i can create new instances of TextDisplayer and put them on the stage
var textDisplay:TextDisplayer = new TextDisplayer();
textDisplay.x = 10;
textDisplay.y =10;
addChild(textDisplay);
cool, that works ... but now i would like to put text inside that dynamic text field with instance name 'textFld', but i dont know how to get hold of that from my textDisplay. or i would like to add eventlisteners to that button ... but i dont have a clue how to get hold of that button.
Ideally in my TextDisplayer i have some private property of the type TextField, but then i would need a way to 'link' that existing dynamic text field in the MC to the private property in the Class somewhere in the constructor
I hope you guys understand, because i guess its sounds a bit confused ...
Access Property/function Of Instance From Inside Another Instance
Might be something really obvious, but I'm still trying to get my head round as3...
I need to call up a property and function of another instance of the same class, similar as in as2 (called from within "_root.instance_mc1"):
ActionScript Code:
_root.instance_mc2.someNumber = 0;
_root.instance_mc2.someFunction();
Now in AS3 I can access the object (extending sprite) itself (and inherited properties like x) by using:
ActionScript Code:
this.parent.getChildByName("row2").x
but if i try to access public variables/functions from that object (this.parent.getChildByName("row2").someNumber) I get Error 1119: Access of possibly undefined property someNumber through a reference with static type flash.displayisplayObject.
Anyone know how I can get this to work?
Dynamic Referencing An Instance Name
Ok, What I want to do is dynamically reference the instance of an object. My goal is to avoid writing _root.box1.engine.homeX a million times. Everything is the same in this except "box1". Box1 changes from "box1" though "box72" so I am trying to write it in a way that uses the least amount of code. Is their a way to change "box1" on the fly.
Here is the script.
function moveThing(point1, point2)
_root.box1.engine.homeX=point1;
_root.box1.engine.homeY=point2;
}
Referencing An Instance Name Using Variables?
Hi,
I have a series of mcs on the main timeline, all with a stop action on the first frame.
When a menu selection is made, i want the relevant mc to play from frame 2 - so i use
on (release) {
_root.gigpage.gotoAndPlay(2);
}
Simple right?
However, on each of these mc's, i want the 'active' mc to play from frame 11 (there is a stop action on frame 10), just so you can visualise - frames 2-10 tween the mc in, frames 11 onwards tween it out.
So i thought, by using a piece of code on each button that will set a variable curpage to the current page, ie. curpage = gigpage;
then use the code _root.curpage.gotoAndPlay(11); on the other buttons this would suffice.
I was wrong!
Is there a reason why I cannot use a variable to represent an instance name?
PS. I have tried using quotation marks ie. curpage = "gigpage".
All help appreiciated.
Thanks
Referencing A Button Instance Name?
Hi im using Flash MX with actionscript 1 and wondering if the following is possible?
I have an overhead site plan of an area with over 100 buttons mapped out that will trigger an effect when each button is rolled-over.
Everythings working fine but i've coded it all the long way by having seperate code on each button. What i want to do however it place all the relevant code to run at rollover within a function that can the be simply dumplicated on each button. Each button is labelled (b1, b2 .. b100 etc.)
What im struggling to do is reference the instance name of the button that is currently rolled-over within the actionscript for that button! I need this information to call in the appropriate information for that particular button.
Anyone with any ideas? Many thanks, hope that makes sense!
Instance Name Referencing Problem
Hi,
I'm trying to use an expand/shrink function from the tutorial section. This is the code, put in frame 1 of the main timeline:
Code:
function Expand (buttonRate, buttonName, buttonXSize, buttonYSize) {
if (buttonName.scale == 1) {
setProperty (buttonName, _xscale, buttonName._xscale += ((buttonXSize*buttonRate)-(buttonName._xscale*buttonRate))*(buttonRate/10));
setProperty (buttonName, _yscale, buttonName._yscale += ((buttonYSize*buttonRate)-(buttonName._yscale*buttonRate))*(buttonRate/10));
}
etc...
}
On the stage, I have 2 identical movieclips.
one that calls the function like this:
Code:
onClipEvent (enterFrame)
{
_root.Expand(2, _root.clipname, this.xscale, this.yscale);
}
the other like this:
Code:
onClipEvent (enterFrame)
{
_root.Expand(2, this._name, this.xscale, this.yscale);
}
The only difference being how I get the name of the target instance. The second one doesn't work and I was wondering what the problem was. Please help me out, thanks!
Referencing A Variable As An Instance Name
I have a set of buttons numbered 1-10, each with an instance name of b1, b2, b3 etc... depending on which button is pressed I want to move an indicator (which is an underline) to the position of that button to display to the user which page they are on. I have a variable called whichButton that I can get the value of the instance name but am having trouble actually getting the variable to be recognized as an instance name when telling the indicator to move its ._x position...
any thoughts?
function indicate() {
var button = "b";
trace(button+" this is the button prefix");
var whichButton = button+pageNum;
trace(whichButton+" this is the button Instance Name");
subNav.indicator._x = subNav.whichButton._x;
}
//whenever a button is pressed it updates pageNum with the value of that button, so button 3 when pressed pageNum = 3; and so on //
Referencing An Instance Name As A Variable?
I know this might sound like a silly question, but I've been trying to reference an instance name within a function as a variable passed into the function. For example:
Code:
ambient_emissions_monitoring.onRollOver = function(){
linkArrowView('on',this._name);
}
linkArrowView = function(offOrOn,iconPosition){
trace(_root.iconPosition._x);
}
I would like to be able to access all the properties (for example, the x coordinates) for an instance on the stage, but it returns 'undefined'. I'm fairly certain it can be done, I just cannot recall how to do so! Any help would be greatly appreciated.
thanks much!
Jon
Basic Question About Referencing An Instance.....
Hi all!
I came across something id just like to straighten out.
//class A is just a useful thing with public methods
Code:
var a = new A();
//class B will handle events and change a's state via mouse events, it also
should be given a reference to object a so that it can manipulate a's state.
Code:
var b = new B(a);
When i do this, i am not 100% sure what i have done.
If class Bs constuctor includes this:
Code:
private var objectToControl:A;
public function B (objectToControl:A)
{
this.objectToControl = objectToControl;
}
Then what am i doing here? I do not seem to be able to contact 'a'. I think maybe im making a copy of 'a' into objectToControl and not actually referencing it like i want to.
I just dont know though. If i am making a copy of 'a' and assigning it to a property, then how do i achieve a reference to 'a' and not a clone of it?
Dynamic Referencing The NumChildren In A Mc Instance
I am trying to dynamically read the number of children in movieclips that are created at runtime. These mc "windows" have several items in them, (scrollbars, text fields, image, etc...). I can run tweens and stuff by referencing these mc instance with:
DocClass(root).popupPages.getChildByName(pageToBuild) // works as a reference to a specific item
However, this same syntax fails when I add: numChildren
DocClass(root).popupPages.getChildByName(pageToBuild).numChildren // generates an error.
DocClass(root).popupPages[getChildByName(pageToBuild)].numChildren // generates an error.
What I want to do is run a for() statement on the mc to have it read back all of its contents. However, it fails to do that because it can never give me the number of children it contains.
Problems With OnClipEvent - Referencing Movie Instance
Hi,
Firstly, I should say that I'm pretty new to actionscript so please be gentle with any replies!!
Ok, here's my question;
I'm trying to use the onClipEvent statement to control when certain actions happen in my movie.
For example, I'm using "loadVariable" to call variables from an asp page and I don't want the movie to play until all the variables have been loaded.
Here is the actionscript I'm currently using to stop the main movie loading another movie until all the variables have been loaded into the main movie...
onClipEvent ( data ) {
loadMovie ("back2.swf", "/background");
}
Unfortunately this gives an error...
"Scene=Scene 1, Layer=Layer 5, Frame=5: Line 1: Clip events are permitted only for movie clip instances
onClipEvent ( load ) {"
The error also includes the following but I don't think this is relevant;
"Generator is not enabled for this movie. P: estsaspimageflashloadmovie3.swf"
I guess I need to reference the instance of the main movie I'm loading the variables into but I don't know the syntax of how to do this??
Any help would be much appreciated
Cheers
Dave
Button Referencing A Movie Clip Instance
Ok, I haven't used flash in a long time and this once seemed easy to me, but for some reason i can't remember how to have a button, on release - go to a particular movie clip instance on the same timeline.
PLEASE HELP!
thanks!
Referencing An MC Instance By Combining Variable Strings
Hello everyone,
I know this is pretty easy and there is a specific way to do it, but for the life of me I can't remember.
I have several boxes on stage. Each have an instance name of box1, box2, box3, etc. I'd like to call a function that each time references the next box up. I've created this:
Code:
SlideStart = function(){
i++;
boxVar = "box" + i;
SlideOff(boxVar);
}
Although the variable boxVar does trace as "box1", when I pass SlideOff the value boxVar, it doesn't do anything. If I pass SlideOff the value "box1", it works fine. Can anyone clue me in?
Thanks!
Referencing Main Timeline From Symbol Instance
i have a symbol instance on the main timeline in frame 1. inside the symbol there is a button which i want, when released, to move the main timeline over one frame.
is it possible to reference the main timeline from within this instance of the symbol? i have tried placing an onRelease command both within the instance and on the button inside the symbol. neither seem to work.
Referencing Dynamic Text Boxes By Instance Name
Hey Guys,
I have some code below here that creates a bunch of textfields based on the len variable which is the length of the initial for loop in the function. The first time the function is run, everything works perfectly. When the function is run a second time all I am trying to do is modify the text in the fields that were created the first time around. I am having great difficulties referencing the name and only one of the text fields are switching as it stands.. see the code:
ActionScript Code:
private function buildTextFields():void
{
var i:uint = 0;
// Number of textfields on this page
len = courseXML..module.(@num==moduleNum).page.(@num==pageNum).@txtFields;
// If this is the first run, create the text fields and populate them with text
if (textActive == false){
for (i=0; i<parseInt(len); i++){
console(courseXML..module.(@num==moduleNum).page.(@num==pageNum)["txtField"+i].(@langPref==lang));
txt = new TextField();
//Text Field Inits
txt.styleSheet = _styleSheet;
txt.wordWrap = true;
txt.multiline = true;
txt.border = true;
txt.width = courseXML..module.(@num==moduleNum).page.(@num==pageNum)["txtField"+i].(@langPref==lang).@w;
txt.height = courseXML..module.(@num==moduleNum).page.(@num==pageNum)["txtField"+i].(@langPref==lang).@h;
text_loc = courseXML..module.(@num==moduleNum).page.(@num==pageNum)["txtField"+i].(@langPref==lang).@l;
text_x = courseXML..module.(@num==moduleNum).page.(@num==pageNum)["txtField"+i].(@langPref==lang).@x;
text_y = courseXML..module.(@num==moduleNum).page.(@num==pageNum)["txtField"+i].(@langPref==lang).@y;
txt.text = courseXML..module.(@num==moduleNum).page.(@num==pageNum)["txtField"+i].(@langPref==lang);
console(text_x);
console(text_y);
contTextVers.addChild(txt);
sm.addItem(txt, text_loc, parseInt(text_x), parseInt(text_y));
}
}else if (textActive == true){
// During the second run, just change the text.. however, we cannot reference the name txt here as the items we want to reference were created previously and are already on the stage? How do I reference them by name? Tried using an array to store the name, but I cannot access the variable directly?? Only changes one text field.
for (i=0; i<parseInt(len); i++){
txt.text = courseXML..module.(@num==moduleNum).page.(@num==pageNum)["txtField"+i].(@langPref==lang);
}
}
textActive = true;
}
Thanks for any assistance.
Referencing Instance Name W/variable In Prototype Call
Hello all, I'm trying to reference an instance through the use of a variable in my call to a prototype. The variable is myVar and contains the instance name to which I want to apply the resizeTo prototype. My syntax is incorrect and I haven't found any clues in my search. Any help is always appreciated. Thanks.
Code:
on(release){
//disregard this line
this.swapDepths(this._parent.getNextHighestDepth());
//this is calling a prototype named resizeTo
this.resizeTo(150, -100, -100);
//Setting instance name of another movie
myVar = "green";
//Trying to drop that instance name into my next prototype call
this._parent.myVar.resizeTo(100, _parent.old_X, _parent.old_Y);
}
Referencing An Mc Created In One Class From Another Class
Hello everybuddy,
Cracking site, I normally don't post but have read and learned much from here thanks to all the posters!
I'm struggling with AS3 at the moment, forcing myself to take an OO approach and slowly getting there... However I'm now stuck...
My project is a dynamically generated web page, getting pics and data from xml files.
I have a button class that creates buttons based on an xml file, this is in its own class file(buttons.as) which is called from my document class.
The document class also creates a bunch of thumbnails using (screen.as), the thumbnails are placed in an MC called thumbs (which created by the document class).
What I need now is a way of linking my button class to the thumbs MC, so that when I click a button my thumbs MC is tweened using my dotween function.
when I run my project i get an errror from my buttons.as --> 1120: Access of undefined property thumbs.
I guess what i'm asking is how to reference an MC created in one class, from another seperate class. I thought that by setting it to public this would be possible but its not working...
Here is my code:
Code:
//Document.as
package {
import flash.display.MovieClip;
public class Document extends MovieClip {
public var thumbs = new MovieClip;
public var butArr = new Array;
public var screen1:screen;
public var thumbArr = new Array;
public function Document() {
//add buttons
for (var i:uint = 0; i < 10; i++) {
button[i] = new buttons(i);
addChild(button[i]);
}
//add thumb container
this.addChild(thumbs);
//addthumbs
for (var i:uint = 0; i < 10; i++) {
var thumbleft:uint=140+i*320;
thumbArr[i] = new screen(thumbleft,275,i,320,240,"thumb");
thumbs.addChild(thumbArr[i]);
}
screen1 = new screen(140,35,1,640,240,"home");
addChild(screen1);
}
}
}
Code:
//buttons.as
package {
import flash.net.URLRequest;
import flash.net.URLLoader;
import flash.events.Event;
import flash.display.MovieClip;
import flash.display.SimpleButton;
import flash.events.MouseEvent;
import flash.text.*;
import flash.filters.GlowFilter;
import fl.transitions.Tween;
import fl.transitions.TweenEvent;
import fl.transitions.easing.*;
public class buttons extends MovieClip {
public var num:uint=1;
public var myXML:XML;
public var thisText =thisText;
public var thisID:uint = thisID;
public function buttons(thisID) {
this.num=thisID;
getXML();
}
public function getXML() {
var urXML:URLRequest;
var ulXML:URLLoader;
urXML=new URLRequest("buttons.xml");
ulXML = new URLLoader(urXML);
ulXML.addEventListener(Event.COMPLETE, xmlLoaded);
ulXML.load(urXML);
}
public function xmlLoaded(event:Event) {
myXML = XML(event.target.data);
var xmlID=thisID-1;
thisText=myXML.butTitle[this.num];
makeButton(thisText);
}
public function makeButton(thisText) {
var myTextField:TextField=new TextField;
// Here we add the new textfield instance to the stage with addchild()
addChild(myTextField);
// Here we define some properties for our text field, starting with giving it some text to contain.
// A width, x and y coordinates.
myTextField.text=thisText;
myTextField.width=120;
//myTextField.height=50;
myTextField.multiline = true;
myTextField.wordWrap = true;
myTextField.x=15;
myTextField.y=this.num*50+50;
// Here are some great properties to define, first one is to make sure the text is not selectable, then adding a border.
myTextField.selectable=false;
//myTextField.border=true;
// This last property for our textfield is to make it autosize with the text, aligning to the left.
//myTextField.autoSize=TextFieldAutoSize.LEFT;
//This is the section for our text styling, first we create a TextFormat instance naming it myFormat
var myFormat:TextFormat=new TextFormat;
// Giving the format a hex decimal color code
myFormat.color=0xFFFFFF;
// Adding some bigger text size
myFormat.size=16;
myFormat.font="SkandiaDisplay";
// Last text style is to make it italic.
//myFormat.italic=true;
// Now the most important thing for the textformat, we need to add it to the myTextField with setTextFormat.
myTextField.setTextFormat(myFormat);
this.addEventListener(MouseEvent.CLICK,changePage);
this.addEventListener(MouseEvent.MOUSE_OVER,mouseover);
this.addEventListener(MouseEvent.MOUSE_OUT,mouseout);
}
function mouseover(evt:MouseEvent):void {
var glow:GlowFilter = new GlowFilter(0xFFFFFF,0.5,5,5);
this.filters=[glow];
}
function mouseout(evt:MouseEvent):void {
this.filters=[];
}
function changePage(evt:MouseEvent):void {
var newPage:Number=evt.currentTarget.num;
trace(newPage);
//not working
//1120: Access of undefined property thumbs.
thumbs.dotween("x",700,460);
}
public function dotween(command,startVal, endVal) {
var myTween:Tween = new Tween(this,command, None.easeOut, 0, 1, 1, true);
}
}
}
Any help would be greatly appreciated!!!
Thanks in advance!
Removing Instance X Inside Instance X
In Flash CS3 in library I have a MovieClip symbol Help (exported for AS).
The function below opens an instance of the symbol when the button is clicked.
ActionScript Code:
function showHelp(e:MouseEvent):void {
var helpwindow:Help = new Help();
helpwindow.x = 50;
helpwindow.y = 50;
addChild(helpwindow);
}
This works and instance "helpwindow" shows on the screen.
Now inside the symbol Help i have another button which will run a function that would close that instance. How do I get rid of that instance? I was trying with removeChild but errors occurr.
ActionScript Code:
function removeHelp(e:MouseEvent):void {
removeChild(MovieClip(parent).helpwindow);
}
Quote:
TypeError: Error #2007: Parameter child must be non-null.
How To Call The Instance Name Inside That Instance?
Ok this is what I want...
I am inside an instance of a movie clip. And I want to access the properties of this movie clip. Now the problem is (if) I don't know the name of the instance of the movie clip (suppose I create the instance of the movie clip on the fly!!!), how do i refer to the name of the instance.
Is there something called this. in actionscript?
Any help would be appriciated!!!
Sushubh
Checking To See If One Instance Of Class Hits Other Instances Of The Same Class?
Hi guys, the idea is similar to Yugop.com JAMPACK 01.
Let's say i have a bunch of balls/cells. I'm having trouble figuring out how to make it so that every other ball bounces off of every other ball.
so in short, it's really one instance being able to check all other instances of the same ball class?
any ideas guys and if you dont know what im talking about, please feel free to state that also.
Referencing Variables Inside A MovieClip
Is there an easier way of referencing variables inside a movieClip, without having to add 'this.' in front of all of them
Here is my code on the main timeline, there is a clip called ball2
Code:
ball2.onEnterFrame = function() {
if (!dragging) {
_x = _x+xspeed;
_y = _y+yspeed;
if (_x+edg>r_e) {
_x = (r_e-edg);
xspeed = -xspeed*bounce;
}
if (_x-edg<l_e) {
_x = l_e+edg;
xspeed = -xspeed*bounce;
}
//ground
if ((_y+ldg)>b_e) {
_y = (b_e-ldg);
yspeed = -yspeed*bounce;
}
yspeed = yspeed*friction+gravity;
xspeed = xspeed*friction;
} else {
xspeed = (_x-oldx);
yspeed = (_y-oldy);
oldx = _x;
oldy = _y;
}
if (_x>throwArea) {
dragButt._visible = false;
} else {
dragButt._visible = true;
}
};
stop();
all variables xspeed.. etc.. are declared within the ball2 clip
Referencing Inside Movieclips Gives 1119
I have searched actionscript.org and the web in general for a solution to this but I have been unable to find an answer.
The issue is this I have a class that extends Loader. This class loads a compiled .swf. I need to do some actions to movieclips nested inside the loaded movieclip. I reference the nested mc's by this.content.mc1, this.content.mc2 ...
With strict mode turned on I get this message
"1119: Access of possibly undefined property mc1 through a reference with static type flash.displayisplayObject."
If I turn off strict mode everything works fine but then I miss out on the compile time error checking fun of as3. Any help would be greatly appreciated
-Derek
Referencing Button Inside A Loaded SWF
Hey everyone,
I'm completely new to ActionScript and have been learning what I can in bits and pieces today. I'll try to keep my problem simple. In my main movie, I have a button that loads a second swf (small window) file into the main movie. The second file "flies" in from the bottom using motion easing. I've accomplished everything fine so far except that when I press close on the popup, it abruptly disappears.
I thought I could use yoyo() to reverse the animation when close is clicked to hide the popup off screen until I need it again. I just don't know how I'm supposed to reference the close button in the second movie from the first one.
The button in the second movie instance is Exit while its class is ExitButton. To accomplish what I'm trying to do I should set up an event listener in the main movie and remove the one from the second correct?
ActionScript Code:
wbutton.buttonMode=true;
wbutton.addEventListener(MouseEvent.CLICK,onClick);
function onClick(event:MouseEvent):void {
var box:Loader= new Loader();
var urlrHome:URLRequest = new URLRequest("popup.swf")
addChild(box);
var myTween:Tween = new Tween(this, "y",Exponential.easeOut, 600, 0, 1, true)
box.load(urlrHome);
}
Returning The Instance Name Of A Class From Within The Instance
Hi,
I'm trying to do some error reporting in my actionscript.
I have a class MyData which can be instantiated several times over in each project e.g.
var myData1:MyData = new MyData();
var myData2:MyData = new MyData();
In the error reporting I have put statements like
trace("MyData.loadData reports error.... message...");
However, I'd really like it to return the instantiated name, not the generic class name so that I can trace errors to the particular instance that is failing. Does anyone know how to do this? I've tried
trace(this.toString() + " reports error.... message...");
but I just get a name of [object object] which isn't that helpful!
Many thanks!
Referencing Different Keyframes Inside An Embedded File
Hi everyone,
I have another rookie question. I am teaching myself flash and I have come across a problem that has got me stumped. Here it is:
I need to reference different keyframes inside and embedded swf file (sport.swf) from the menu buttons of main file(athletes.swf). Does anyone know the functions to do this?
Thanks for your help,
Robb
XML - Referencing A Text Box Inside Two Movie Clips
I currently have a text box ('text_txt') inside two movie clips ('Section3_mc' and 'Part1_mc').
I am using an XML file to populate this text box.
I am currently using the following code to do this:
Code:
_root.Section3_mc.Part1_mc.text_txt.htmlText=myXML.firstChild.childNodes[0].childNodes[4].childNodes[0].childNodes[1].childNodes[36].firstChild.nodeValue
The reason it is HTML text is that I'm using CDATA tags within the XML.
Why doesn't it work, though?
I'm assuming I have to place the above code outside all the movie clips and in a frame in the root of the Flash file? Would I be wrong in thinking this? Does it actually need to be in the topmost movie clip ('Part1_mc')?
Or is there something else wrong here?
Can I even reference a text box in this way?
All help is greatly appreciated.
Probelms Referencing A Class
Basically I have a class which extends EventDispatcher (DropDownMenu) and creates instances of another class(MenuButton) dynamically the first class is a menu the second the menu buttons for that menu.
It was all working fine until I make and instance of the dropdown menu which then makes instances of buttons and although the classpath is correct it will not make an instance of the button
this["menuMC"+i] = new MenuButton(dropMenu_mc, p_obj.eventName, 1, 1, p_obj.txt, "VP-100-256-639", "icon_mc", p_obj.iconType, 10, yPos);
unless I first declare this["menuMC"+0] = new MenuButton(); explictily in DropDownMenu constructor which defeats the dynamicnesss of it as I dont want to predeclare the vars because I dont know how many buttons there are going to be.
Has anyone experienced anything like this - its like the class has no scope in the parent class unless it is first declared in constructor - any help would be appreciated.
AS2 Class Object Referencing
Okay, so I have an object which is derived from mty DrawGrid3d class which works lovely. The draw3d class extends the movie clip class and has a constructor methos which believe it or not builds a 3d grid. Now I cant seem to be able to refer to the objects properties in any way. for example the code below traces out 'undefined'.
Any ideas?
Cheers
Code:
my_grid3d=new DrawGrid3D(_root,130,100,16,16,12,18,176,5.9,0xC5D7FE,0xFFFFFF)
trace("GRID IS:"+my_grid3d._x)
Referencing Stage From Class
Hello,
I am trying to make my first as3 class based game and so i was wondering if i could get some help. although the game wont have fancy graphics, i just would like to understand the way it works...currently, i am at a point where im getting :
1067: Implicit coercion of a value of type flash.display:Stage to an unrelated type Stage.
in my main file robot.fla, im using
var robo:robot=new robot(stage);
//var starenemy:enemy1=new enemy1(this.stage);
addChild(robo);
inside that robot.as
....
public class robot extends Sprite {
import flash.display.Stage;
private var _stage:Stage;
....
public function robot(stageRef:Stage):void {
_stage = stageRef;
...
}
amongst other things and i cant reference anything from the stage.
I think im going nuts trying to figure out how to correctly reference things to the stage. so can you take a look and guide me and tell me how i can proceed?
Attached is the zip file
Referencing Class Methods.
Hi,
I am have a class which I am instantiating in the first frame of a movie.
The class has a method called statecheck which I would like to access from a movie clip symbol.
I can reference the method easily from the first frame. what is the correct way of referencing it from the movieclip?
import Tpanel
var public panel:Tpanel = new Tpanel;
panel.statecheck(this); // works
the same line of code in the movieclip symbol does not.
also
_root.panel.statecheck(this); // does not work in as3
Cheers
Matt
Help Referencing A Visual MC From Another Class
I have a fla file with visual content onstage. This Fla also has a document class assigned called Home(extends Movieclip.) One of the visual assets onstage is a movieclip called mcHome that the Home class controls successfully.
I’ve got another class, Photos(extends Sprite) that I have imported(from another package) and it also successfully does what it’s suppose to. However, when I add code to Photos to refer to mcHome, the onstage movieclip, I get an
1120 access of undefined property mcHome error
What is necessary to make Photos understand what mcHome is?
Thanks
Delete Instance Of Class From Class' Method
So I have a class called Unit. When I use this class in a .fla file, I create it by saying:
var unit00:Unit = new Unit(...);
So then it creates a gfx representation of the screen for me. I would like to have a method like this:
PHP Code:
public function remove ():Void { unit_mc.removeMovieClip(); //deleting the gfx representation of the class in the .fla delete instance of this; //I want to delete the variable that references the instance of this class}
So how do I get this to work? I know that delete this will not work when defined inside the class. How do I target the .fla's instance name when I don't know what it will be called?
Thanks for any assistance
Referencing A Clip Inside A Scroll Pane Component?
can someone please tell me how to reference am MC placed inside a scroll pane component?
so i can controll it with actionscript
i tried giving the scroll pane instance a name and then using the name as though it was just part of the path but it doesnt work.....what am i doing wrong???
please ...help
Referencing Instances Inside The Symbol (CS3/4) From A Pure AS3 File
Hello everyone,
now I know this is an ancient question, and there are a million threads out there that discuss this, but they're all a bit chaotic... I've gotten all of my work in AS3 done in a pure code way, and all of my graphics have been programmatic, but now its time to load up some CS3 graphics, and Im running into walls...
I have a symbol, and inside of it I have bunch of other symbols with instance names assigned...
- how would I go about accessing these if I loaded the SWF with that symbol in it?
- how would I create an instance of that main symbol, from a loaded SWF?
help is much appreciated
thank you
Referencing A Subclip From Within A Class File
Say I have the following movieClip Structure
myMovieClip
myMovieClip.subMovieClip
I want to make a Class file for myMovieClip
I would like this Class to reference and adjust the subMovieClip._y using commands from the class file.
I keep getting errors when trying to do this. Is this a matter of syntax or is there no way to reference another movieClip from a class file?
Thanks
Dynamic Class Referencing Question
Quick question, I'm sure this is a stupid syntax problem...
Code:
fighter1_mc.aiPattern="SwoopDown";
fighterPattern = new classes.ai_routines[fighter1_mc.aiPattern](this, 20, 1, 5, 5);
fighterPattern = new classes.ai_routines.SwoopDown(this, 20, 1, 5, 5);
The second one creates the object as it is supposed to, but the first one does not. What is the correct way to dynamically reference the object?
Thanks in Advance
Problems Referencing Parent Class
I would like to have a child access the properties of the parent class and I've read _parent allows you to reference a parent object. However, I can't seem to get it to work. Here's an example.
Code:
class test{
public var name:String;
public var Test:test2;
function test(){
name = "testSring";
Test = new test2();
}
}
class test2{
function test2(){
var This:Object = this;
trace(This._parent.name);
}
}
//in the .fla
var Test:test = new test();
If I run it, I will get "undefined".
|