Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    Flash




Referencing Timeline Variables From A Class



Yet another question..How do I referece, within a class function, variables residing in the timeline that is invoking the class? (Very beginner here!)

So far I've had to send the timeline variables from the timeline to the class's function as parameters, which works, but there's so many. And I know I can just make these variables reside in _root and reference them this way, but that is not smart.

Does it have to do with _parent at all? Tried using it but failed..

Thanks.



KirupaForum > Flash > Flash 8 (and earlier) > Flash MX 2004
Posted on: 06-02-2005, 01:40 PM


View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread

[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 The Root Timeline Within Using _root In A Class
I have a class that I wrote and I need to reference the root timline but I can't use _root to do that because my movie will be loaded into another movie. Is there another way to reference root?... maybe a _global variable? If so, how would I set up that global variable on the root timline and then use it in the class?

Thanks.

Movieclip In Library Referencing Variables In Main Document Class
I have a main.fla and a main document class (main.as)

Within the main.fla file I have a movieclip in the library with the linkage id of "myMC" and it is exported within the first frame.

Within that movieclip I have two images that I would like to attach ToolTips to, however, the key is to reference the text for the tooltips from XML as I have done previously through the main.as class.

I keep getting this error Access of undefined property toolTip and XML_mc

Here is the code within myMC in the library

ActionScript Code:

_button1.addEventListener(MouseEvent.ROLL_OVER, launchToolTip);
function launchToolTip(event:MouseEvent):void {
toolTip.addTip(XML_mc.preferences.imageAltText);
}




Note: In main.as I have toolTip and XML_mc both referenced as public variables within the package.

Any ideas?

Referencing Clips On Main Timeline From My Main Document Class
Hi All,

I'm trying to reference clips on the main timeline either in or via my main Document class, but if I declare any clips as public in the class body as I would have done is AS when linking an external class, I get:


Code:
1151: A conflict exists with definition tfLength in namespace internal.
If I don't declare the clip, then I can reference it from within the same class with this.tfLength, but other classes complain it the Document classes tfLength variable doesn't exist!

So how do I reference a clip on the timeline in my class?

Thanks,
Dave

Is It Possible To Access Class Variables From Timeline?
Hello there
I have a document class myClass, where i set a variable:

Code:
var playhead:String = new String("");
index_menu_bar.menu_bar.btn_menu.addEventListener(MouseEvent.MOUSE_OVER, MouseOverBar);
function MouseOverBar(e:MouseEvent):void{
index_menu_bar.playhead = "hs";
index_menu_bar.play();
}
and in the timeline I have a movie clip index_menu_bar inside it, say in frame 25 I have this script hat tries to get the variable from the class

Code:
stop();
gotoAndPlay(playhead);
but i got error:

Code:
1120 : access to undifined property playhead
as you can see i already defined this property on my class!!
any clews?
thanx

[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 Another Timeline
i've got 2 movieclips "primaryMC" and "secondaryMC". secondaryMC is inside primaryMC and is brought about by a button that is also inside primaryMC.

i need primaryMC to _root to the MAIN timeline and secondaryMC to reference the primaryMC timeline.

How is this done without making the primaryMC reference itself with the _lockroot command?

Referencing Main Timeline
I have a button in a movie clip(ab) I want the button to reference the main timeline (gotoAndPlay Label1 in the main timeline) can someone help me with this.

Thanks

Referencing Component Timeline
How do I refer to the timeline or an instance of a component. I just finished making a flash application in the main timeline of a movie, (http://www.52oz.com/projects/messagesWithBottom.swf ). I want to convert this into a component now. But all my referentes to _root obviousely mess up the functionality as a component. What should I replace _root to, so that it will be a direct referente to the timeline of the component? Thanks.

Referencing Wrong Timeline?
Hi, Please help!
On this page: http://www.dcssound.com/Kelly%20Website/intro.html, go to the Product tab, and select the "In-Wall Speaker" then select "LEW Series" and click on it. Notice NOTHING happens.
http://www.dcssound.com/Kelly%20Website/intro.html

On this page: http://www.dcssound.com/Kelly%20Website/product.swf
Do the same thing; select "In-Wall Speaker" then "LEW Series" and click. Nothing a list of speakers NOW SHOWS.

There is NOTHING as far as coding and design between these two pages. the ONLY different is that in the "Intro.html" page, I placed product.swf inside it(using a loader component).

The codes where I load the "LEW Series" images is this:

lew.onRelease = function(){
mcLoader.loadClip("lew.swf",_root.picViewer_mc.speakerloader);
}

Why does it work when it is in produc.swf itself but does not work when it is int Intro.html?

Thank you.

Referencing The Main Timeline From Elsewhere
From inside a movie clip (button) which is inside a display object (buttonSet), I want to gotoAndPlay a specific frame on the main timeline. I've tried stage.gotoAndPlay(thisFrame). I got closer with gotoAndPlay(stage.thisFrame). I still have something wrong.

I have about 15 frames on the main timeline. Each frame contains a myriad of objects all doing different things. Most importantly they transition from frame to frame based on the current frame (last button clicked) and the next frame (the newly clicked button).

Example: the last button that was clicked was button #4, the button I have just clicked is button #2. Based on this knowledge, I want the main timeline to gotoAndPlay frame #6.

Thanks for the aid. :)

Referencing Variable On Another Timeline
Hi gang,

I've got a simple scenario which has been causing some distress and confusion for me. I have a movie clip placed on the stage, which has a variable defined within it. My question is...how can I reference that variable from the _root timeline, without instantiating any on{} statements?

Sounds simple, yes...but I'm unable to do this. I've tried setting the variable in a variety of ways (var, global, Object, etc). No matter how that variable is set, I simply cannot reference from the main timeline, without reading the variable in an on statement block

ex.
trace(_root.mcTest.strTest); // invalid

on(press) {
trace(_root.mcTest.strTest); // correct
}

Thanks in advance to anybody who can enlighten me.

Referencing Root Timeline From Within A Mc
Hi,

This is probably a really simple question....

I have a root timeline in which contains a movie clip on a certain frame.

Inside that movieclip, on it's second frame, there is a button.

I would like to use this button, when clicked, to move take the user to a frame on the root timeline.

Anyone know the how to do this.

Peace to all mankind.

Referencing The Root Timeline
Ok, so my problem stems from my dependence on the _root object in AS2.0

If I have a movieclip that I want to call a function that is on the main timeline, which reference would I use? I tried root.testFunc() to call said function, but got no play.

Any ideas?

Referencing Variable On Another Timeline
Hi gang,

I've got a simple scenario which has been causing some distress and confusion for me. I have a movie clip placed on the stage, which has a variable defined within it. My question is...how can I reference that variable from the _root timeline, without instantiating any on{} statements?

Sounds simple, yes...but I'm unable to do this. I've tried setting the variable in a variety of ways (var, global, Object, etc). No matter how that variable is set, I simply cannot reference from the main timeline, without reading the variable in an on statement block

ex.
trace(_root.mcTest.strTest); // invalid

on(press) {
trace(_root.mcTest.strTest); // correct
}

Thanks in advance to anybody who can enlighten me.

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!

Referencing Main Timeline From External Swf?
lo all.

here's the deal.
I've made a main movie with different scenes. I've also made another movie with forward and back buttons on it to control the main movie. The control movie is loaded into level1000 so it's always on top.

I've put the following code on the button in the loaded swf.

//this SHOULD change the scene on the MAIN movie.

on (release) {
_level0.nextScene();
}

it's not working though.. I can only assume it's going to level0 of the control movie and not the main movie. I've had a quick look through the forums and can't find an answer. I'm hoping someone here will help me out.

If anyone want to have a look at the files then just ask and I'll post a url.

cheers

Specimen
www.the-nervous-system.co.uk

Timeline Control & Object Referencing
Hi,

I'm wondering what the proper ActionScript is to control a timeline within an event handler function. In an xml.onLoad function I want to send the main playhead to a certain frame based on the content of the XML. The only way I have found to do this is using _root.gotoAndPlay within the {} of the onLoad function; using gotoAndPlay, this.gotoAndPlay, this._parent.gotoAndPlay etc. doesn't work. These would of course work if they weren't within the onLoad function -- thus something about being within an object function changes positioning/referencing of movie clips and timeline control.

_root is a workaround and it's not perfect. any ideas on how to properly control timelines from within functions such as xml.onLoad?

Thanks in advance!

External .as Referencing Timeline MovieClips
Hi,
I have a flash file which has an Movieclip "Inventory" in the library that is linked to its own external class file that is responsible for its behaviors. Within this movieclip there is another clip that is on the stage called "LevelIndicator".

I'm trying to get the external class "Inventory" to refer to "LevelIndicator" but i'm not sure how to target it in the code of the external class.

for example i have the following function within the Inventory class:
function getLevel():Number{return LevelIndicator._y;}

Actionscript produces an error saying there is no property with the name LevelIndicator.

Is it possible to target these clips, or would they have to be attached within the class itself?

Referencing The Main Timeline From A Movieclip
So I have a movieclip on frame1 of the main time line.

Once the movieclip as finished playing I want to add a line of code that tells the playhead on the main time line to gotoandplay frame 2.

If I add
Code:
gotoAndPlay(2);
predictably the movieclip repeats itself, how do i reference the main play head. I tried
Code:
_root.gotoAndPlay(2);
but it didnt like it

Any ideas?
Many Thanks

Referencing Movieclips On Main Timeline
Hi, I know this issue has been talked about a considerable amount on here and other places. I did my fair share of searching and trying a few different methods.. but nothing has worked for me yet.

I have movieclips I created sitting on the stage of the main timeline with instance names deck, titles, stats, and ui.

In frame 2 of a movieclip INSIDE the ui movieclip, I'm trying to reference the movieclips sitting on the main timeline.

I do not have a main document class- its making its own when i run the swf.


Code:
this.parent.stats
// this throws an error: 1119: Access of possibly undefined property stats through a reference with static type flash.display:DisplayObjectContainer.

this.root.stats
// this throws an error: 1119: Access of possibly undefined property stats through a reference with static type flash.display:DisplayObject.
So I also tried creating a dummy mc on the nested movieclips stage and using it to access the root.. and after that failed I tried tying the movieclips on the main timeline to a classname and adding it to the stage with code so i could type it as a movieclip.. no luck there either.. examples below


Code:
dummy.root.stats
//throws the same error as above

var stats:MovieClip = new Stats();
addChild(stats);
//didn't change a thing
As you can see I'm stretching quite a bit What's the correct to do this from code on the timeline? I'd like to not have to make this completely class based if possible.. is that the only way?

Thanks for any suggestions!
Alan

Having Trouble Referencing To The Main Timeline.
Hi, I'm working on a game for this class I'm taking.
It's a maze sort of thing and I want it to go to a losing screen when you run out of time.
This losing screen is on frame 122 of the main timeline.
I have the actual maze on only one frame, with a stop action.
The timer is a movie clip that lasts for 720 frames, just the hand going around once for 60 sec. When I try to have it gotoAndPlay at the end it goes to the frame on the timer movie clip, not the main timeline.
This is what I have, but doesn't work:

gotoAndPlay ("Scene 1", 122);

I tried everything I could think of, everything I try plays the frame 122 for the timer movie clip. So I thought that maybe I wasn't using the correct reference, so I tried this:

gotoAndPlay ("dfsgdfs", 122);

And it still played the frame for 122 on the timer clip. So I know that it doesn't think that Scene 1 is the timer clip, I'm just telling it the wrong thing.
So... yah, can someone help me with this? Please?
I just need it to play from 122 on the main timeline, thanks.

Referencing Root Timeline Within Loaded Movie
Hi, I've got a movieclip that's going to be loaded by the main stage and I'd like to know what the correct path would be inside the clip to access it's local main stage, since _root will be the parent movie clip.
The module worked fine on its own when I made _root references but now that it is to be loaded by another movie I have to replace _root with a different path. I'm somewhat familiar with levels and have been trying different things but to no avail.

Problem Referencing MAIN Timeline From Embedded SWF
Here is my problem.

I have a projector file on a cdrom.
The projector file has three scenes, INTRO, INDEX, and VIDEO INDEX.

At the begining of the cd-rom you are presented to watch a video or tour the cd-rom. the cd-rom loads a bunch of different .swf files according to what section you pick. this all works fine. When you choose to load the video at the prompt the button takes you to the INDEX VIDEO scene where the video is loaded into a dummyMC from an external .swf file.

Here is the problem, what I need to do is have the video unload, (or not if it doesnt matter that it is now inside the dummyMC) then after it is doen playing (at the last frame of that .swf) I need it to go back to the original cdrom/video prompt. So what I need the video.swf to do is go to a frame label in the INTRO scene on the main timeline of the projector. IS IT POSSIBLE to have the video.swf movie go to a frame label on the MAIN projector timeline??

if so what would be the code.

PLEASE help In dying here I have tried everything.


Thanks.

If you help I will personanlly mail you a home cooked cookie.

Referencing Function In Main Timeline From Loaded .swf
Hi,

I have a movie where I'm loading a .swf using placeholderMC.loadMovie("somemovie.swf");

Once the movie is loaded, I tell it to play, and it plays.

However, I'm needing to know when this movie has finished playing.

I put some code in the last frame of "somemovie.swf" to call a function in the main timeline.

_root.someFunction();

But it won't work.

How do I call the main timeline from a loaded .swf.

Thanks,

The Alchemist

[F8] Global Functions And Referencing The Calling Timeline
I am trying to have a single global function that handles the button presses (and results thereof) for the menubar on my website. The problem I am running into is how do I make sure that when the global function (defined on the first frame of _root) references the movieclip that calls it.

so, for example if I do something like this:

_global.ButtonClick = function () {
this.play();
}

and on the movie clip I..

on(release){
ButtonClick();
}

How do I make it so the global function plays the the timeline of the calling movieclip? Thanks for any help!

--David

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 A Button On Frame 2 Of MC From Main Timeline
I have these two addEventListener's on my main timeline.


ActionScript Code:
// back1_btn is on frame 1 of loadWindow_clip
loadWindow_clip.back1_btn.addEventListener (MouseEvent.CLICK, clickedgoBack1);

// back2_btn is on frame 2 of loadWindow_clip
loadWindow_clip.back2_btn.addEventListener (MouseEvent.CLICK, clickedgoBack2);


When I test the movie, I receive the following error:
TypeError: Error #1009: Cannot access a property or method of a null object reference.

If I remove:

ActionScript Code:
loadWindow_clip.back2_btn.addEventListener (MouseEvent.CLICK, clickedgoBack2);

I don't receive the error.

The movieclip, loadWindow_clip, has 2 frames. Frame 1 and frame 2.

On frame 1 of loadWindow_clip I have a button, instance named: back1_btn
On frame 2 of loadWindow_clip I have a button, instance named: back2_btn

What it looks like to me is that I cannot make reference to any other frame other than frame 1 of another movieclip, from the main timeline.

Am I correct?

What Is The Simple Equivalent For Referencing The _root Timeline?
I've got a .swf (movie B) that gets loaded into a clip in my main movie(movie A). Movie B needs to control another clip within movie A.

In AS2, i would simply start off with a _global var on the main _root timeline, like this:

_global.home=this;

then, later in my seconday movie (movie B) i would reference that timeline simply like: home.myClip.gotoAndStop("whatever");

What is the simple equivalent for referencing the _root timeline? I've tried _parent with no results.

I'm looking forward to utilizing classes more, but for now I've got timeline code (on a single frame at least), with aspirations of moving toward a 'class-based' development style.

thanks for any help!

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

Class Question: How To Access Timeline Objects From Class W/o Arguments
Hey all,

I am looking into builiding an application with OO functionality. I understand most of it. Except I cannot figure out how to access something in my app from a class. For instance, lets say I have one Loader class that loads some data and stores it in a variable inside the class (or on the main timeline, doesn't matter). Now, I know I can pass a reference to the data in an argument to another class for that class to manipulate. But if I have several data sources, and other variables and such, that I need to modify in a single class function, how would I do that without having to give the function access to them through arguments? I just want to be able to say, from a class, something like _root.someObject.someFunction();

So, any help would be greatly appreciated, and sorry if that made no sense at all, I tried to explain as best I could.

Happy Holidays!
Dave

AddChild Works With Document Class, But Not Timeline-instantiated Class
I cannot get a sprite to display for me when I create an instance of a very simple class in my FLA file's timeline.
However, when I make the class file the FLA's document class file, it displays just fine.
The task in question is simply drawing a square with the shape class.

Problem example:
My class, Test.as, resides in the same folder as my FLA file - so I don't use any import statement. I'm new to lots of CS3 stuff. Can anyone tell me why this doesn't work and create the shape on the stage? This seems to fail silently without any errors:
var myTest:Test = new Test();

Working example:
Setting the document class to Test.










Attach Code

// Test class

package {
import flash.display.*;

public class Test extends Sprite {

public function Test():void{
doThing();
}

private function doThing():void{
var myRect:Shape = new Shape();
myRect.graphics.lineStyle (2, 0xcc0000, 1);
myRect.graphics.beginFill(0xcccccc, 1);
myRect.graphics.drawRect(10, 10, 200, 200);
addChild(myRect);
}
}
}

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

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?

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".

Referencing Stage.stageWidth From A Class
I created a custom class in a .as file. I then linked this custom class with a symbol from the library in my .fla file. However, I can't reference stage.stageWidth in my custom class file. I get a null object error.

I think this happens because the custom class file is associated with a symbol on the stage and not the stage itself. For example, if I set the fla file's Document Class to the name of my custom class I can reference stage.stageWidth in the custom class. But I don't do this because I am creating multiple instances of the symbol on the stage. In order to do that properly i found I have to set the class in the properties panel of the symbol to the underlying class which then defines how each symbol behaves.

Under this type of linkage, is there a way to reference the stage width from the class?

I've tried root.stage.stageWidth and parent.stage.stageWidth to no avail. I also made sure to import flash.display.* in my custom class.

Below is the code for my .fla file and my .as file. In the .as file you'll see the line "x = Math.random() * stage.stageWidth;". This is the line giving me problems. I could hard code it, as I do for the y variable on the next line, but I'd prefer not to in order to keep the code flexible.

I also attached the files in a zip.

Any help would be appreciated.


ActionScript Code:
//.fla code

var i:int;

for(i=0; i < 100; i++){
    var myBall:flaBall = new flaBall();
    addChild(myBall);
}


//.as code

package {
   
    import flash.display.*;
    import flash.events.Event;
   
   
    public class Ball extends MovieClip{
       
        var dx:Number;
        var dy:Number;
       
        public function Ball(){
            addEventListener(Event.ENTER_FRAME, onEnterFrame2);
            reset();
        }
       
        private function reset(){
            x = Math.random() * stage.stageWidth;
            y = Math.random() * 400;
            dx = Math.random() * 20 - 10;
            dy = Math.random() * 20 - 10;
        }
       
        private function onEnterFrame2(event:Event):void{
            move();
            checkBounds();
        }
       
        private function move(){
            x += dx;
            y += dy;
        }
       
        private function checkBounds(){
            if (x > 550 || x < 0){
                dx *= -1;
            }
            if (y > 400 || y < 0){
                dy *= -1;
            }
        }
    }
}

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.

Thanks

Rich

Referencing Stage From External Class
I have an external class file that extends the MovieClip class and is linked to a movieClip on the main stage. I need it to be able to access properties of other movieclips on the main stage. How could I do this. Here is what my base movieclip class that I want to access the stage with looks like. Remember, it is linked to a movieclip on the stage, if that matters...
Obviously there is more code in the class, but I removed it for the sake of simplicity.







Attach Code

package{
import flash.display.MovieClip;
import flash.display.DisplayObject;
import Math;

public class Test extends MovieClip{

public function Test(){ //Constructor

}
}
}

Referencing Stage.stageWidth From A Class
I created a custom class in a .as file. I then linked this custom class with an symbol from the library in my .fla file. However, I can't reference stage.stageWidth in my custom class file. I get a null object error.

I think this happens because the custom class file is associated with a symbol on the stage and not the stage itself. For example, if I set the fla file's Document Class to the name of my custom class I can reference stage.stageWidth in the custom class. But I don't do this because I am creating multiple instances of the symbol on the stage. In order to do that properly i found I have to set the class in the properties panel of the symbol to the underlying class which then defines how each symbol behaves.

Under this type of linkage, is there a way to reference the stage width from the class?

I've tried root.stage.stageWidth and parent.stage.stageWidth to no avail. I also made sure to import flash.display.* in my custom class.

Any help would be appreciated.

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

Referencing A Movie Clip From A Class .as File
Okay, so I'm making a game. I've made various class files for various elements on the screen and used linkage to make the movie clips on screen members of my custom classes (by right clicking on the movie clip in the library and selecting linkage, etc). But I'm having an issue...
I can't reference child movie clips. So say I have a movie clip called "sea", and within it I have one called "fish" (instance name, of course). I use linkage to make "sea" a member of my custom "SeaClass" class. However if I try to do something like this.fish.gotoAndStop(5); I get an error saying that there is no property "fish". I understand that it's looking for a "fish" function instead of the "fish" subclip, but is there any way to make it reference the subclip?
This is a big issue because I'm having to use a lot of onClipEvent(enterFrame) variable checks for my subclips and whatnot to make them execute something instead of being able to put the command straight in a function and its really bogging down code.
I hope this makes sense... thanks in advance for the help!

Referencing A Parent Method From A SimpleButton Class
I'm new to AS3 (know AS2 fairly well), and am having trouble wrapping my head around OOP methods of doing things. I know it will keep things organized and more modular, so I'm trying to learn, but am having trouble...

Specifically, I've defined a method called showScreen within the document class (Main). I've also defined a NavButton class that's attached to a hand full of simple buttons objects. The only problem is that, when one of the buttons is clicked, I receive an error that the parent class's method (showScreen) isn't defined.

1061: Call to a possibly undefined method showScreen through a reference with static type flash.display:DisplayObjectContainer.

(It's worth noting that I'm still learning to read those fancy new errors, and that making things public / private / static have only confused me further as to their relevance to my problem.)


PHP Code:



// Main.as... abridged to save you time
package com.as3Adventures
{
    public class Main extends MovieClip
    {
        function Main()
        {
            // sets up the elements on the stage, etc
        }
        public function showScreen(which:String):void
        {
            // animates the old screen out and displays
            // another, based on the variable passed
            
            // this is the method I want to call
        }
    }
}




And


PHP Code:



// NavButton.as... also abridged
package com.as3Adventures
{
    public class NavButton extends SimpleButton
    {
        function NavButton()
        {
            // sets up the button...
            addEventListener (MouseEvent.CLICK, clickHandler);

        }
        function clickHandler (e:MouseEvent):void
        {
            // does a little magic with the button, animating, etc... then...

            trace(parent);  // returns "[object Main]"
            parent.showScreen(this.name);  // <------------ Causes headaches
        }
    }
}




I suspect that making NavButton extend MovieClip rather than SimpleButton would fix this (am I wrong? I have no idea), but doing so breaks the functionality for the button that's already been written. And besides, this seems like a fairly common thing to do - calling a method from a button.

What am I doing wrong? Any help would be much appreciated.

Copyright © 2005-08 www.BigResource.com, All rights reserved