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




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!



FlashKit > Flash Help > Flash ActionScript
Posted on: 12-06-2005, 05:44 PM


View Complete Forum Thread with Replies

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

Referencing Nested Movie Clips From A Class File
Hey guys, its me again. With yet another question.

I am writing a class that extends the movie clip class and am having trouble with a certain part.

I have a Movieclip, and nested inside this movie clip are several other movie clips. The "Main" Movieclip has the linkage set to my class file. I have tried to link all the clips inside it to my class file but that didn't seem to work. When i go to change the image/Movie in say the 3rd nested clip it seems to change the image/movie of the "Hosting" movieclip. Is there any way to reference the nested clips from inside my class file?

As always thank you for any help that you may be able to give.


Lazerath

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

Dynamically Referencing An External Class (not Embedded Movie Clips)
I've seen several posts for how to dynamically attach movie clips from the library, since they become their own classes. This question is how to dynamically refer to external classes.

The example that showed this was:

function createNewChart(myChart:int){
var classRef:Class=getDefinitionByName("chart"+myChart) as Class;
var newChart:*=new classRef();
}

I want to instantiate an external class versus a movieclip, and using this code outright is not the trick - I get an error (Error #1065: Variable MyClass is not defined.) from the following:

var presentationClass:String = classNameFromXmlFile; // MyClass
var classRef:Class = getDefinitionByName(classFromXMLfile) as Class;
var myClassInstance:* = new classRef();

I know that hard-coding the class here does work, so the class itself is fine, as in the following:
var myClassInstance:MyClass = new MyClass();

What is the proper syntax for dynamically doing this?

Referencing A Movie Clip
I have a button which calls the below code:

_root.movie.chapter+varChapter.play();

I have a series of frames with MC named chapter1, chapter2 etc. How do I dynamically reference a MC?

_root.movie. #### MC here to be referenced dynamically ####.play()

I have tried _root.movie.chapter where chapter is set using:

varChapter = "chapter1"

or varChapter = 1

and then

chapter + varChapter


but this does not work?

Referencing A Movie Clip
Hi all. I'm a bit new to AS3 and have a pretty simple question. Here is my code.


Code:
function loadXML(loaded) {
if (loaded) {

_root.inventor = this.firstChild.childNodes[0].childNodes[0].firstChild.nodeValue;
_root.comments = this.firstChild.childNodes[0].childNodes[1].firstChild.nodeValue;

text_1.text = _root.inventor;
text_2.text = _root.comments;

} else {
trace("file not loaded!");
}
}
xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load("inventors.xml");
but what if the text boxes (text_1 and text_2) are inside of a movieclip called mc_background? how do I reference this in the code - obviously not using _root...but?

I'm a newbie as you can see, but am working on it.

Regards
~ Steven

Parent Movie Clip Referencing
How do I reference two levels above a mc?
Is is _parent._parent ?

I have a mc with a mc inside that has a mc inside. The third mc I want to talk back to the first one.

Not working for me.

Referencing A Button In A Movie Clip
I think i have the right idea, and i'm pretty sure i've done this before but can't remember how.

I have a button symbol (button-restore) in a movieclip (movie-topbar), and the movieclip is on the main timeline.

When the button-restore button is clicked I want it to disappear, and another button symbol (button-maximize) to appear (the button-maximize symbol is already present in the movie clip, but just has a visiblity of 0)

I've been trying this action for the button-restore button:

Code:
on (release) {
setProperty ("button-restore", _visible, false);
setProperty ("button-maximize", _visible, true);
}
--> I've also tried referencing the buttons by doing: _root.movie-topbar-button-restore, and this doesn't seem to work either.

Any ideas?

Referencing Duplicated Movie Clip
I'm trying to get the height of a duplicated movie clip that was created as: -

duplicateMovieClip (_root.my_movie, "my_movie"+i, i);

Where i is a number incrementing from 0 to whatever. How do I reference the movie I just created? Having troubles with syntax, currently using: -

getProperty(_root.my_movie+i, _y)

but doesn't seem to work, I'm guessing its the +i that is inncorrect?

Help much appreciated, thanks

[F8] Referencing A Button In A Movie Clip
I know this is an easy one, but I can't figure this out for the life of me. I have a button called mute_btn inside a movieclip muter on the main timeline. I want to write this script

mute_btn.enabled = false;

but how would i write it for the mute button since it's inside the movie clip because as it this doesnt work.

Thanks for you time and patience.

Cheers!

Problem Referencing A Movie Clip.
... I have a movie clip that has buttons on it....

... When I use the following code from the stage, it makes my movie clip "links_mc" rotate as intended.

import fl.transitions.*;
import fl.transitions.easing.*;

TransitionManager.start(links_mc, {type:Rotate, direction:Transition.IN, duration:1, easing:Strong.easeInOut, ccw:false, degrees:45});

However, when I try to use this same code from one of the buttons in the movie clip, it tells me the error: 1120: Access of undefined property links_mc.

How do I reference the movie clip correctly from one of the buttons?

-Xian
Using Flash CS3.

Problem Referencing A Movie Clip.
Posted in the newbie forum, no response, trying here!

... I have a movie clip that has buttons on it....

... When I use the following code from the stage, it makes my movie clip "links_mc" rotate as intended.

import fl.transitions.*;
import fl.transitions.easing.*;

TransitionManager.start(links_mc, {type:Rotate, direction:Transition.IN, duration:1, easing:Strong.easeInOut, ccw:false, degrees:45});

Obviously, nothing complicated here... however, when I try to use this same code in a button in the movie clip, it tells me the error: 1120: Access of undefined property links_mc. How do I reference links_mc correctly from within the movie clip (not the stage)?

-Xian
Using Flash CS3.

Referencing Dynamic Movie Clip ID's
Hi All,

I have an interactive map where I am loading "buttons" through a database using attachMovie(). I can position the button appropriately, change the color, etc. But I cannot set the button to have a specific ID. For example, if I have 3 buttons I would like to name them button_1, button_2 and button_3 respectively so I could call other stuff out of the database based on the button referenced.

below is my code for loading the buttons to the screen.


ActionScript Code:
var positions:XML = new XML();
    positions.ignoreWhite = true;
    positions.onLoad = function(success)
    {
        placeDots();
    }
    positions.load("test.php");

   
function placeDots()
{
   
    for (var count:Number = 0; count<positions.firstChild.childNodes.length; count++)
    {
        var rootNode:XMLNode = positions.firstChild;
        var thisLot:XMLNode = rootNode.childNodes[count];
        var lotChildren:Array = thisLot.childNodes;
        var xPosition = lotChildren[0].firstChild.nodeValue;
        var yPosition = lotChildren[1].firstChild.nodeValue;
        var color = lotChildren[2].firstChild.nodeValue;
        var dotTitle = lotChildren[3].firstChild.nodeValue; 
       
        //attaches a dot out of the db and positions it to the correct location using xPosition and yPosition
        this.attachMovie("dotButton", count, this.getNextHighestDepth(),{_x:xPosition, _y:yPosition});
               
    }
}

this is my code for the button - the tooltip pop up does work properly and i can assign info to it but it has to be hard coded. or when i try to run a variable it pulls the last item out of the loop above.

ActionScript Code:
on(rollOver) {
        _global.storeID = this.id; //_global.dotName[_global.myCount];
        _global.comp = "77";
        _root.displayName(_global.storeID);
        var myTip:ToolTip = new ToolTip();
        myTip.addTip(_global.company);
    }

My xml file exports data in the following fashion:

ActionScript Code:
<?xml version="1.0" encoding="UTF-8"?>
<positions>
     <row ID="1">
          <x>25</x>
          <y>63</y>
          <availability>Available</availability>
          <dotName>Lot 1</dotName>
     </row>
</positions>

from what i have seen somehow i can reference the id of the attached movie clip using "attachedMovieClip.id" but that doesn't seem to work. I was thinking an array might possibly work but somehow i would still need to assign a variable to the button.

any help on this would be great.

thanks

Eric

Referencing Movie Clip Not Same When SWF Loaded Into SWF
This code is based on the _droptarget info in the Actionscript 2.0 language reference. It works fine by itself but breaks when the SWF is loaded into another SWF. Note that I uses the _lockroot property to keep the _root of the loaded clip.

I've isolated the problem to the "if" condition. The player doesn't seem to recognize the equivalence of the names. But when debugging with Trace, the names are identical.

The desired result is to have the drag object snap to the target object when dropped on the target but snap back to its origin if not on target. It works in 6, but the drag object snaps back to its origin 7 - as if it was not dropped on the target object.









Attach Code

this._lockroot = true;
origX = garbage_mc._x;
origY = garbage_mc._y;
targX = trashcan_mc._x;
targY = trashcan_mc._y;
garbage_mc.onPress = function() {
this.startDrag();
};
garbage_mc.onRelease = function() {
this.stopDrag();
if (eval(this._droptarget) == trashcan_mc) {
this._x = targX;
this._y = targY;
} else {
this._x = origX;
this._y = origY;
}
};

























Edited: 11/10/2006 at 07:07:59 AM by raylaur

Referencing A Movie Clip Within A Button?
i have a button that has a movie clip in it. I would like to play the movieClip on the rollOver event, but I can't get it to play. Here is what I hae got

on(rollOver) {
_root.myProjects_btn.folderZoom_mc.gotoAndPlay("st art");
}

I have also tried but it didn't work either

on(rollOver) {
this.folderZoom_mc.gotoAndPlay("start");
}

Thanks for the help

Referencing A Movie Clip Within A Button?
i have a button that has a movie clip in it. I would like to play the movieClip on the rollOver event, but I can't get it to play. Here is what I hae got

on(rollOver) {
_root.myProjects_btn.folderZoom_mc.gotoAndPlay("st art");
}

I have also tried but it didn't work either

on(rollOver) {
this.folderZoom_mc.gotoAndPlay("start");
}

Thanks for the help

[as] Movie Clip Referencing Problem
I am making an image gallery by loading dynamic movie clips from xml.

thumb.swf is a simple with a loader obejct and a frame around it..
I can load these files just fine, but can't change the width and height or access the symbols inside each MC.


ActionScript Code:
for (_global.inc=0; _global.inc<imagesArray.length; _global.inc++) {
 
createEmptyMovieClip(['thumb'+[_global.inc]], _global.inc+100);
 
loadMovie("thumb.swf", ['thumb'+[_global.inc]]);
 
 
_root['thumb'+[_global.inc]]._height = 200;
_root['thumb'+[_global.inc]]._width = 100;
               
 
 
}


if i don't include the last two lines, the swf will load just fine. however, when i try to change the width and height, the MC dissapears.

any suggestions?

Referencing A Movie Clip (Music Player Help)
I am trying to create a simlple player. (having a play, stop, next buttons etc).I want to be able to drag this (reuse it) into any new movie i create without completely coding it again. How do i go about doing this. I tried saving it as a movie then importing it into another movie...but just the graphic was imported as well as the songs and separate buttons(BUT NOT THE ACTIONSCRIPT). Can someone help!

Referencing A Movie Clip (Music Player Help)
I am trying to create a simlple player. (having a play, stop, next buttons etc).I want to be able to drag this (reuse it) into any new movie i create without completely coding it again. How do i go about doing this. I tried saving it as a movie then importing it into another movie...but just the graphic was imported as well as the songs and separate buttons(BUT NOT THE ACTIONSCRIPT). Can someone help!

Referencing Vars From External Movie Clip >>>
Hi guys,

Can you please help me to figure out how to reference the variable from externially loaded swf file? Here is what I have in my main swf file (I'm trying to trace a variable from playlist.swf but it doesn't show up):


Code:

// main swf file:

_root.createEmptyMovieClip("container_pl", 2);
_root.container_pl.loadMovie("playlist.swf");
trace("Var from external movie clip: " + container_pl.test_var);

// playlist.swf file:
var test_var = "What should I do so you can see me?"



Thanks in advance...

Newbie Question: Referencing Movie Clip
Hi

this is the code I have, but isn't working...


Code:
var letter = "t";
var movieclipname = letter + "_mc";
_root.movieclipname._alpha = 100;


you can see what I'm trying to do - but obviously don't know how to do this in actionscript!!!
when I try "_root.t_mc._alpha = 100;", it works fine.

Reason for this is that "letter" variable will be passed via a function so could be different each time.

What am I doing wrong?
cheers.

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 Movie Clip Names Dynamically?
Hi all - I've been out of the AS scene for a LONG time, but am back in now due to Flex2 and syncSWF development.

Quick, likely easy question. This has to be AS2 or lower since its syncSWF.

How can I dynamically associate a property assignment dynamically? In my case, I have an array that contains an _x, _y, and movie clip name. So the function looks like this, where the movie clip name is "a":

this.a._x = array.value[0];
this.a._y = array.value[1];

Now let's say that array.value[2] is "b". How can I dynamically change this.A._x to this.B._x via the array value[2] of "b"?

THANKS!

Referencing Movie Clip Instances Dynamically
Forgive me if I sound dumb, but I'm trying to understand dynamic instance names in AS3.

I have 15 movie clip instances on the stage, each named myClip01 through myClip15.

Users enter up to 15 names in a text field, separated by commas. I split that text field and build an array (myArray) with anywhere from 1 to 15 elements, depending on user input.

I want to display the same number of clips as elements in the array by setting visibility of all clips to false, then going through the array and setting visibility to true for the number of elements in the array.

I then want to set a text field within each clip to the text of the respective array element, but I'm confused by AS3:

This doesn't work:

for (var i:Number = 0; i < myArray.length; i++){
myClip[i].visible = true;
myClip[i].myTextField.text = myArray[i];
}

This used to work in AS2, but I can't seem to wrap my mind around AS3. Can someone walk me through this?

Thanks

Referencing A Movie Clip From Button Click?
Here's my dilemma. I have about 15 buttons on the stage, and I'm trying to keep my code nice and simple, so I'm looking to have one function that works for all of them, instead of 15 unique functions.

So let's say I have a button called aboutUs and also a movieclip called aboutUsMovieClip. When aboutUs is clicked, I want aboutUsMovieClip to play. Is there a way to reference it using something like:


ActionScript Code:
function playMovieClip(e:Event):void{
e.target.name+"MovieClip".play();
}

Now, I would be about 99% sure that way will not work, but I tried to give you guys the gist of what I wanna do. That way, I can name all my movie clips the same name as my button, just with "MovieClip" appended to the instance name, and only have to write one function.

Referencing A Button In An Attached Movie Clip
I am trying to code an onRelease function for a button located in a movie clip I've attached to another movie clip. It works for one button, but not for another, eventhough I think I've done them the same way. Here's the code:


Code:

his.stop();

//THIS PART WORKS
map_button_holder.map_anim_mc.btn_get_map.onRelease = function(){
map_holder.attachMovie("mapclip", "map_mc", map_holder.getNextHighestDepth());
map_button_holder.removeMovieClip("map_anim_mc");
map_button_holder.attachMovie("mapclose", "map_close_mc", map_button_holder.getNextHighestDepth());
trace("get map clicked");
}

//THIS PART DOESN'T WORK
map_button_holder.map_close_mc.btn_close_map.onRelease = function(){
map_holder.removeMovieClip("map_mc");
map_button_holder.removeMovieClip("map_close_mc");
map_button_holder.attachMovie("mapanim", "map_anim_mc", map_button_holder.getNextHighestDepth());
trace("close map clicked");
}
The movie clip "map_anim_mc" was attached (using attachMovie) to map_button_holder a few frames earlier, and btn_get_map works. Can anyone see what's wrong with my code, or what might be the problem?

Referencing Embedded Movie Clip Function.
How fo I reference a function that's inside an embedded movie clip?

I have a mc_placeholder called Page1, on that page 1 is the embedded movie clip Textarea.swf. Textarea.swf just creates a text area on it. I just want to reference a function inside Textarea.swf.

The function i'm trying to call is called hello();

I've tried:

this.Page1.hello();
_root.Page1.hello();
this.hello();
_root.hello();
this.Page1.textarea0.hello();
_root.Page1.textarea0.hello();
hello();

None of these work. What's the correct syntax?

Thanks

Referencing Sound Object Attached To A Movie Clip
Hey, I'm trying to reference a Sound object that is attached to a movie clip on the root level. I am trying to reference it from a button embedded in a movie clip. I can't get it to work from the button, even though I can get it to work from the root level. Here is the code I'm using:

Root level frame code:

createEmptyMovieClip ("movie_mc", 1);
var driveSound:Sound = new Sound("movie_mc");
driveSound.attachSound("mySound");
driveSound.start(0,999);
driveSound.setVolume(80);

Button code for button embedded in a movie clip:

on(release){
_parent.driveSound.stop();
_root.driveSound.stop();
driveSound.stop();
_parent.movie_mc.driveSound.stop();
_root.movie_mc.driveSound.stop();
movie_mc.driveSound.stop();
}

As you can see, I've tried to reference the sound clip in every way I can think to try from the button and nothing works. Please help! Thank you!

Assigning And Referencing A Root Variable In A Movie Clip
I have code inside a movie clip and need to set a variable thats on the root.

is AS2 we would just go _root.myVar = true;

but can't do that in AS3.... how can I do that now?

Referencing Duplicated Movie Clip In Separate Code Block
I have the following code:


ActionScript Code:
bubble_mc._visible = false;var bubbleCount:Number = 40;var vertMaxSpeed:Number = 10; // will be used in calculating maxiumum vertical speed for bubbles' movementdupMovie =  function ()  {    for (i=0; i<bubbleCount; i++) {        bubble_mc.duplicateMovieClip("bubble"+i+"_mc", i, {_x:Math.random()*bubble_mc._x, _y:Math.random()*bubble_mc._y, _visible:true});        with (eval("bubble"+i+"_mc")) {            _height = _width = Math.random()*bubble_mc._height;        }    }};dupMovie();onEnterFrame = function() {    for(i=0; i<bubbleCount; i++) {        var randomSpeed:Number = Math.random() * vertMaxSpeed;        "bubble"+i+"_mc"._y += randomSpeed;        if ("bubble"+i+"_mc"._y < 28) {            delete "bubble"+i+"_mc";            bubble_mc.duplicateMovieClip("bubble"+i+"_mc", i, {_x:Math.random()*bubble_mc._x, _y:Math.random()*bubble_mc._y, _visible:true});            with (eval("bubble"+i+"_mc")) {                _height = _width = Math.random()*bubble_mc._height;            }        }    }}


The problem is that Flash whines when I call


ActionScript Code:
"bubble"+i+"_mc"._y += randomSpeed;


Because it won't let me reference the duplicated movie clips that way.. is there any other way to do this?

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

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

[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 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!

Ref To Movie Clip In Parent Movie Clip Class
Utimately, this is for use in Flex, but I have a Movie Clip in Flash that I want to add multiple Movie Clips to. I would like listeners on each Movie Clip (or know when a particular Movie Clip is clicked). When exported to Flex, and one of the Movie Clips is clicked, it does something.

I have created a AS3 Class in Flash for my parent/base Movie Clip and I can add a event listener (for mouse down) to it. When I export to Flex it works fine.

My problem is, I need help with exposing/add listeners to the child movie clips in the parent/base Movie Clip so when the children are clicked in Flex, it will do something.

Can someone point me to a white paper or offer any advice?

Thanks in advance. J.

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

Referencing A Nested, Nested Movie Clip
Here's the setup.

let's say you have a movie clip called "parent" on the root timeline.
On frame 1 of the parent clip, you have another clip called "childA"
On frame 2 of the parent clip, you have a clip called "childB"

so, only childA is on frame 1, and only childB is on frame 2

also, let's say that both childA and childB each have a local function named "Add"

using dot syntax, you can call those functions from the root timeline:

_root.parent.childA.add(); or _root.parent.childB.add();

however, Flash only seems to be aware of those children that exist on the currently selected frame of the parent. In other words, if the current frame in the parent mc is 1, you can use parent.childA.add(); but not parent.childB.add();

Is there any way to be able to reference a child movie clip in a parent movie clip when the child is not on the currently selected timeline?

I can't put all the child clips on every frame, because I need to be able to print the entire parent movie clip (multiple frames, so each child can only exist in their own frames).

Thanks in advance for your help or insight!

Cheers!

Class And Movie Clip
Hi,

I have 2 questions about movie clips and classes.

1. Is it possible to create an empty movie clip and load into it in run time an external graphic and register the new movie clip with a class ?

2. If i load into a movie clip an external movie clip which include in it an empty movie clip and i want to change the graphics in it, is it possible to do it and how?

the following example show what i tried to do:
first load into movie clip "mc" the file "external mc"
_root["mc"].loadMovie("external mc",1);
now i want to load something into movie clip "empty" inside "external mc"
_root["mc"]["empty"].loadMovie("a new graphics mc"]);

after this command nothing change on the screen

Thanks
Hadass

Movie Clip Class
Hello, I'm trying to create a variable called pic1 in a for loop to control positions of an object from box i of an array.

This array has 16 boxes with a movie clip in each. Because my movie clips are all different they all have names from p1 to p16. So when I write my code:


ActionScript Code:
for(var i:int = 0; i < numPics; i++) {
        var pic0:p1 = pics[i];
        for(var j:int =  i + 1; j < numPics; j++) {
            var pic1:p1 = pics[j];

this can't work as the variable needs to reference to all of the objects in the Array pics. So tried substituting p1 with MovieClip:


ActionScript Code:
for(var i:int = 0; i < numPics; i++) {
        var pic0:MovieClip = pics[i];
        for(var j:int =  i + 1; j < numPics; j++) {
            var pic1:MovieClip = pics[j];

This doesn't work. I'm not sure what else to try. Does anyone know what I could do here?

My Own Movie Clip Class?
HI,

I have made a 3-d model in Flash of an office, where one can walk around hallways, etc. The initial version was made doing everything "inside of the fla". Now I am trying to accomplish the same thing using a class structure.

I have made a class called Room. What I want this class to do is, I send it the names of external swf files, one for the floor, ceiling, left, right and back walls and it is supposed to return the "room". This code works IF I create empty movie clips (which are then populated with the external files) that are tied to the _root.

Now, the way my application works, each room is a hallway segment. Each hallway segment's "backwall" has the next segment loaded into it, at a quarter of the size (so you can see all the way down and it's created dynamically). Because of this I obviously can't tie my empty movie clips to the _root because the second will replace the first and so on.

I'm obviously misunderstanding something here, but I thought that when I write:

class Room extends MovieClip {

that I now have at my disposal, the MovieClip object referenced by the name "Room". That "Room" IS now a MovieClip. If that's the case, when I trace this._name which returns a MovieClips instance name, it should return my Room's name given in the fla file - ie myRoom1=new Room(); should return "myRoom1" in a trace. Instead it returns undefined.

Inside of my class, I create an empty movie clip for each part (3 walls, ceiling and floor) and I need those to be referenced to the Room that is instantiated by myRoom1=new Room();

How do I do this????

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

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