Accessing Variables And Functions Inside Dynamically Loaded .swf
I'm loading an external .swf into a container_mc using: Code: container_mc.loadMovie("movie.swf");
How do I access the variables and functions that are inside of movie.swf?
FlashKit > Flash Help > Flash ActionScript
Posted on: 10-13-2006, 04:17 PM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Accessing Functions Inside Dynamically Attached Clip
i've got clips being attached using attachMovie (clips are in the library with linkage id's).
inside those clips are two functions. I'm trying to access those functions after I attach the clips, but not getting anywhere.
I assume that the methods of my attached clip (the functions) aren't available immediately, but rather after the clip actually 'loads' to the stage they are.
I thought that clip.onLoad would get me somewhere but that's not firing! any ideas?
Accessing Functions In Dynamically Loaded SWF
I have a main fla. that is called "Stage1.fla"
I then use this code to load in aother swf called "Print.swf"
var myRequest:URLRequest = new URLRequest("Print.swf")
var myLoader:Loader = new Loader();
myLoader.load(myRequest);
stage.addChild(myLoader);
myLoader.y = 132;
I then have a button in Stage1.fla
When i press this button i want to reach a function inside of "print.swf" called forward
I tried this code, but it didnt work, can someone explain how to write it.
Stage.myLoader.forward;
or
myLoader.forward;
Accessing Functions And Clips In A Loaded Swf..thats Inside A Mc
I have a little issue.
I can access the mcs and such of a loaded SWF by using
Code:
loader.content.myMC
but I have put the loader instance inside a movieclip
so i have a for loop
for(blah){
l:Loader = new Loader():
l.load(blah);
c:loaderContainer = new loaderContainer();
c.name = "c"+i;
c.addChild(l);
}
result is c0, c1, c2, etc
then i got
function dosomthing(){
c2.????? i tried loader.content .. tried c2.content. nothing.. any ideas how to access that loaders content thats inside that specific mc?
}
Accessing Variables And Functions Between Loaded External Swfs?
Using AS 3.0: Say I have a menu.swf that loads a content.swf below it using the following
var newContent:Loader = new Loader();
newContent.load(new URLRequest("fowContent.swf"));
addChildAt(newContent,0);
Now say I have a frame label in newContent that is an animation ending the display of that swf. Upon clicking of another menu button in menu.swf, can I access the content's ending sequence by:
newContent.gotoAndPlay(newContent.endingSequence);
Also can you use while loops in AS 3.0? I would like to have a boolean variable "ended" in the newContent that becomes true after the ending animation has played.
while ( newContent.ended != true)
{
//wait
}
then have it run the function to load and display the new content.swf
Accessing Custom Functions Inside Moveclips
Hi all,
I did not see any postings related to this, and maybe it's because the question is so basic. Yet I am stumped:
I have a movie, with one frame in the main timeline. This frame contains a movieclip and I have given the instance name myclip.
myclip has one frame in it, and in that frame has the following code:
code: function myfunction(){
trace("hello world");
}
In frame 1 of the main timeline I attempt to call the above function:
code: myclip.myfunction()
When I run it, I get nothing.
Obviously my actual project has more to it, but I've got it down to this basic concept and obviously there is something I am missing.
Any help would be appreciated.
Cheers,
Taneem
________
http://www.dheo.com/
Accessing MCs And Functions In A Loaded .swf
Is this possible?
I know it's possible to control a named instance in the loaded swf, but what I'm trying to do is attachMovie a library movieclip in the loaded swf.
I would also like to use a function written in the loaded swf.
Can't get either to work. I'm trying to build a library swf with the mc's contained useable by more than one application.
thanks
Accessing Functions From A Loaded Swf
Hello,
I found the thread on accessing functions from a loaded swf here: http://www.actionscript.org/forums/s...ons+loaded+swf
but it hasn't been working for me. The swf I am loading loads an xml file, so its first frame has this code:
ActionScript Code:
_global.slideData = [];
function loadXML(loaded) {
if (loaded) {
total = this.firstChild.childNodes.length;
for (i=0; i<total; i++) {
var slideentries:Object = new Object();
slideentries.slideFile = this.firstChild.childNodes[i].childNodes[0].firstChild.nodeValue;
slideentries.slideNumber= this.firstChild.childNodes[i].childNodes[1].firstChild.nodeValue;
slideentries.slideID = this.firstChild.childNodes[i].childNodes[2].firstChild.nodeValue;
_global.slideData[i] = slideentries;
}
//sort tabs
_global.slideData = _global.slideData.sortOn("slideNumber");
gotoAndStop(2);
} else {
content = "file not loaded!";
}
}
xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load("content/tab1/slides.xml")
stop();
I want to put my other functions in the second frame, but I can't seem to access them from my main movie, using the method in that thread. I can access functions I put in the first frame. PLEASE HELP!!
Accessing Functions In Loaded Swf
I'm sorry if this has been answered 1,000 times, but I am so confused with everything!!
In the main timeline of my movie, I have a container movieclip called "content". I want to load an external swf into content, and then access the functions in that swf.
I can load it no problem, but I can't for the life of me figure out how to access the functions, I can't seem to find it anywhere! Please help!!
Accessing Outside Variables From Functions
I can't figure out how to access variables that are declared in a movie clip from a function declared in that same movie clip.
i.e.
****************************
var int1 = 1
var int2 = 2
function myfunction(){
int1++;
int2++;
}
myfunction();
****************************
I'm trying to do this in the main movie clip of a movie that I plan on importing dynamically in another movie. I've tried to use this.int1++, but I think that flash was looking for a variable that belongs to "myfunction" when I did that. I could just use _root.int1++ but like I said, I plan on dynamically loading this into another movie, in which case it would be pointing to the wrong movie.
Help!!
Accessing Outside Variables From Functions
I can't figure out how to access variables that are declared in a movie clip from a function declared in that same movie clip.
i.e.
****************************
var int1 = 1
var int2 = 2
function myfunction(){
int1++;
int2++;
}
myfunction();
****************************
I'm trying to do this in the main movie clip of a movie that I plan on importing dynamically in another movie. I've tried to use this.int1++, but I think that flash was looking for a variable that belongs to "myfunction" when I did that. I could just use _root.int1++ but like I said, I plan on dynamically loading this into another movie, in which case it would be pointing to the wrong movie.
Help!!
Accessing Functions From A Loaded Movieclip?
hi i have a file named for this example as "phone.fla". it has functions like on rollovers, an init function and many others.
i have a second file named "phoneholder.fla" and i want to load phone.swf there and be able to access its functions. is this possible? i tried creating a n empty movie clip in phone loader and then using loadmovie to load phone.swf but i cant seem to access the functions. i tired something like this:
(this one is in phoneholder.fla)
this.createEmptyMovieClip("canvas_mc", 10);
canvas_mc.loadMovie("phone.swf", this);
canvas_mc.init();
i also tried canvas_mc.phone.init(); and phone.init(); but it both didnt work. any help is greatly appreciated.
Accessing Functions Within Loaded Swfs
I've been looking for an answer to this problem for some time and couldn't find it here so if this was already discussed I apologize in advance. Basically, I have a main.swf where I create a new loader instance that loads my gallery.swf. My gallery.swf is a black fla file that has a document class called Script.as Inside my Script.as file I have created a function called currentis that expects 1 parameter that is an integer. This integer determines which xml section my gallery reads (determines which gallery to show). I can determine from inside the Script.as file which gallery opens but I want to control this option from my main.swf. I used
gallerymenu_mc.galleryswfloader.content.currentis( 0);
Here is a simplified form of my main.swf
import Script;
stop();
var galleryswfloader:Loader = new Loader();
var galleryrequest:URLRequest = new URLRequest("index.swf");
gallerymenu_mc.wed1_btn.addEventListener(MouseEven t.CLICK, galleryload);
function galleryload(event:MouseEvent)
{
galleryswfloader.load(galleryrequest);
galleryswfloader.addEventListener(Event.COMPLETE, addgallery)
//addChild(galleryswfloader);
function addgallery(event:Event):void{
switch (event.currentTarget.name)
{
case "wed1_btn" :
gallerymenu_mc.galleryswfloader.content.currentis( 0);
addChild(galleryswfloader);
trace("wed1");
break;
}
}
}
I was wondering if I was trying to access the function correctly because my gallery doesn't show at all when I call that function. When I remove that line of code the gallery works but always opens the same gallery.
Thanks for any help!
Accessing Variables And Functions From Parent Clips
i have a navigation system setup.
a clip with main navs... and clips in there with sub navs.
i have functions in the main nav clip that i'm trying to use from the sub nav clip.. got this error..
1061: Call to a possibly undefined method nav_tracker through a reference with static type flash.displayisplayObjectContainer.
i also have variables i'm trying to change the values of from the sub nav clip..
get this error.
1119: Access of possibly undefined property main_press through a reference with static type flash.displayisplayObjectContainer.
Accessing Class Functions/variables In OnLoadInit?
Ok, I'll sum up my prob
Quote:
class fial
{
public var num = 5;
public function returnStuff()
{
return 3;
}
public function doStuff()
{
... [mclistener crap]
mclistener.onLoadInit = function()
{
trace(returnStuff() + " " + this.num);
}
}
}
The result when onLoadInit traces, "(undefined undefined)", outside the onLoadInit, it would work fine. I've tried changing this.num to num, but it was no use.
What should I do?
Thanks.
Arun
Problem Accessing Elements Inside A Dynamically Called MovieClip
I have a MovieClip setup with login and password section inside. It sits inside the library, and is dynamically called in, using attachMovie.
Problem:
When the MovieClip is on the stage, everything seems to work fine. I can click on the elements inside, etc. But when it's being called by AS2, I can't seem to access anything inside.
Here's an example:
/* =============================================== */
stop();
import mx.transitions.Tween;
import mx.transitions.easing.*;
// login button
this.createEmptyMovieClip("login_mc",31);
login_mc.attachMovie("loginPanel","login_mc",this.getNextHighestDepth(), {_x:Stage.width / 2, _y: Stage.height / 2});
login_mc._visible = false;
loginBtn.onRollOver = function() {
login_mc._visible = true;
var panelAlphaIn:Tween = new Tween(login_mc, "_alpha", Strong.easeInOut, 0, 100, 5, false);
};
login_mc.onRollOut = function() {
var panelAlphaOut:Tween = new Tween(this, "_alpha", Strong.easeInOut, 100, 0, 5, false);
panelAlphaOut.onMotionFinished = function() {
login_mc._visible = false;
};
};
/* =============================================== */
'loginBtn' is the login mc instance, and 'login_mc' gets created dynamically and tweened in.
Thanks in advance~!
Accessing Movieclips Inside A Loaded Swf
I have a movie where I am loading in a .swf file. This swf file has movieclips in it that are generated by a class. Essentially, the point of the class is to see movieclips inside of my external swf, duplicate them, then delete the originals so that the movieclips now have the methods and properties of my class avaliable for their use. Okay, now onto my problem. I compile this movie and it works fine. but when i try to access these movieclips from the main movie, like if i print out its abssolute path (with level0. blah blah), then it will trace nothing. this is driving me insane. any ideas?
Accessing MC Instances Inside Loaded SWF
Ok... I feel like an idiot. Although I've been working with AS3 since the start... and for the life of me I can't seem to access a movie clip instance inside a loaded SWF! I've searched high and low. Help is much appreciated.
Here's what I have: An external SWF named map.swf. Inside that is a movie clip instance named "portland_mc". Here's my code that doesn't work:
Code:
private var _mapLoader :Loader;
private var _mapLoaded :Boolean = false;
private var _myMap :MovieClip = new MovieClip();
public function LoadMap() :void
{
_mapLoader = new Loader();
_mapLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, DoneLoading);
_mapLoader.contentLoaderInfo.addEventListener("ioError", ErrorLoading);
_mapLoader.load(new URLRequest("assets/UI/map.swf"));
function DoneLoading(evt :Event) :void
{
trace("Done loading map!");
_mapLoaded = true;
_myMap = MovieClip(_mapLoader.content);
addChild(_myMap);
_myMap.portland_mc.gotoAndStop(1); // doesn't work!!!!
}
function ErrorLoading(evt :Event) :void
{
trace("Error! - Could not load external map SWF file!");
}
}
// Assume the nav button event has been declared and bound to this handler
public function MapButtonOnClick(evt :MouseEvent) :void
{
// Make sure map content is loaded
if (_mapLoaded)
{
// Play animation of portland_mc (a MC instance inside the loaded SWF)
_myMap.portland_mc.gotoAndPlay(2); // doesn't work either!!!!
}
}
Again, any help is appreciated.
Accessing Variables Inside Other Movieclips.
I'm currently learning OOP through Sen's information here at Kirupa, and I've decided to try out his "creatures" exercise mentioned in his Best of Senocular thread...I still have a bunch to learn, but I wanted to go ahead and ask a question for a problem I am having right now.
The situation is a random number of sprites are created, and they move around the stage, interacting. They all have a certain amount of "health," defined as a variable in a MovieClip prototype applied to the MC. When they hit, I want their health to go down a little bit, so how can I access a particular MC's "health" variable while I'm outside of the MC itself?
Accessing Variables From Inside The Instance
hello people !
straight to the point...
the thing is : i have defined a variable attached to a move clip via Mc.OnLoad = function *etc
so is it possible to access this variable from within the move clip ?
and if not is there another way to work this around ?
thanks in advance
Accessing Variables Inside Other Movieclips.
I'm currently learning OOP through Sen's information here at Kirupa, and I've decided to try out his "creatures" exercise mentioned in his Best of Senocular thread...I still have a bunch to learn, but I wanted to go ahead and ask a question for a problem I am having right now.
The situation is a random number of sprites are created, and they move around the stage, interacting. They all have a certain amount of "health," defined as a variable in a MovieClip prototype applied to the MC. When they hit, I want their health to go down a little bit, so how can I access a particular MC's "health" variable while I'm outside of the MC itself?
Accessing Variables From Inside Function
Hi there, for you experts this will be simple but I'm just starting on ActionScript so I'm rather useless
Code:
myData.load("detailclip_feedflash.php?ID=5002");
var myLinkers:Object = { before1:"33434", before2:"", before3:"", after1:"", after2:"", after3:"", pdf:"", clip:""};
myData.onLoad = function(succes){
if(succes){
// DO WORK
myLinkers.before1 = this.beforeimage1;
} else trace ("Error loading data")
}
I have a data object being set in the first frame of my video then I'm calling variables from a PHP file and planning to do some work then set the variables into a variable that can be accessed in ANY part of the current execution.
The issue is that it doesn't seem be modifying the variable outside the function. I thought I should use _global.myLinkers.before1 = "" but that didn't work either.
I know I'm missing something to access the variable but WHAT?
Arg.
Dynamically Accessing Array Variables
Here's my problem:
I am loading the variables for a page into an array. A couple of timelines into my movie I have a handy function to access one of those variables based on what number I feed the parameter of the function:
function image_display (i) {
caption = eval ("../../:page [../../:page_current].image_"+i+"_caption");
}
The idea is that I send this function "1" as a parameter and it will give me the value for "page [page_current].image_1_caption", which is on the root timeline (I like relative as opposed to absolute references, but it shouldn't make a difference either way).
The problem is that I cannot get this to come up with anything but "undefined". If I hardcode this without the "eval" statement and replacing the "i" with "1" it works fine, which says to me that I need to construct the variable I want to get differently, but I don't know how to do that.
Any thoughts?
Accessing Dynamically Created Variables
Hey Flash Kit!
If I dynamically create Movis Clips using this process:
Code:
var str:MovieClip
for (var i=0; i<=5; i++)
{
str = new star();
addChild(str);
str.x = 550*Math.random();
str.y = 400*Math.random();
var size = 5 * Math.random();
str.width = size;
str.height = size;
}
Is there any way to access the clips individually by number afterwards?
Thanks,
DHP
Accessing A Dynamic Textfield That's Inside A Loaded Swf
so I loaded a swf onto my stage using the Loader Class.
so when I trace this:
trace(stage.getChildByName('_loader'));
it returns [object Loader].
Ok so far.
But suppose I want to access a dynamic textfield that's inside the swf I just loaded. How would I access it?
This throws an error:
code: stage.getChildByName('_loader').data_txt.text = 'test';
so does this:
code: stage.getChildByName('_loader').getChildByName('da ta_txt').text= 'test';
Any help would be greatly appreciated.
Accessing _width Property Of Dynamically Loaded Image
Hi all,
Well this is really driving me nuts!
I am building a "thumbnail gallery" shall we say of dynamically loaded external images.
But for each of these images, the _width property remains stubbornly stuck at 0 throughout the life of the first-frame initialization scripting and related callbacks ( init --> XML.onLoad --> MovieClipLoader.onLoadComplete )
As I mention above, I am using the MovieClipLoader utility. (since this seems to be the only method I can use asynchronously). It would seem sensible that in the onLoadComplete callback, these parameters would be then available, but this is not the case.
The only way I have been able to so far access these values is by attaching some trace() commands to a button's onRelease handler.. I.e., after the movie is running and all the first-frame initialization stuff has finished..
I'm trying to stick with ActionScript 2.0 in this project... I think with 3.0 there is a BitMap class I could use.
Well, thanks for any help.. blargh this is making my brane hurt
Accessing Nested Clips In Dynamically Loaded Clip
I have the following scenario. I have an movie clip in my main fla library called "thumbnailobject". Inside this movie clip is a dynamic text field bound to a variable called "theText". I have exported this mc to a swf file.
What I would like to do is reuse this swf and load 5-10 instances of it into my main movie. Each time i load it, i want create another nested movie clip inside of it and fill it with a jpg thubmnail image. I also want to change the text of the pre-created text field to display a caption for the thumbnail.
So my current code looks like this. But it doesn't seem to work:
ActionScript Code:
_root.createEmptyMovieClip("container", 1);
loadMovie("thumbnailobject.swf", "container");
_root.container.createEmptyMovieClip("innercontainer", 2);
loadMovie("thethumbnail.jpg", "innercontainer");
theText = "This is my thumnail image caption"; //this part works
_root.createEmptyMovieClip("container2", 2);
loadMovie("thumbnailobject.swf", "container2");
_root.container2.createEmptyMovieClip("innercontainer2", 2);
loadMovie("thethumbnail.jpg", "innercontainer2");
theText = "This is my thumnail image caption"; //this part works
... and so on
Any ideas why this wouldn't work?
Dynamically Creating Empy Movieclips And Accessing Variables
The code at bottom of this page makes a row of 65 color swatches on the main stage at runtime. Now i understand all the code ( the loop is a bit tricky, but take my word for it creates 65 swatches that spread across the stage and are 10 pixels each.
The part i do NOT understand is this part i.e
Code:
mcSwatch.onRelease = function():Void {
trace(nColor);
};
(when we click on each swatch it shows us the color of each swatch in the output window)
THE question is when we test the movie and we click a swatch, how does it know what the value of nColor was when the swatch was created? Because i cant see the value of 'nColor' stored in any array or anything that would have allowed us to associate it with that particular swatch.
(what seems more obvious is that when we click any swatch it should just display the LAST value that nColor was given when the loop ended).
The full code is as below:
Code:
// Create a movie clip to hold the color selector.
var mcColorSelector:MovieClip = this.createEmptyMovieClip("mcColorSelector", this.getNextHighestDepth());
// Declare a variable to store the selected color.
var nSelectedColor:Number = 0;
createColorSelector();
// Create the color swatches.
function createColorSelector():Void {
var nColor:Number = 0;
for(var i:Number = 0; i < 5; i++) {
for(var j:Number = 0; j < 13; j++) {
createColorSwatch(nColor, (10 * i) + (50 * j), 375);
nColor += 17;
}
nColor += 1053475;
}
}
function createColorSwatch(nColor:Number, nX:Number, nY:Number):Void {
var nDepth:Number = mcColorSelector.getNextHighestDepth();
// Create a movie clip for the swatch.
var mcSwatch:MovieClip = mcColorSelector.createEmptyMovieClip("mcSwatch" + nDepth, nDepth);
// Draw a rectangle in the swatch. Fill the rectangle with the specified
// color.
mcSwatch.lineStyle(0, 0, 0);
mcSwatch.beginFill(nColor, 100);
drawRectangle(mcSwatch, 10, 18);
mcSwatch.endFill();
mcSwatch._x = nX;
mcSwatch._y = nY;
mcSwatch.onRelease = function():Void {
trace(nColor);
};
}
function drawRectangle(mcClip:MovieClip, nWidth:Number, nHeight:Number):Void {
mcClip.lineTo(nWidth, 0);
mcClip.lineTo(nWidth, nHeight);
mcClip.lineTo(0, nHeight);
mcClip.lineTo(0, 0);
}
Any help would be appreciated..its doing my head in!!! Ive attached the fla ..please help cheers
Problem Accessing Movie Clips Inside Of Loaded Swfs
Hey All;
Here's what I am having problems with. In swf movie A I have a movie clip on the stage with the instance name SQUARE. In swf movie B I load in swf movie A by using the following:
this.createEmptyMovieClip("world_mc", 999);
loadMovie("A.swf", world_mc);
Now... the following line of code gives me undefined:
trace (world_mc.SQUARE);
Why? Can I not access the movie clip SQUARE once swf A is loaded into swf B?
Thanks.
Accessing Loaded SWF's Variables
I'm using a Loader to load in a SWF. I can load it in ok, but I can't seem to access it's properties. There's a String 'url' that I want to set when it loads, but I keep getting errors.
Here's the (abreviated) code:
ActionScript Code:
loader.contentLoaderInfo.addEventListener(Event.INIT, initHandler);
function initHandler(event:Event):void {
addChild(loader);
trace(loader.content.url);
}
Comparing Variables Inside Functions To
Okay, here's another one for you...
var q4:Boolean = false; //Will have thirty-eight of these, q4-q41
function noRepeat() {
if (q(_root._currentframe) == true) {
gotoAndStop(randRange(4, 41));
} else if ((q(_root._currentframe)) == false) {
q(_root._currentframe) = true;
}
}
Now, my problem is the bits in red (yes, I know they don't work, that was just the best way I could think to describe what I wanted).
If I create a string that says "q4" then I find it won't compare that to the boolean variable, but I'm positive there must be a better way than putting one of these on every frame.
I'd love some advice on this one. It's hurting my head!
Functions Do Not Work Inside Externally Loaded Swf
Hey so my issue is this. I have a main fla file that loads three external swf files into movieclips that i dynamically created from the main movie timeline. they load just fine. but the thing is, the functions i created in the external swfs do not work. Ive been told its an issue with my levels and their scope. If someone can, please help me with this. and explain levels and scope to me.
chad
here is my work files. the masterfile that loads everything is autoXmain.swf/fla. the rest is self explanatory once u get inside.
http://wa-01.yousendit.com/transfer.php?action=download&ufid=D2FFFFD0297F82DE&rcpt=im@northstarassociates.com
Accessing Loaded Variables From Within A Function
I want to be able to load variables from a text file and use them to load corresponding flash files.
The variables load fine onto the root movie
ie PrintJob[1] = example.swf
But when I want to call the following function, It doesn't generate the correct address to load the movie from.
function load(path, arrayName, arrayNumber) {
file = Arrayname[arraynumber];
Goto = path + file;
loadMovieNum(goto, 10);
}
For example, the function is called using :
Load(content/print, PrintJob, 1)
It doesn't work
So I try
Load("content/print", "PrintJob", 1)
It doesn't work either.
So I change the function to this to test if the correct variable is being accessed:
function load(path, arrayName, arrayNumber) {
file = PrintJob[1];
Goto = path + file;
loadMovieNum(goto, 10);
}
And lo and behold, the Function cant asign the variable 'file' to the content of 'PrintJob[1]' even though PrintJob[1] exists as a loaded variable.
HELP ME FOR GODS SAKE
HOW do I access these variables from within a function.
Thanks
Accessing Variables In A .swf Loaded Into A Movieclip
Please could someone help me with this.
I am creating a teaching product. The shell .swf contains all the navigation controls for each lesson.
In the display area of the shell is a blank movie clip with instance name holder_mc.
I want to load the .swf for each lesson into the holder_mc and then use the shell movie to
- access variables in the lesson .swf (e.g. about number frames, etc)
- control the lesson .swf using goto frame labels in the lesson .swf
Even though I've tried all manner of paths, global variables and so-on I've found it impossible to get anything out of or into either .swf from the other or goto the lesson.swf to move to a frame label. The .swf loads fine and I can resize and move the holder_mc.
I'm using the following structure:
In the lesson .swf:
var testVariable:String = "success";
In the shell .swf
loadMovie("lesson.swf","holder_mc");
trace (holder_mc.testVariable); //returns undefined
holder_mc.gotoAndStop("frame I want"); // gets ignored
I've made sure I've created the .swf each time and tried every path I can think of.
Any help would be great.
Any clues why I can't get variables and move to frame labels?
Accessing Variables From A SWF Loaded In A UILoader
Greetings enlightened ones
Here's my problem:
I have a main swf movie in which a var is defined on its main timeline. I have a UILoader on that main timeline which loads an other SWF.
Here' what I need to do: How can I let the loaded SWF in the UILoader access that variable on the main timeline of the main swf?
Please help
Access Variables Declared Inside Functions
Hi guys, i have a problem in AS3
I have a problem with a function that needs to access a variable declared inside another function.
What I understand is how a variable can change due to var X:Number=0
because var PictureLink:String = Array[X] when X increments. What i don't understand is how when an event listener listens for a mouse click on a movieclip which load another movieclip with link PictureLink, it knows which Array[X] it is when the X has already incremented through all the pics.
By the tutorial I watched (Cartoon Smart AS3 XML Gallery), he said "we need to create variable PictureLink to store Array[X] at a particular time to when user click on thumbnail, it goes to the correct link.
This all worked fine but the code was getting too long and i wanted to seperate this massive functions into their own .as files, this is when it stuffed up.
WHY, because the loaded was refering to Array[X] when that var was declared in the previous function and now I can't reference it .
Here's my code. Some things aren't in the, like gallery pane and some other layout script because they're in other .as files, they won't matter though to solve the problem.
Code:
var mainPicArea:MovieClip = new MovieClip();
mainPicArea.buttonMode = true;
mainPicArea.useHandCursor = true;
addChild(mainPicArea);
var all_thumbs:MovieClip = new MovieClip();
all_thumbs.buttonMode = true;
all_thumbs.useHandCursor = true;
addChild(all_thumbs);
galleryPane.source = all_thumbs;
var fadeIn:Tween;
var fadeOut:Tween;
var urlVar:String = "xml/gallery.xml";
var highResPathList:Array = [];
var lowResPathList:Array = [];
var thumbPathList:Array = [];
var pictureTitleList:Array = [];
var pictureDescList:Array = [];
var totalPics:Number;
var mainPicPlacementX:Number;
var mainPicPlacementY:Number = 100;
//LOAD THUMBNAILS
var thumbLoader:Loader;
// variable for load thumbs function loop
var c:Number = 0;
// spacing between each thumb on x-axis. Number includes thumb width plus spacing
var xSpacing:Number = 105;
// spacing between each thumb on y-axis
var ySpacing:Number = 105;
//how many thumbs are occupying a row
var xs:Number = 0;
//how many thumbs are occupying a column
var ys:Number = 0;
var thumbRowCount:Number;
var thumbColumnCount:Number;
var thumb_orientation:String;
//////////////////////
function loadTheThumbs()
{
thumbLoader = new Loader();
var thumbRequest:URLRequest = new URLRequest(thumbPathList[c]);
thumbLoader.load(thumbRequest);
thumbLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, whenThumbsLoad);
function whenThumbsLoad(event:Event):void
{
var thisMainsLink:String = highResPathList[c];
var thisThumbsLink:String = lowResPathList[c];
var thisPicsTitle:String = pictureTitleList[c];
var thisPicsDesc:String = pictureDescList[c];
//spread thumnails along x-axis by xs
thumbLoader.x=(xs*xSpacing); //add pixels to end of equation for a buffer. For eg ....+8 (optional)
//spread thumnails along y-axis by ys
thumbLoader.y=(ys*ySpacing);
if (thumbColumnCount==0){
xs = xs + 1;
//trace("row space")
}
if (thumbRowCount==0){
//trace("column space")
ys = ys + 1;
}
if (thumbColumnCount==0 && xs==thumbRowCount) //if row has reached the max thumbs per row, then start a new row
{
//trace("row add")
//by reseting the x placement
xs = 0;
//on a different row
ys = ys + 1;
}
if (thumbRowCount==0 && ys==thumbColumnCount) //if row has reached the max thumbs per column, then start a new column
{
//trace("column add")
//by reseting the x placement
ys = 0;
//on a different row
xs = xs + 1;
}
thumbLoader.addEventListener(MouseEvent.CLICK, loadMainPic); //listener when thumbnail has been clicked
all_thumbs.addChild(thumbLoader);
c = c + 1;
if (c<totalPics)
{
loadTheThumbs(); // calls the first function in this file again (for the amount of thumbs)
} else {
xs=0;
ys=0;
c=0;
}
} // end if(c<totalPics)
} // end whenThumbsLoad
} // end loadTheThumbs
///////////////////
function loadMainPic(event:MouseEvent):void
{
thumbLoader.removeEventListener(MouseEvent.CLICK, loadMainPic);
if (mainPicArea.numChildren == 1){
mainPicArea.removeChildAt(0);
}
picDesc.text = "";
picTitle.text = "";
loadingText.x = mainPicPlacementX;
loadingText.y = mainPicPlacementY;
var mainLoader:Loader = new Loader();
var mainRequest:URLRequest = new URLRequest(thisThumbsLink); ////THIS IS THE PROBLEM, I CAN'T GET "thisThumbsLink from 'whenThumbsLoad function"
mainLoader.load(mainRequest);
mainLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, progressHandler); //listener while main pic loading
mainLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, mainLoaded); //listener when main pics has loaded
function progressHandler(event:ProgressEvent):void //pre-loader function
{
var kbLoaded:String = Number(event.bytesLoaded/1024).toFixed(1);
var kbTotal:String = Number(event.bytesTotal/1024).toFixed(1);
loadingText.text = "Loaded "+kbLoaded+" of "+kbTotal + " KB";
} // end progressHandler
function mainLoaded(event :Event):void
{
thumbLoader.removeEventListener(MouseEvent.CLICK, loadMainPic);
loadingText.text="";
if (thumb_orientation == "horizontal" || thumb_orientation == "vertical"){
mainPicPlacementX = (stage.stageWidth / 2) - (mainLoader.width / 2); //if you want mainPic to move on x-axis in relation to stage
mainPicArea.x=mainPicPlacementX;
}
mainPicArea.y=mainPicPlacementY;
mainPicArea.addChild(mainLoader);
fadeIn = new Tween(mainPicArea,"alpha", None.easeNone, 0, 1,1, true)
picTitle.text = thisPicsTitle;
picDesc.text = thisPicsDesc;
picTitle.x = mainPicArea.x;
picDesc.x = mainPicArea.x;
picTitle.y = mainPicArea.y + mainPicArea.height + 5;
picDesc.y = mainPicArea.y + mainPicArea.height + 20;
picTitle.width = mainPicArea.width;
picDesc.width = mainPicArea.width;
} //end mainLoaded
} // end loadMainPic
i'm new to as3 so i would love any knowledge on the issue or any direction. Also another thing i would love to know, how to send values from function along with eventListener, that would solve the problem, being able to send variables through the event listener into the function that gets triggered.
Cheers
KayaScript
Loop Variables Inside Inline Functions
A simple noobie question (it's probably been asked many times but my queries are not turning up anything -- I'm probably not using the right terminology):
I have this code that tries to call a function with the button index when the button is pressed.
Code:
private static function drawButtons():Void {
var btn:MovieClip = null;
for (var i:Number = 0; i < 7; i++) {
btn = _root.createEmptyMovieClip("btnColor" + i, 10 + i);
// btn.beginFill(), ... some lines ..., btn.endFill()
btn.onPress = function():Void { TestClass.changeColorSelection(i); }
btn._x = 8;
btn._y = 8 + (i * 33);
}
}
The problem is all buttons pass in the value of i == 8 (the value of i after the loop is done). How do I get them to use their own index?
Thanks!
Calling Functions Inside Loaded Movie Clips
"calling functions inside loaded movie clips" - Can this be done? If so, lets explore!
I did a search but could not come up with anything so I thought this would be a good thread to start and keep updated. Please use this to consolodate all information on this subject.
I realize that a class file would accomplish the tasks involved in OOP, but as a root designer and Flash beginner, it is easier to use SWF's.
Pet peeve: Posters not being explicit and concise in the Title when creating / replying to posts. I think we should all take our time to properly convey our thoughts when posting. Even for beginners (like me) who more often than not tend to rush to try to get the answer to get the job done. Does anyone agree with me?
LoadMovie - Accessing Variables Of Loaded Movie
I am trying to access variables of a mc loaded via loadMovie.
movie1 loadMovies movie2. Then from movie1 I want to get a variable value stored in movie2.
I'm setup like this:
1. movie2 has the following code on frame 1:
var foo='bar';
2. From movie1 I do the following in frame 1:
mcHolder.loadMovie(movie2);
3. From movie1 I do the following in mcHolder's object actions:
onClipEvent(data) {
trace(foo); <-- blank
}
What am I doing wrong?
TIA
Smapdi
Accessing Variables Loaded From An External Source
Hi,
I'm trying to load variables into flash from an external source and then, depending on whether the variable is true or false, make a movieclip do something.
so my external source is like this:
Quote:
&myVar=true&
and my loadVars is like this:
Quote:
var here = this;
my_lv = new LoadVars();
my_lv.load("external.txt");
my_lv.onLoad = function() {
booVar = this.myVar;
};
I have a text field on the main stage with a variable name of booVar and when the data is loaded in it displays 'true'
what i want to happen then is the movie clip on the stage to look at the variable 'booVar' and if its true, to start playing the movie clip
the code inside the movieclip is like this:
Quote:
stop();
if(_root.booVar == true) {
play();
}
am i just being dumb? can someone help me
thanks in advance
Trouble Accessing Variables From Root In Loaded Swf - AS3
I've searched the forums for days now and can't seem to figure this out. I'm building a flash site using AS3 that loads the individual pages into a single movie. The problem I'm having is I can't get the loaded swf to see variables that are set in the root movie.
For example... The site is for a construction company and I've created a dynamic image gallery. The gallery is divided into different catagories (embassies, churches, commercial, etc...) and the user chooses one of those catagories from the XML generated main menu located in the root movie. That loads the image gallery page into the root movie. The image gallery should then call a php page which returns the selected catagory from my database. I can't figure out how to get the gallery swf that was loaded into the root movie to know which catagory it should send to the php page.
I'm trying to set a variable when catagory is selected, "returncatagory.php?catagory=churches" for example, and have the image gallery use that for its URL request.
Any thoughts????
Accessing Variables Loaded From An External Source
Hi,
I'm trying to load variables into flash from an external source and then, depending on whether the variable is true or false, make a movieclip do something.
so my external source is like this:
Quote:
&myVar=true&
and my loadVars is like this:
Quote:
var here = this;
my_lv = new LoadVars();
my_lv.load("external.txt");
my_lv.onLoad = function() {
booVar = this.myVar;
};
I have a text field on the main stage with a variable name of booVar and when the data is loaded in it displays 'true'
what i want to happen then is the movie clip on the stage to look at the variable 'booVar' and if its true, to start playing the movie clip
the code inside the movieclip is like this:
Quote:
stop();
if(_root.booVar == true) {
play()
am i just being dumb? can someone help me
thanks in advance
Dynamically Loaded Clips With External Images & Specific Functions
Hi fellow flash developers
I'm trying to build a little function that loads some variables from an online PHP file, where I get the number of existing elements, the correspoding thumbnails and the associated text for each. This elements are to be placed horizontally 120pix right after each other. For this, I chose to use a "for in" loop, that executes the number of times equivalent to the number of elements retrieved from the variable in the PHP file the SWF connects to.
Unfortunately the PHP file still doesn't have the paths to the thumbnails set in any variable, so for purposes of testing I am loading these thumbnails from the hard disk. They are in the SWF's folder.
The connection with the PHP is working fine, I am able to get the number of elements in it. The address if you want to check the variables, is http://www.imaginando.net/resin/traction.php .
So, in a more synthetic way, how do I get these images to appear on each corresponding clip I create, and how do I make them have a specific .onRelease function?
Going through the script helps to understand
Quote:
//declare the thumbnails's pictures array
releasesArray = new Array("RSI001small.gif", "RSI002small.gif", "RSI003small.gif", "RSI004small.gif");
//load the number of elements from the PHP
loadReleases = new LoadVars();
loadReleases.load("http://www.imaginando.net/resin/traction.php");
loadReleases.onLoad = function() {
//the number of elements is the variable ntractions
_global.numberOfElements = this.ntractions;
trace(numberOfElements); //this shows 10 in the output panel, there are 10 elements
//let this loop 10 times then.
for (i=0; i<numberOfElements; i++) {
//the next line of code is my attempt to set the "currentTractionImage" to "RSI001small.gif", doesn't seem to work
currentTractionImage = releasesArray[i];
trace(currentTractionImage); //this unfortunately outputs underfined
//get the button instance from the library (linkage id "traction_element", containing an MC with the instance name "holder_mc" where I would like to place an image from the SWFs folder, more precisely the actual [i] element of releasesArray:
var currentTractionItem = _root.attachMovie('traction_element', 'traction_element'+i, i);
//place the newly created item 120pix to the right
currentTractionItem._x += i*120;
//here I try to dinamically load the external GIF but the requested releasesArray's value is not retrieved
currentTractionItem.holder_mc.loadMovie(releasesAr ray[i]);
//the following command tests the button's activity, and works
//> //how do I apply a specific action for each?
currentTractionItem.onRelease = function() {
trace("button pressed");
}
//yet another yellow attempt to reach releasesArray's content
var imagetoLoad = ["RSI00"+i+"small.gif"];
trace("imageToLoad = " + imageToLoad); //outputs undefined
}
}
stop();
so.. that's my frustrated attempt to do it, and what fails is listed in the code's comments. If you see any mistake or any suggestion to make, I thank you in advance!
Duping Dynamically Loaded Jpg Inside Mc?
I have a rather large image (120k) that I'm loading dynamically into an empty mc, is there a way that I can dupe the mc (or even better, dupe the jpg) so that I don't have to load the image twice? In my experimenting, when I dupe the movie clip, it only dupes the empty clip and not the image inside it. I just don't want to have to have the user wait to dl both...
I'm checking to see the image has fully loaded before the duplication, thinking that after that the image would cache and it would come up quicker; however testing it on my server out in internet land it seems as if each time the image is requested i have to wait for the new instance of the image to load as well...
Any help would be much appreciated!
Calling Functions / Setting Variables In Loaded SWF
You know how you can create a Movieclip object, add a function or variable to it, then call that function or change that variable from within the SWF that includes it? I wanna be able to do that, only with SWFs that are loaded at run time.
My "main" SWF is simply a menu-type thing. The user clicks a button in my MAIN.SWF, and the MAIN.SWF then loads the SWF that's associated with that button, using the AS 3.0 prescribed Loader()-URLRequest()-addChild() method that everyone always asks about.
This works great. But now I've got some custom objects and such (ie., not just strings) within my MAIN.SWF that I'd like to be able to share with the loaded SWFs. Preferably, I'd like to use an accessor-type function (ie., LoadedSWF.GiveMeTheCoolObject(MyCoolObject);), though at this point I'm willing to hack into the object itself (ie., LoadedSWF.CoolObject.CoolField = MyCoolObject.CoolField;) if that's what it takes.
I've tried just calling the functions and setting the fields, but the AS 3.0 compiler doesn't care for that sort of nonsense on it's generically-defined objects. Notice also that, at run time, a call to LoadedSWF.hasOwnObject("GiveMeTheCoolObject") returns true.
So my big-brained colleagues, what's the magic?
In advance, thanks for the help!
Scott
Dynamically Creating Variables Inside A Loop
I am doing a for() loop. well, can i create variables dynamically inside this loop so that it will look like this:
for (i=0; i=5; i++) {
var (friend+i):String;
}
so that the variables names will be : friend1, friend2, friend3, friend4, friend5 ...
or if that isn't possible, can i refer to a bunch of variables dynamically? because in PHP, it 'echoes' back to flash 'dynamically' created variables but i need to assign and 'refer' to these variables for different instances of this movie clip that has a text field.
the location of this text field is:
_root.friendHolder1.name.text and i want name inside friendHolder1 to have the value of friend1.
and in the same way, _root.friendHolder2.name.text to have the value for friend2 and on and on.
basically (its just an attempt) i'm trying to create smthing that is like myspace. but i have some neat stuff planned for it that myspace doesn't have. so i really need this thing to work. can someone help me out...PLEASE!!! I'm ripping my head here
thanx
Dynamically Put Variables Inside A Movie Clip
In the past, I could dynamically add variables to a movie clip to assign values to them so that I was able to read them later per movie clip.
It doesn't seem like I can do this now. Is there anyway to do it?
Also, this is in a class, and when the student has answerd the quesiton, I need variables to be set from the main stage. (nextEnabled, backEnabled for buttons to become active). So on a side note, from a class, how do I set variables in the main stage?
thanks in advance
This is for a XML generated exam, and I'm creating the answers dynamically here:
Attach Code
for(var i:uint=0; i<ansTot; i++) {
var arNum:uint = Number(listArray[i]);
var disMC:MovieClip = new MovieClip();
var ansText:TextField = new TextField();
disMC.addChild(ansText).name = "ansText";
ansText.x = 15;
if(i == 0) {
thisY = stemText.height + 20;
ansText.y = thisY;
} else {
ansText.y = thisY;
}
ansText.width = 969;
ansText.autoSize = TextFieldAutoSize.LEFT;
ansText.styleSheet = quesCSS;
ansText.wordWrap = true;
ansText.multiline = true;
ansText.selectable = false;
ansText.condenseWhite = true;
ansText.antiAliasType = "advanced";
//ansText.border = true;
ansText.borderColor = 0xFFFFFF;
ansText.htmlText = "<span class='n'>" + formatScreenText(subXML[arNum]) + "</span>";
disMC.defaultText = formatScreenText(subXML[arNum]);
disMC.remediation = subXML[arNum].@remediation;
disMC.isCorrect = subXML[arNum].@correct;
disMC.addEventListener(MouseEvent.CLICK, answerClicked);
thisY += ansText.height + 10;
this.addChild(disMC);
}
private function answerClicked(event:Event):void {
var myAns = event.target;
if(this.isCorrect == "1") {
this.ansText.htmlText = "<span class='cor'>" + this.defaultText + "</span>";
} else {
this.ansText.htmlText = "<span class='wng'>" + this.defaultText + "</span>";
}
}
Dynamically Creating Variables Inside A Loop
I am doing a for() loop. well, can i create variables dynamically inside this loop so that it will look like this:
for (i=0; i=5; i++) {
var (friend+i):String;
}
so that the variables names will be : friend1, friend2, friend3, friend4, friend5 ...
is this possible? thanks guys?
How To Place Images Inside Dynamically Loaded Text
I'm wondering if anyone could advise me on how to place images inside dynamically loaded text.
I have a textfield loading text from an external file - I'd like to have images wrapped in the text, like any html page - any ideas?
I tried using html <image> tags to mark up a layout, but flash doesn't really support html, not really, they say they do, but really they only support <a> and a few other tags - woot!
Thanks!
|