Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / Flash / Flash Actionscript / July 2005



Tip: Looking for answers? Try searching our database.

Referencing an instance within a dynamically attached mc

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
phillyj - 22 Jul 2005 05:43 GMT
Hi,

I'm just delving into attachMovie for the first time, and pulling my hair out
trying to get it working right.

I'm attaching a movie using the following code (this is within a loop):

_root.nav5_mc.sets_mc.attachMovie([this.thisMC], "collection_mc",
this.getNextHighestDepth());

Then, I want to be able to adjust the _alpha value of an instance that is
within the "collection_mc" movieclip.  I tried this:

_root.nav5_mc.sets_mc.collection_mc.thumb1..onRollOver = function() {
        this._alpha =10;
};

But nothing happens.  I actually can't even seem to adjust the _alpha value of
the movieclip itself by using:

_root.nav5_mc.sets_mc.collection_mc.onRollOver = function() {
        this._alpha =10;
};

From the book I have, this seems like the way you're supposed to do it, but
obviously I must be doing something wrong.
jwize - 22 Jul 2005 06:04 GMT
would something like this work? I am new to but I think it might.

var my_mc = _root.attachMovieClip(....);

my_mc.onClick = function () { // I think click is only available to buttons.
// Do something.
}
phillyj - 22 Jul 2005 06:45 GMT
I gave that a shot - it didn't work.  Same result as before, nothing happens.
sampurtill - 22 Jul 2005 07:43 GMT
var newMc = _root.nav5_mc.sets_mc.attachMovie([this.thisMC], "collection_mc", this.getNextHighestDepth());
newMc.onRollOver = function(){
newMc._alpha = 10;
}

Try that.
sampurtill - 22 Jul 2005 07:44 GMT
Wait have you given all your new movies properties such as _x and _y? Or are they all stacked on eachother? I ran into this problem when I was a newbie...
sampurtill - 22 Jul 2005 07:46 GMT
var rows:Number = 10;
var cols:Number = 10;
for (i=0; i<rows; i++) {
    for (j=0; j<cols; j++) {
        var newImage = imagesHolder.attachMovie("flower", "flower"+i+j,
imagesHolder.getNextHighestDepth());
        newImage._x = i*flower._width;
        newImage._y = j*flower._height;
        newImage.num_txt.text = i+""+j
    }
}

// have an empty movieclip on the timeline called imagesHolder, and a
movieclip in the library linked as "flower".

try that and see what it does.
phillyj - 29 Jul 2005 06:40 GMT
What I'm trying to figure out is, in that last example, is "num_txt" a
textfield that exists within the "flower" movie clip?

Because this is basically what I'm trying to do (with another button, not a
textfield), and having no success.  First, I attach the movie like so:

var newsPictures = this.sectionPics_mc.attachMovie("newsPics_mc", "name",
this.getNextHighestDepth());

Then I try to use news1_btn, which is within the newsPics_mc movie clip, using
the variable name like you suggested:

newsPictures.news1_btn.onRelease = function() {
  trace("Success.");
};

Only I never have "Success" when clicking news1_btn, so I must not be
referring to that button correctly.

Any help?
sampurtill - 29 Jul 2005 07:26 GMT
Yeah, sorry, num_txt is inside the flower movieclip. Do you want to be able to
make each button say "Success" when you press them? Just try this code...

function successButton(button_mc:MovieClip){
button_mc.onRelease = function(){
trace("Success");
}

 var rows:Number = 10;
var cols:Number = 10;
for (i=0; i<rows; i++) {
for (j=0; j<cols; j++) {
var newImage = imagesHolder.attachMovie("flower", "flower"+i+j,
imagesHolder.getNextHighestDepth());
newImage._x = i*flower._width;
newImage._y = j*flower._height;
successButton(newImage)
}
}
phillyj - 29 Jul 2005 16:30 GMT
This is a little closer to what I want.  I don't know - maybe I'm trying to do
something that can't be done.  I'll try to explain myself a little more clearly.

The buttons I want to control are within the attached movie clip.  Normally
this would not be a problem, if the movie clip itself were on the stage.  This
movie clip is in the library and being attached dynamically, so I just can't
seem to access the buttons withiln it.  (The buttons aren't attached
dynamically themselves - they just exist within the movie clip).

When I used your code, it worked when I clicked on any part of the attached
movie clip itself (newImage), but I need to be able to specifcally click on
each button within it (also, for some reason, it stopped the over & down phases
of my buttons from working).  I tried to edit it with no sucess.  Here's what I
did, to give you an idea of what I'm trying to get at:

function successButton(button_mc:MovieClip){
    button_mc.onRelease = function(){
        trace("Success");
    }
}

    var newImage = sectionPics_mc.attachMovie("pics_mc", "newsPics_mc",
this.getNextHighestDepth());
    var button = (newImage + ".news1_btn");
    successButton(button)

If I trace the value of "button", it seems to point directly at my news1_btn,
yet nothing happens when I click it.

There are multiple buttons within newImage, and they all actually open up
different URLs, but I can deal with that part later - I'm just trying to get
them to work (which is why I was using the trace("Sucess")).
sampurtill - 29 Jul 2005 17:55 GMT
Oh ok, all you have to do then is

successButton(newImage.news1_btn);

Don't use var button or successButton(button), it should work like that if
you've named the mc inside the attached movieclip news1_btn
phillyj - 01 Aug 2005 00:10 GMT
Thanks!  That worked.  I'm wondering if there's a way to make the code so it
works for multiple buttons, without having to create a new copy of the function
for each button.  Here's what I have right now for my first 2 buttons:

function successButton(button_mc:MovieClip){
    button_mc.onRelease = function(){

        getURL("javascript:openNewWindow('news1.htm','news','height=425,width=615,tool
bar=no,scrollbars=no')");
    }
}
function successButton2(button_mc:MovieClip){
    button_mc.onRelease = function(){

        getURL("javascript:openNewWindow('news2.htm','news','height=425,width=615,tool
bar=no,scrollbars=no')");
    }
}
var newImage = sectionPics_mc.attachMovie("newsPics_mc", "newsPics_mc",
this.getNextHighestDepth());
successButton(newImage.news1_btn);
successButton2(newImage.news2_btn);

It seems clumsy, and like there should be a way to pass a variable to the
function, so that I could just use 1 function, but I can't figure out how.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.