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




How To Reference A Movie Clip In Main Swf From A Class?



I'm a little ahead of myself in doing AS 3 for a client - before I have complete understanding myself.

Here's where I am stuck -

In the main swf(fla) I have "presentation_mc" which is a movie clip with many keyframes. Later designers will add/remove keyframes as needed. So I also have to generate numbered buttons dynamically.

Here is the code that generates the custom buttons in the main.swf:

function placeButtons():void{
var i:int
for(i=0; i<varNumOfSections; i++){
var varTemp:Number = i + 1;
varButtonLabel = String(varTemp);
varButtonX = varButtonFirstX + (35 * i);
varButtonOver = sectionArray[i];

var b1:Button_mc = new Button_mc(varButtonLabel, varButtonX, varButtonY, varButtonOver);

mySprite.addChild(b1);
}
}

----- end code in main.swf

Here is the custom class for Button_mc:

package{

import flash.display.MovieClip;
import flash.text.TextField;
import flash.events.MouseEvent;

public class Button_mc extends MovieClip{
public var varLabel:String;
public var varX:Number;
public var varY:Number;
public var varOver:String;

public function Button_mc(varLabel, varX, varY, varOver){
this.label_txt.mouseEnabled = false;
this.label_txt.text = varLabel;
this.x = varX;
this.y = varY;
this.toolTip_mc.over_txt.text = varOver;

this.toolTip_mc.tipBacker_mc.width = this.toolTip_mc.over_txt.textWidth + 20;
this.toolTip_mc.visible = false;
this.buttonOver_mc.visible = false;

this.buttonMode = true;

this.addEventListener(MouseEvent.CLICK, clickHandler);

}

private function clickHandler(event:MouseEvent):void {
var tempVar:String = this.label_txt.text;
//trace("You clicked " + tempVar);
buttonClick(tempVar);
}

function buttonClick(tempVar:String):void{
trace("I want to go to presentation_mc frame # " + tempVar);
//presentation_mc.gotoAndStop(tempVar);
}

}
}

---- end Button_mc.as

Note the red and bold traces fine on clicks - but I can't actually reference the movie clip "presentation_mc" from here.

I'm really sorry if this is simple - referencing is always the second thing I check on errors - after spelling. But I am getting a specific 1120: Access of undefined property presentation_mc error.

I am working my way through Moock's book on AS 3 at a feverish pace, but if I can't get this sussed I am in serious trouble for today.

I greatly appreciate anyone's help - whether simple or conceptual.



FlashKit > Flash Help > Actionscript 3.0
Posted on: 03-19-2008, 02:02 PM


View Complete Forum Thread with Replies

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

How Do I Reference Movie Clips On The Main Timeline From Inside A Class?
Hey everyone, this might be a stupid question but I thought I'd ask cause it's making me nuts. I'm all of 2 days into AS3 (coming from not using Flash at all in YEARS) so feel free to consider me ignorant. I do have plenty of application development experience in other areas though.

I can't seem to create a class that can reference an instance of a movie clip on my main timeline. I'd post code of what I've tried but I've gone through so many desperate edits & wild guesses that it was just garbled junk before I deleted it all.

Basically here's how I figured Flash could work, though maybe it doesn't work this way at all.

I'm assuming that with AS 3 being so big on being a true object oriented environment, I wouldn't need to mix my code and interface together. Preferably I'd be using the Flash authoring tools just to design my interface. Create a button... place it somewhere... give it an instance name. Roughly the equivilant of Apple's InterfaceBuilder for those of you that might be familiar with Cocoa development. I can see maybe having to put a few lines of ActionScript onto frame 1 (though really I'm hoping Flash would have a better method of kicking off the application at this point that using code tied to frames) to load my classes & such, but after that I'd like all of my code to be held in external class files.

So maybe I've got:

Interface.fla - My interface
--- Button_1
--- Button_2
--- TextField_1
Main.as - My main controller class using to handle all of my applications behavior
SomeClass.as - Some helper Class
SomeOtherClass.as - Some helper Class

Main.as would have instructions in its initialization method to go ahead & attach events to buttons & initialize anything else that needs to happen when the application starts. From there on it would all be objects communicating back & forth. Button_1 would get clicked with would fire Main.someMethod(). Main.someMethod() would then do it's thing and set the value of TextField_1. All very clean & code is very separated from interface.

Unfortunately I can't for the life of me figure out how AS3 classes reference each other like that. There doesn't seem to be any kind of a global 'root' or '_root' I can use to locate any movie clips on the stage. I've searched the help & the web for any kind of simple tutorial but to no avail. My job has tasked me with building a flash app for a project but I'd really rather not have a tone of ActionScript just shoved into frame 1. That just seems... ugh! (::shudder:

Can someone maybe point me in the right direction here? I'm really willing to do my homework but I can't seem to locate the info I need to get started. Also, is there an ActionScript IRC channel or something maybe?

Thanks,
Cliff

Making Button In Movie Clip Symbol Reference Main Scene
I set up a flash movie with a scroll pane moving a movie clip. When I place instances of buttons in that movie clip and apply actions to them, they are not working.

The main movie has only one scene, so my actions for the buttons in the movie clip contained in the scroll pane have the following properties: gotoandplay, scene 1, frame label, frame label in scene 1 I'd like to jump to.

Is there a reason, the actions applied to those buttons won't take me to the corresponding frame label in my main movie?

Movie Clip Reference Within A Class
Having problems dynamically creating a movieclip reference to pass to another class.

Basically I have a Game class and a Boiler class. The Game class contains a property called "mcReference" which is being created correctly as "_level0.game_mc" when I create the Game instance

var myGame = new Game(this);

Within the Game class I have a method to create 9 Boiler instances.

i.e


Code:

public function create_Boilers():Void {

arrBoilers = new Array();

for (var i:Number = 0; i < numBoilers; i++) {


var vBoilerRef:MovieClip = mcReference["boiler" + (i + 1) +
"_mc"];
var vBoiler_Obj:Boiler = new Boiler(vBoilerRef);


}

}
If I do a trace on vBoilerRef, I get undefined.

Any ideas what I am doing wrong?

The code for the 2 classes is as follows:


Code:

import Boiler;

class Game extends MovieClip{


// -----------
// Constructor
// -----------



public function Game(passed_mcReference:MovieClip) {


mcReference = passed_mcReference;
trace ("Game mcReference = " + mcReference);


}

public var mcReference:MovieClip;
public var arrBoilers:Array;
public var numBoilers:Number


public function init():Void {

numBoilers = 9;

}



public function create_Boilers():Void {


arrBoilers = new Array();

for (var i:Number = 0; i < numBoilers; i++) {


var vBoilerRef:MovieClip = mcReference["boiler" + (i
+ 1) + "_mc"];
var vBoiler_Obj:Boiler = new Boiler(vBoilerRef);


}

}

}
##############################


Code:


class Boiler extends MovieClip{


// -----------
// Constructor
// -----------



public function Boiler(passed_mcReference:MovieClip,
passed_ID:Number) {


mcReference = passed_mcReference;
trace ("Boiler mcReference = " + mcReference);
numID = passed_ID;
trace ("numID = " + numID);



}

public var mcReference:MovieClip;
public var numID:Number;
private var numInitialRotation:Number = -83.5;


public function reset_Needle():Void {

mcReference.guage_panel_mc.needle_mc._rotation = numInitialRotation;


}


public function set_Needle_Rotation(passedRotation:Number):Void {

mcReference.guage_panel_mc.needle_mc._rotation = numInitialRotation;


}

}

Is It Possible To Get A Reference To The Main Timeline In An External Class?
Hello,
After spending more then 2 hours on google on how to acces the main Timeline trough an external class
i found no solution.

Does anyone know how to acces the main Timeline in an external class?
And can you acces a movieclip (the instance name) of a movie clip that is drawn on the stage and not
dynamically placed with addChild in an external class?

I hope to hear from someone.

How Do I Reference My Main Movie From An External Swf?
Hi there.

I've learnt from many tutorials and forum questions on Kirupa...
...and have gone along steadily in my task...
...but finally I've found something that I can't find an answer for.

I've loaded a few external swf's into my mainmovie...
...where the external swf's are individual ads.

Each external swf is loaded randomly at the beginning of the "side-ad" movie clip...
...then there are about 90 frames of play...
...then back to frame 1...where the ad is randomly loaded again...
...and so on.

Each external swf has it's own transparent button covering the ad...
...which when moving your mouse over it...stops the movie at it's current frame...
...so that you can click on the ad and be taken to the relevant page.

My issue is this...
...like each individual swf movie...
...I would like to be able to stop the "side-ad" movie clip in the same way as the ads...
...so when moving my mouse over the ad...the "side-ad" clip should then stop at it's current frame...
...but if I put a transparent button over the external swf...to stop the clip when the mouse moves over it...
...the button covering the ad becomes void...
...so the "side-ad" clip stops...but the ad carries on playing...
...and when I click on the ad...it doesn't respond...because of the other button that's now covering the external swf.

My solution appears to be a simple one...
...instead of having this button covering the external swf's...telling "side-ad" to stop...
...I suppose each individual external swf should reference the main movie...
...and the button telling the ad to stop...should also tell mainmovie/"side-ad" to stop.


Is there a way of referencing my mainmovie from inside an external movie?

Loading Movie Into Main Timeline From Movie Clip Within Main Movie
Hi there,

I'm having major difficulties loading external SWF's into my main movie. The button actions are in a movie clip within the main movie. I've used the following AS to load in my external SWF files on higher levels:-

mybutton_bn.onRelease {
loadMovieNum("two.swf",1);
unloadMovieNum(2);
unloadMovieNum(3);
unloadMovieNum(4);
unloadMovieNum(5);
}

Similarly, my external text files are not loading!

myLoadVars = new LoadVars();
myLoadVars.onLoad = function() {
my_txt.htmlText = myLoadVars.myHTMLdata;
}
myLoadVars.load("textfile.txt");


All works fine until I upload to the server. It's really driving my around the bend. Any suggestions will be gratefully received.

Many thanks

Q.

Control Main Timeline With Movie Clip In Main Movie,,
I could really need your help on this.

http://www.flashkit.com/board/showth...hreadid=465355

How To Manipulate A Movie Clip On The Main Stage From Inside Another Movie Clip
I have a button inside a movie clip, and I want it to work that when you hit the button, a different movie clip will go to frame 5. anyone know how to help? I think it has something to do with which level it is on, but I can't manage to figure out anything else.

Can't Reference Movie Clip
Help! I can't reference this movie clip. Any sugeestions?


-----------------------------------------------
_root.wishlistbox = _root.attachMovie("newwishlist", "wishlist", d+37, {_x:60,_y:100});

trace("wishlistbox = "+wishlistbox); //outputs: _level0.wishlist

ref1 = _root['wishlist'];
trace("ref1.box = "+ref1.box); //outputs:undefined

ref2 = eval("wishlist.box");
trace("ref2 = "+ref2); //undefined

trace("wishlistbox.box = "+wishlistbox.box); //outputs:undefined


/*
// This is the code in the 'newwishlist' Movie Clip
this.createEmptyMovieClip("box", this.getNextHighestDepth());

//draw filled box
this.box.beginFill(0xffffff, 100);
this.box.lineStyle(1, 0x000000, 20);
this.box.moveTo(0, 0);
this.box.lineTo(750, 0);
this.box.lineTo(750, 80);
this.box.lineTo(0, 80);
this.box.endFill();

timelabel = "wlitem";
createTextField(timelabel, this.getNextHighestDepth(),30,10,200,20);
this[timelabel].multiline = false;
this[timelabel].wordWrap = false;
this[timelabel].border = false
this[timelabel].text = "wishlist";
this[timelabel].selectable = false;
this.timelabelformat = new TextFormat();
this.timelabelformat.bold = true;
this.timelabelformat.align = "left";
this.timelabelformat.font = "Arial";
this.timelabelformat.size = 15;
this.timelabelformat.color = 0xcccccc;
this[timelabel].setTextFormat(timelabelformat);


this.box.onRelease = function(){
trace(this);
}
*/
-----------------------------------------------

Thanks, Pete.

Help With Movie Clip Reference
Hi Everyone,
Please help me with this script:

rootMovie.Fla code:
courseObj.onPress = function(){
txtIntro._visible = 0;
loadMovie("courseObj.swf", mcPlaceHolder);
}

As you can see I used a button to trigger a swf to load into a MC called "mcPlaceHolder". This works.


courseObj.Fla code:
function txtBasicFunc(mcName,mcAlpha){
_root[mcName]._x = _root._xmouse;
}


This works by itself, but when load into mcPlaceholder in rootMovie.Fla it doesn't work. I know that the _root[mcName] array must be the problem and this is where I need help.

thankyou

How To Reference To A Movie Clip
Hello

I have a movie clips with 2 buttons (a red and a blue). When I do a mouse over on the red button my blue button will come visible.

When I drag my movie clip to the stage I can see the red button and the blue button will be available when I do a mouse over on the red button

Now I want to apply an action script on the scene for my blue button that makes the time line go to frame 20. But I am not sure on how to reference the button from the movie clip. I get an error with a null reference.

I have attached my scenario. I am new to AS3 so this is maybe a simple question

Thanks
Tanja

Movie Clip Reference
If i have movieclipD iside movieclipC iside MovieclipB inside MovieclipA whose parent is the _root and i would like to reference MovieClipD in terms of the _root and not its parent. I know i could do it mathamatically calculating the X Y of every parent but i was wondering if there was a simpler way to do it?? for instace something like "movieClip._xworld".

Please and Thank you.

Please ask me to clarify if i have explained it poorly.

Using A Variable To Reference A Movie Clip
This has got to be simple....
How do you use a variable to reference a movie clip which is linked from the library?
eg, I have a movie clip linked as movie1. And a variable called varmovieclip.
and I want to say - varmovieclip.play()???????

How To Reference Arrays In A Movie Clip
I have dynamic and input text fields in a movie clip
and trying to referance them in a for loop

for (i=0; i<2; i++) {
yoselfMC["varLineTot"+i] = yoselfMC["varLotQty"+i]*aryPrc[i];
Total += yoselfMC["varLineTot"+i];
}

where
yoselfMC is the movie clip instance name
varLineTot1, varLineTot2,.. are dynamic text variable names
and
varLotQty1, varLineQty2,.. are input text varible names

code must calculate total order price but does not

any suggestions about referancing varibles in a movie clip in this manner..
by the way.. should i do something to insert(or attach?) varibles to movie clips..

Array Movie Clip Reference
Hi
I got some movie clips' references in an array as follows:

Code:
var buttons:Array = new Array(architektura_mc, urbanistyka_mc);
These movie clips are nested in a movie called 'menu_mc', so I can reference to them like so:

Code:
menu_mc.architektura_mc.property = value;
However, I'd like to facilitate my array in the following way:

Code:
menu_mc.buttons[0].property = value;
It won't work since when I trace menu_mc.buttons[0], it's apparently undefined. How come?

How To Reference Movie Clip In Button
Hello,

I have a button, lets say its linkage name is btn. From script in the main timeline I am adding the button (from the library) to a movie clip with attachMovie, giving it an instance name btn1. This has been working fine for me (however, please correct me if I should not be using attachMovie on buttons).

This button, in the Up frame, has a movie clip with an instance name interior. Is it possible, after I call attachMovie and create btn1, to reference this interior movie clip, like: _root.outer.btn1.interior ? I can successfully reference btn1 with _root.outer.btn1, but _root.outer.btn1.interior is undefined.

If I list objects while debugging, I can see a target: _root.outer.btn1.instance63. I realize that Flash has generated that instance name, but why hasn't it used the "interior" name I assigned inside the button?

Please excuse my lack of knowledge here, and know that I've spent a number of hours researching this before posting. Any help would be appreciated.

Thanks,
M

Ways To Reference A Movie Clip?
Can anyone explain why within a function this would work: colorSwatch_0._alpha-=10;

But this would not? this["_root.colorSwatch_"+0]._alpha-=10;


I am certain that the reference is solid, and I can access other variables in the same manner (dynamic text fields).

Any clues?


Thanks muchly


b

Movie Clip Reference Problem
Hi there, 1st of all, thank you for all those who have helped me out for that last week. I have gained so much information this week more than I do in a month. The progress of my project is going because of this forum.

2nd, I run into another question.

I have 1 index movie (_root). Inside this movie, I have a container_mc, and I load external swf file into this container.

For examble, I load a news.swf into the container_mc

But when I reference into a mc inside the _root timeline of news.swf, It doesnt recognize it.

For example: I have a myMovie_mc inside the _root timeline of news.swf
How do I make an absolute reference to this myMovie_mc?? ( I have a button inside myMovie_mc, and onRelease, I want it to play the 2nd frame on myMovie_mc

This doesnt work:
_root.container_mc.myMovie_mc.gotoAndPlay(2);

A quick solution is appreciated. Thanks guys.

FMX: Get Reference To Clicked On Movie Clip
New to flash!
I normally write javascript code, so I wonder how to do this.
In JS "Microsoft IS" you'll write code like this:

document.onclick = func;

function func()
{
var obj = event.srcElement; //And there I have reference to the object;
}

The graphic designer creates flash drawings and then converts whatever objects to movieclips. Then passes them over to me. All these "mc" need the same action applied to them. So I don't need to know how many they are or their names....Can this be done in Flash???
Thanx

Using Variable To Reference Movie Clip?
In AS2 I used to be able to reference a movie clip using a variable like this:


Code:
var target = nameofmovieclip;
I've been looking for an answer on how to do the same thing AS3 but with no luck. I'm trying to create a dynamic homing missle, but unfortunately everything I've tried just generates errors.

Does anyone know how to accomplish something like this is AS3?

Removing A Movie Clip Reference
Last edited by chance : 2003-01-27 at 06:31.
























For some reason, I can't seem to remove the reference to an unloaded movieclip that is contained in a movieclip that is contained in another movieclip that has been loaded using attachMovie(). I know the clip is being removed because listing the objects in the movie just shows the reference to the removed clip, not the objects within the removed
clip.



------------- Code ---------------
item = itemPath.attachMovie(itemClip, "item" + i, i);

var mp3 = item.mediaType_mc.mediaMp3_mc;
trace(mp3); // path to mp3
unloadMovie(mp3);
trace(delete mp3); // false

----------------------------------

I've tried:

mp3.unloadMovie()
unloadMovie(mp3)
mp3.removeMovieClip()
removeMovieClip(mp3)

Is there something I'm missing here? I don't have any code anywhere that references these clips so I can't for the life of me figure out why I can't delete their reference.

Any help is appreciated, or if you know a way in the debugger or somewhere else to show all references to a given object, that may help too. I may have set a variable somewhere that references these clips and forgotten about it.

Thanks.

Mark Chance
mchance@ideo.com
IDEO
http://www.ideo.com

Movie Clip Reference Issue
I'm having this problem quite often now, I know it's kinda vague to tell, but it's basically this; reference to movieclips just stop working for no apprent reason.

For instance, I have this project where I have a movie clip at the stage and I use code from the same fla to make a reference to it and it just doesn't work.

Say myMC.buttonMode = true; to make it change the mouse arrow when the cursor is over the MC.

But if I make it simple, by deleting everything else but the part of the code where it makes the reference the MC and the MC itself, it works!

That's not the first time that it happened to me, so I wonder if it's a kind of well know bug that I should be aware of, or something...

Reference Current Movie Clip
how do you reference the current movie clip.

for example, as part of my "skip intro", i would like to stop the current playing movie clip.

this.stop() seemed reasonable but it does not work.

Loosing Reference To Movie Clip
I'm somehow loosing my reference to my movie clip i created dynamically.... can someone tell me what's wrong with this code.

var y=0;
var x=0;
var imageHolderWidth = 276;
var imageHolderHeight = 362;
var gap=50;
// loop through XML and place in array
for (var i=0;i<2;i++) {
var image = "last10_image_"+i.toString();

_root.createEmptyMovieClip(image,50+i);

var imageHolder = eval(image);
imageHolder._x=x;
imageHolder._y=y;
imageHolder.createEmptyMovieClip("_tn"+i,100+i);
mv_sub_image = imageHolder["_tn"+i]

trace(_root[image]["_tn0"]);
with(mv_sub_image){
_x=1.5;
_y=1.3;
_alpha=60;
with(imageHolder){
lineStyle(2,0xA0A0A0);
moveTo(0,0);
lineTo(imageHolderWidth,0);
lineTo(imageHolderWidth,imageHolderHeight);
lineTo(0,imageHolderHeight);
lineTo(0,0);
}
loadMovie("glamour.jpg");
}
_root[image].onRollOut=function(){
_root[image]["_tn0"]._alpha=60;
}
_root[image].onRollOver=function(){
_root[image]["_tn0"]._alpha=100;
}

currentNode = currentNode.nextSibling;
x = x + gap + imageHolderWidth;

//set the max image that can be displayed.
if(i>=1){break};
}




if you look at the trace output .. the first movie clip is undefined after the second loop.

How Do I Reference The External Movie Clip's Button?
I'm loading a movie into a container (a navigation system). Now I want to put in some code in the first swf, not the external swf, to change the alpha of a movie clip. Can someone help?


Code:
var navLoader:Loader = new Loader();
gavholder.addChild(navLoader);
var navURL:URLRequest = new URLRequest("dock.swf");
navLoader.load(navURL);
navLoader.x=0;
navLoader.y=0;
navLoader.scaleX=1;
navLoader.scaleY=1;
I thought I could just say this


Code:
gavholder.c1.addEventListener(MouseEvent.CLICK, camp);
function camp(event:MouseEvent) {
gcrmcholder.alpha =50;
}
Regards,

Glen Charles Rowell

Using A Variable To Reference An Already Existing Movie Clip?
Hello,

I have been struggling with what I suppose is a very simple issue: I am importing content into my application via a text file, this all works fine. I have about 10 different movie clips on the parent timeline that I have hidden (dc_mc.visible = false.

So what I need to do is take one of the variable names that I've got from my text file and use its value to "turn on" one of these hidden movie clips.

So I'm trying stuff like:

var directory = e.target.data.directory; // Grabs the data, sets var
var raceNameButton:String = directory+"_mc"; // Set data into new var
raceNamesButton.visible = true; // display movie clip with var name

and it's giving me all sorts of problems. I know I can do this with ActionScript, but just can't seem to get it to work.

Any thoughts out there?

Can't Reference A Movie Clip Array Via For Loop
Hello everybody, I have this problem since many weeks ago, I can't figure out how to resolve it. My partial code is:

function checkCollision(rect) {
for(j=0; j < drop.length; j++) {
temp2 = eval(drop[j]);
if(eval(rect._droptarget) == temp2){
rect._x = temp2._x;
rect._y = temp2._y;
}
else {
rect._x = rect.origX;
rect._y = rect.origY;
}
}
}

I send to the function a movie clip that I use for drag and drop, so when I drop this function is called. The problem is that of the three rectangles that I use for contain the others, only the last senses the drop target. I read the Canadian post of frequently asked questions, and one of the questions is very similar, but I can't figure out how to apply it here. Any help please. Thanks

Pass Reference Of Movie Clip To Function?
Hey guys,

I'm trying to do something like this, but for some reason it isn't working...


ActionScript Code:
function mouseClickHandler(t:MovieClip):Void {       if(!t){        trace("no target");        var t:MovieClip = this;    }    else{        trace(t._name);    }}// using a call to this function I want to simulate a click on navItem_2mouseClickHandler(container.navItem_2);


Any idea why this shouldn't work?
Should I do it as a string or what?

Update:

Hmm, I replicated this situation in a blank movie and it works as it should. Really confused now.

Dynamic Movie Clip Reference Problems
Last edited by Codemonkey : 2006-08-18 at 10:30.
























i'm trying to convert the following statement:


ActionScript Code:
line_mc_1.moveTo(end_mc_1._x , 353);

I'd like to replace "mc_1" with the variable "currentSWF". by doing this:


ActionScript Code:
whichLine = "line_" + currentSWF;
whichEndX = "end_" + currentSWF + "._x";
 
eval(whichLine).lineTo(eval(whichEndX), 353);

...only the first eval is working. Is there a better way of doing this? I'm basically trying to dynamically generate the reference to the MC property. I've tried other approaches with no success.

Thanks in advance!

Raphael

Using A String Variable To Reference A Movie Clip
I have an appended variable that i want to use to reerence a movie clip instance, but it dosnt work....

var blah_num:Number = 1;
blah = "blah" + blah_num;

_root.blah.gotoAndPlay(5);

I hope this explains what im trying to do. I have 15 instances of the same movie clip that are named "blah1","blah2",...etc. the blah_num variable changes and is appended to blah, and then I want to use the string var blah as a movie clip instance. I ma trying to use it in this form: blah.gotoAndPlay(10); etc...

Thanks in advance

Talking To A Movie Clip On Main Stage From Other Movie Clip
This is something I have been struggling to understand for awhile.

On my main stage, I have created a couple of movie clips for the purpose of loading in content (other MCs) at a later point. I'm doing this like so:


Code:
// Define a new MovieClip to display ribbon
var ribbonMC:MovieClip = new MovieClip();
addChild(ribbonMC);
Then I have another MC that is housing a datagrid. When the user clicks on one of those rows, it's supposed to load up a new movie clip into my ribbonMC movie clip. That code is this:


Code:
function handleClick (ev:ListEvent) {
// If the item has an 'panel' attribute

if (ev.item.panel != null) {
// Use the 'panel' attribute to get a movie clip by that name from the library
var myClip:Class = getDefinitionByName(ev.item.panel) as Class;
removeChild(ribbonMC);
ribbonMC = new myClip() as MovieClip;
// Position the new movie clip
ribbonMC.x = 200;
ribbonMC.y = 20;
// Add the new movie clip to the display list
addChild(ribbonMC);
}
}
But of course, ribbonMC is not in this movie clip, so I get an error:
1120: Access of undefined property ribbonMC.

I've searched on how to access stuff like this but I am totally confused. What is the proper way to access ribbonMC on the main stage from inside this other movie clip?

Buttons In One Movie Clip Controling Main Clip
I have a movie. In the center on the movie there are a set of four buttons. Instead of the hassle of making 5 or 6 extra layers on the main movie, I made them on their own clip. Now, if I press a button on that clip, can I make a play action work for the main clip? It seems to just make the buttons play again.

When it plays the button clip goes away and a tween moves the background around to the next step. The button sets a variable which determines which movie is loaded thereafter.

Thanks ahead of time! :^)

Loosing Reference To My Movie Clip When Create Dynamically
I'm somehow loosing my reference to my movie clip i created dynamically.... can someone tell me what's wrong with this code.

var y=0;
var x=0;
var imageHolderWidth = 276;
var imageHolderHeight = 362;
var gap=50;
// loop through XML and place in array
for (var i=0;i<2;i++) {
var image = "last10_image_"+i.toString();

_root.createEmptyMovieClip(image,50+i);

var imageHolder = eval(image);
imageHolder._x=x;
imageHolder._y=y;
imageHolder.createEmptyMovieClip("_tn"+i,100+i);
mv_sub_image = imageHolder["_tn"+i]

trace(_root[image]["_tn0"]);
with(mv_sub_image){
_x=1.5;
_y=1.3;
_alpha=60;
with(imageHolder){
lineStyle(2,0xA0A0A0);
moveTo(0,0);
lineTo(imageHolderWidth,0);
lineTo(imageHolderWidth,imageHolderHeight);
lineTo(0,imageHolderHeight);
lineTo(0,0);
}
loadMovie("glamour.jpg");
}
_root[image].onRollOut=function(){
_root[image]["_tn0"]._alpha=60;
}
_root[image].onRollOver=function(){
_root[image]["_tn0"]._alpha=100;
}

currentNode = currentNode.nextSibling;
x = x + gap + imageHolderWidth;

//set the max image that can be displayed.
if(i>=1){break};
}




if you look at the trace output .. the first movie clip is undefined after the second loop.

Dynamic Movie Clip Reference, Invoke Function In Mc
Happy new year all!!

I'd like to invoke a function inside a mc from it's parent, but I want to have the reference to the clip be dynamic. When I path the mc directly and invoke the function it works, how would I make that same reference work dynamically.

Here's a sample of what I'm trying to do:

Code:
var myArr:Array = new Array();
myArr[0] = "galleryContainer_mc.eventGallery1_mc.imgContainer_mc";
trace(myArr[0]);

// This works
toggle_btn.onRelease = function() {
galleryContainer_mc.eventGallery1_mc.imgContainer_mc.videoToggle();
}
// But this doesn't work
toggle_btn.onRelease = function() {
myArr[0].videoToggle();
}
I know I'm fried, but that seems like it should work, am I missing something really basic here? Any advice would be really helpful at this point. Thanks!

How Can A Class Send Messages To The Main Movie
I think I have a prety good handle on AS3. I wrote a class, and attached it to a MovieClip, in my main movie, one the user interacts with the class, and the class does it's thing, I want it to send some infomation back to the main movie (which is also a class). I'm not really sure how to do this. Do I add some sort of custom event listener to class, and then dispatch an event to the main movie from the class? I don't have alot of experiance with this, I wonder if anyone can help me.

How To Reference Root-level Sound From Within A Nested Movie Clip?
I've got this AS on the first frame of my main FLA:

PHP Code:



var spur1:Spur1 = new Spur1();
var playSpur1:Function = function() {
    spur1.play();
}
playSpur1(); 




It works. When the movie starts playing, I hear the spur sound from my library immediately.

I have a cowboy MovieClip on my stage in frame 1. The 2nd frame inside that cowboy movie clip has a movieclip of some legs walking. The 1st and 6th frames of those legs walking has this actionscript:

PHP Code:



playSpur1(); 




This is causing an error:

Code:
1180: Call to a possibly undefined method playSpur1.
My movie will not run properly - the cowboy ignores all the internal actions and loops repeatedly.

What is the recommended way to play a sound when some deeply nested movie hits a certain frame?

Changing A Variables Value In An External .as Class From The Main Movie
hello, ive put this in another thread already after a different question but thought it might get ignored!

my first frame


Quote:





var picnumbers = 1;
butGo.onRelease = function()

{simpleSearch.doSearch(tag.text);


}








simpleSearch is a movie which the external class is linked to

my button which i wish to use to increment picnumbers and change the value in my external file


Quote:





on (release) {
picnumbers = picnumbers * 4;
myTextbox.text = picnumbers;
simpleSearch.doSearch(tag.text);
}








the first few lines of the external class file i am using, flashr.


i need NUM_RESULTS to be associated with picnumbers from the main movie somehow and im a bit stuck!!

Quote:





*/
class com.kelvinluck.flashr.example.FlashrSimpleSearch extends MovieClip
{

public static var NUM_RESULTS:Number = 10;

private var _flashr:Flashr;
private var _flashrResponse:FlashrResponse;

private var _numResults:Number;
private var _photos:Array;

Why Can't I Access A Class Object Variable With A For..in Loop From My Main Movie?
I'm having this problem trying to access an object variable and an array variable for that matter that are part of a Player class that I am creating. Now when I set up the test code I made a temp object that I put some test variables in i.e.,

var temp:Object = {x: 5, y: 5, name: "Rob"};

then I set my Player.attr = temp and I also did:

for(var str:String in temp)
{
Player.attr[str] = temp[str];
}

I have tried this both using a public var attr and a private var _attr that I'm using getter and setter methods with and the result is the same every time. If I directly access the items i.e.,

trace(Player.attr.x) // returns 5

but I can't access it with a for..in loop...why??

for(var str:String in Player.attr)
{
trace(Player.attr[str]);
}

I get an error that the variable doesn't contain the static attribute... I don't get it.

same thing if I have an array variable within my class and i try to access it through a loop:

for(var i:Number = 0; i < Player.tempArray.length; i++)
{
trace(Player.tempArray[i]);
}

I get the exact same error...

Please, is there something that I'm doing terribly wrong to access this data. How do I utilize the loops to pull the data out. I need to use the loops specifically because the array is going to be for the inventory and it dynamically grows or shrinks so I have no way to tell how many elements are within it and although the object has a finite set of attributes there should be a way to get the information out of it through a loop. If not that's just crazy!! Thanks in advance for the help.

Preload Main Movie Via Document Class & Add Details To Stage?
Hi Guys,

I have what I think might be a dumb question on my behalf or maybe I am missing something but is it not possible to added a preloader movie clip that i create to the stage via the document class? i.e. if i wanted to use this method of preloading my movie, is it possible to add a movie clip to the stage with the status? Everything I try just doesn't seem to work Currently, when i test within flash using simulate download, my stuff is added to the stage, after the movie is loaded? I've moved my content on the stage to frame 2 with the correct frame label.

cheers for any help,
stacey


Code:
package {

import flash.display.*;
import flash.events.Event;
import flash.events.ProgressEvent;
import flash.net.*;
import flash.text.*;

public class SiteLoader extends MovieClip {

var preloader_site_mc:MovieClip = new MovieClip();


public function SiteLoader():void {


createPreloader();

//this.loaderInfo.addEventListener(Event.INIT, initApplication);
this.loaderInfo.addEventListener(ProgressEvent.PROGRESS, showProgress);
this.loaderInfo.addEventListener(Event.COMPLETE, onLoadComplete);


}


public function showProgress(theProgress:ProgressEvent):void {

//get the values
TextField(MovieClip(preloader_site_mc).getChildByName("preloader_site_percentage")).text = "" + (theProgress.bytesLoaded / theProgress.bytesTotal * 100);

//update width of bar by amount changed as a percentage
Sprite(MovieClip(preloader_site_mc).getChildByName("preloader_site_progressBar")).scaleX = theProgress.bytesLoaded / theProgress.bytesTotal;

}

public function onLoadComplete (myEvent:Event):void {

gotoAndStop("loaded");


}


public function createPreloader():void {

//create the preloader itself dynamically
var sprite_preloader_site_progressBarBorder:Sprite = new Sprite;
sprite_preloader_site_progressBarBorder.graphics.lineStyle(0.5,0x30304a,0.5,false,LineScaleMode.NORMAL,CapsStyle.NONE);
sprite_preloader_site_progressBarBorder.graphics.moveTo(550,420);
sprite_preloader_site_progressBarBorder.graphics.lineTo(735,420);
sprite_preloader_site_progressBarBorder.graphics.moveTo(735,420);
sprite_preloader_site_progressBarBorder.graphics.lineTo(735,425);
sprite_preloader_site_progressBarBorder.graphics.moveTo(735,425);
sprite_preloader_site_progressBarBorder.graphics.lineTo(550,425);
sprite_preloader_site_progressBarBorder.graphics.moveTo(550,425);
sprite_preloader_site_progressBarBorder.graphics.lineTo(550,420);
preloader_site_mc.addChild(sprite_preloader_site_progressBarBorder);

var sprite_preloader_site_progressBar:Sprite = new Sprite;//b6c0df or fbda9b
sprite_preloader_site_progressBar.name = "preloader_site_progressBar";
sprite_preloader_site_progressBar.graphics.lineStyle(2,0xb6c0df,0.2,false,LineScaleMode.NORMAL,CapsStyle.NONE);
sprite_preloader_site_progressBar.graphics.moveTo(552,423);
sprite_preloader_site_progressBar.graphics.lineTo(734,423);//dont have a width yet
sprite_preloader_site_progressBar.scaleX = 0;
preloader_site_mc.addChild(sprite_preloader_site_progressBar);

//ADD TEXT FIELDS

//create new instance of the font
var preloader_site_font:Font = new Arial_Embedded();

//create a format for the fields
var preloader_site_TextFormat:TextFormat = new TextFormat();
preloader_site_TextFormat.font = "Arial";//
preloader_site_TextFormat.color = 0x57578f;//0xfbda9b;
preloader_site_TextFormat.size = 10;

//create the fields & their attrs
var textField_preloader_site_loadingText = new TextField();
textField_preloader_site_loadingText.autoSize = TextFieldAutoSize.LEFT;
textField_preloader_site_loadingText.selectable = false;
textField_preloader_site_loadingText.name = "preloader_site_loadingText";
textField_preloader_site_loadingText.defaultTextFormat = preloader_site_TextFormat;

var textField_preloader_site_percentage = new TextField();
textField_preloader_site_percentage.autoSize = TextFieldAutoSize.NONE;
textField_preloader_site_percentage.selectable = false;
textField_preloader_site_percentage.name = "preloader_site_percentage";
textField_preloader_site_percentage.defaultTextFormat = preloader_site_TextFormat;

var textField_preloader_site_percentSymbol = new TextField();
textField_preloader_site_percentSymbol.autoSize = TextFieldAutoSize.LEFT;
textField_preloader_site_percentSymbol.selectable = false;
textField_preloader_site_percentSymbol.name = "preloader_site_percentSymbol";
textField_preloader_site_percentSymbol.defaultTextFormat = preloader_site_TextFormat;

//add content to those text fields
textField_preloader_site_loadingText.text = "LOADING DATA";
textField_preloader_site_percentage.text = 0;
textField_preloader_site_percentSymbol.text = " %";

//set the positions
textField_preloader_site_loadingText.x = 550;
textField_preloader_site_loadingText.y = 400;//move above registration point
textField_preloader_site_percentage.x = 700;
textField_preloader_site_percentage.y = 400;
textField_preloader_site_percentSymbol.x = 720;
textField_preloader_site_percentSymbol.y = 400;

preloader_site_mc.addChild(textField_preloader_site_loadingText);
preloader_site_mc.addChild(textField_preloader_site_percentage);
preloader_site_mc.addChild(textField_preloader_site_percentSymbol);

//add to stage
this.addChild(preloader_site_mc);


}


}



}

How Do I Recerence Movie Clips On The Main Timeline From Inside A Class?
Hey everyone, this might be a stupid question but I thought I'd ask cause it's making me nuts. I'm all of 2 days into AS3 (coming from not using Flash at all in YEARS) so feel free to consider me ignorant. I do have plenty of application development experience in other areas though.

I can't seem to create a class that can reference an instance of a movie clip on my main timeline. I'd post code of what I've tried but I've gone through so many desperate edits & wild guesses that it was just garbled junk before I deleted it all.

Basically here's how I figured Flash could work, though maybe it doesn't work this way at all.

I'm assuming that with AS 3 being so big on being a true object oriented environment, I wouldn't need to mix my code and interface together. Preferably I'd be using the Flash authoring tools just to design my interface. Create a button... place it somewhere... give it an instance name. Roughly the equivilant of Apple's InterfaceBuilder for those of you that might be familiar with Cocoa development. I can see maybe having to put a few lines of ActionScript onto frame 1 (though really I'm hoping Flash would have a better method of kicking off the application at this point that using code tied to frames) to load my classes & such, but after that I'd like all of my code to be held in external class files.

So maybe I've got:

Interface.fla - My interface
--- Button_1
--- Button_2
--- TextField_1
Main.as - My main controller class using to handle all of my applications behavior
SomeClass.as - Some helper Class
SomeOtherClass.as - Some helper Class

Main.as would have instructions in its initialization method to go ahead & attach events to buttons & initialize anything else that needs to happen when the application starts. From there on it would all be objects communicating back & forth. Button_1 would get clicked with would fire Main.someMethod(). Main.someMethod() would then do it's thing and set the value of TextField_1. All very clean & code is very separated from interface.

Unfortunately I can't for the life of me figure out how AS3 classes reference each other like that. There doesn't seem to be any kind of a global 'root' or '_root' I can use to locate any movie clips on the stage. I've searched the help & the web for any kind of simple tutorial but to no avail. My job has tasked me with building a flash app for a project but I'd really rather not have a tone of ActionScript just shoved into frame 1. That just seems... ugh! (::shudder::)

Can someone maybe point me in the right direction here? I'm really willing to do my homework but I can't seem to locate the info I need to get started. Also, is there an ActionScript IRC channel or something maybe?

Thanks,
Cliff

Control The Play On The Main Timeline From Within A Loaded Movie (not A Movie Clip)?
Question... I have a movie (main movie) that loads another movie (movie 2) automatically. Movie 2 contains a button that loads yet another movie (movie3). Now I’m having trouble with this next part... When movie3 loads I want "main movie" to stop where it’s at in the timeline and stop all other loaded movies until the user clicks another button where upon movie 3 will go away and "main movie" will resume. Movie 2 is like the paper clip guy in Word and movie 3 is my help movie. Therefore, it can be accessed at any point during the main movie and I don’t want to use a goTo command to jump to a frame label or scene. Does anyone have any idea how to control the play on the main timeline from within a loaded movie (not a movie clip)?

How To Load A Movie In Main Scene While The Command Is Inside A Movie Clip?
Hi all,

Well, I have a scene that has a movie clip, and inside this movie clip there is a button. I want to program that button using ActionScript to loadMovie named "1.swf" inside a container in the main scene (which this movie clip belongs to).

Hope the question is clear and hope to get a fast answer as it is urgent..

Thanks alot in advance.


Regards

How To Get A Button Inside Of A Movie Clip Play The MAIN Movie
how to get a button inside of a movie clip play the MAIN movie

( reposted, bad grammer in 1st one)


I got a button, inside of a movie clip.....
How do I get the button to have the MAIN movie play on click, not the MOVIE clip

Stop Movie Clip But Keep Onstage As Main Movie Continues
I have a movie clip of a rotating wheel. In the main movie, a blackboard is being wheeled midstage from the right edge of the movie. I have the graphic symbol of the blackboard onstage with two wheel movie clip symbols. I created a motion tween from the right position to the middle position. Everything works great, but...how do I make the wheels stop rotating once the position of the blackboard is where I want it?

[F8] Movie Clip Actions Inside Main Movie Not Working
I know this HAS to have been answered somewhere here before... I've been doing Flash on and off since it's creation, but it's been a while since I used it. I have Flash8 running on this dev machine and I am adding a little accordion to an old project. I have tried calling the accordion swf from the main movie and loading it in, but this is not working for me.

So, I tried copying all of the frames form the external SWF accordion (it's small), along with it's actionscript to a MC inside the main movie and placed that MC on the timeline in the main file. The MC shows up fine, but the action associated with it is not functioning.... basically I want the text button to pop up the accordion MC and allow interaction by the user to click through the slides within it.

A little definition:
KSB_MC = the container MC on the main timeline that displays the first frame of the MC which is: KSBbutton_MC
KSBbutton_MC = the text MC visible from the main timeline that should launch the KSBanimation_MC (which is the accordion)

This is the AS I have so far that is in the MC I placed on the main timeline:

//first we stop both animations inside KSB_MC from running

KSB_MC.KSBbutton_MC.stop();
KSB_MC.KSBanimation_MC.stop();

//then we make conditional, the button action so that if the button_MC is pressed, the button goes to frame 2 and the animation_MC plays or else stop both animations

KSB_MC.KSBbutton_MC.onPress = function(){
if(KSB_MC.KSBbutton_MC._currentFrame ==1){
this.gotoAndStop(2);
KSB_MC.KSBanimation_MC.play();
}
else{
this.gotoAndStop(1);
KSB_MC.KSBanimation_MC.stop();
}
}



.......first of all, the KSBbutton_MC on hover shows a finger cursor as it should, but does not activate when pressed. Nothing happens after that. I get no errors in the AS checker....
my problem is with layering or something st00pyd. Feelin kinda n00bysh.

Help a brothah out will ya guys?

Instructing An External Movie Clip To Play From The Main Movie
Anyone tell me the easiest way to sort this one?

I have a movie clip that consists of 2 keyframes.

It is loaded onto level1 above my main movie and the first frame is blank (so that it does not come into play until instructed).

The second keyframe is the main part of the loaded movie and this needs to play after receiving instruction from the main movie.

My problem is 'How do I instruct this to happen??'
I have no knowledge of action script so if anyone could advise or tell me if there is an easier way to do this I would be eternally greatful........................................

Continuous Play Of Several Movie Clips From One Main Movie Clip
hi,

i'm trying to play several movie clips, one after the other from one main movie clip.

i've got 8 movie clips, "m1.swf", "m2.swf", etc. "m8.swf", and one main movie clip, "play.swf".

i've tried using loadMovie, but it only plays the last movie clip. this is what i've got.

in the main movie clip, i've put a play button, and the actionscript i have in the button is:

on(release)
{
this.loadMovie("m1.swf",play);
//this.unloadMovie("m1.swf");
this.loadMovie("m2.swf",play);
//this.unloadMovie("m2.swf");
this.loadMovie("m3.swf",play);
//this.unloadMovie("m3.swf");
this.loadMovie("m4.swf",play);
//this.unloadMovie("m4.swf");
this.loadMovie("m5.swf",play);
//this.unloadMovie("m5.swf");
this.loadMovie("m6.swf",play);
//this.unloadMovie("m6.swf");
this.loadMovie("m7.swf",play);
//this.unloadMovie("m7.swf");
this.loadMovie("m8.swf",play);
//this.unloadMovie("m8.swf");
}


is this wrong? how can i get this to work correctly. really important that i get this working for my job.

any help will be greatly appreciated.

cheers

Send Variable From The Main Movie To A Movie Clip.
How do I send variable form my main movie to a movie clip.

Have some dynamic text in my movie clip whose variables are determined in the main movie

Main Movie With Buttons Link To Movie Clip
Basically, in Scene 1 (my only scene), I have buttons that call certain parts of a movie clip.

I've pulled the movie clip into the scene where I want it, and named the instance.

The movie clip has different things happening along the time line that relate to the different buttons. Each one has a stop action, as needed.

I placed the action of onrelease, tell target for each button to go and play the correct scene. Which it does - the first time. If the user hits one button, it goes to the right frame of the movie clip, etc, but if you hit the same button twice, then it jumps to a different button's place.

If there are only two buttons, it keeps switching back and forth.

If there are more than two buttons, only the last button is the messed up one - and if you hit it twice in a row, it goes back to the first button's frame of the movie clip.

Make sense? Any ideas of how to stop this. I even followed an example of this in a book EXACTLY and I get the same problem.

Thanks.

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