Referencing objects inside an object

Beginning in Flash here!!!

Ive got a flash Document, that I have a command button on, which should set the contentPath of a loader component to an image, problem is, if he image component is on the same scene, it works great, however put it on a different scene, doesnt work at all

I tried to upload an example, but the extension isnt allowed!

HELP!!!!

Tony
tonelm54Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

trigger-happyCommented:
I would suggest that you avoid the use of scenes as it really gets in the way of how you are to use actionscript code. Another thing to note is that the component must really be on the same scene. If you need to hide the component from view, I would suggest that you just set the visibility property to false.

--trigger-happy
0
blue-genieCommented:
i agree with trigger-happy about using scenes but if you absolutely have to, look at this example.
I don't know what you're doing a you've not provided any clues in terms of code snippets.

assuming in scene1 i have the button, and scene 2 i have the loader component...
and you're trying to have the button in scene 1, when you click that it goes to scene 2 and the component loads what it needs to...
so in scene 1....

stop();
var imgPath:String = "test.gif";
com_btn.onRelease = function() {
      nextScene();      
};
 then in scene 2 ....
myLoader.contentPath = imgPath;

blu.
0
julianopolitoCommented:
the problem with scenes is that there are no scenes actually. Compiler turns scenes into labeled keyframes. When you create a keyframe every object in that keyframe is a newborn. So it is completely reinitialized . That's why you must not try to keyframe components or other dynamic objects, because flash has trouble keeping their state. So the best to do is really programmatic animation as suggested. But if you can't for some reason, and need to keep it with scenes, remember that everything you do in scene one to initialize the component , you must redo in scene 2, 3 or 4 so flash knows what you want. blue-genie solution might work well.

I would add to that :
//Scene 1 - frame 1
 stop();
var imgPath:String = "";
com_btn.onRelease = function() {
      imgPath = "img1.jpg";
      myLoader.contentPath = imgPath;
      nextScene();      
};
com2_btn.onRelease = function() {
      imgPath = "img2.jpg";
      myLoader.contentPath = imgPath;
      nextScene();      
};

//Scene 2 - frame 1
myLoader.contentPath = imgPath; //here you are just reloading the image. since it is already in the browser's cache, it will load almost instantaneously. Repeat it for every scene.


Also remember not to use keyframes in the layer where this component is during it's lifetime. If you do, you may need to do that of frame 1 for every keyframe, and depending on what you are doing it may not work.





0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Adobe Flash

From novice to tech pro — start learning today.