• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Cannot convert to flash.display:DisplayObject

New Here ,
Feb 03, 2011 Feb 03, 2011

Copy link to clipboard

Copied

Hey all, my first post so bear with me, hopefully I can explain what it is I'm trying to do ...

I have an empty mc on the stage called "infoloader" and I'm trying to dynamically load a mc called "my_info0" from the library into the empty "infoloader".

My function references an XML array of thumbnails, which trigger movieclips to load into the FLVPlayback depending on which thumbnail is clicked.

====================

//function to load videos
function callVideo(e:MouseEvent):void{
var video_url = my_images[e.target.name].@VIDEO;
vidplayer.source = video_url;
vidplayer.play();
}

====================

All is good there.

I also have a mouse over listener to drop info about the video for each thumbnail. (it actually just plays the referenced clip)

====================

//Mouse Over Functions - drops descriptions
function descDrop(e:MouseEvent):void{
var t = "dropVid" + [e.target.name];
this.gotoAndPlay("down");
}

====================

So far so good.

Using the same concept as the mouse over listener I thought I could load a referenced movie clip from the library, "info0", into my empty movie clip on the stage "infoloader".

====================

//Function to load video info
function callDescription(e:MouseEvent):void{
var d = "info" + [e.target.name];
infoloader.addChild(d);
//trace(d);
}

====================

No cigar so far.

If I trace "d" I get what I want ... info0 ... but I can't seem to get it to load the "info0" mc into the "infoloader".

I've tried a whack of ideas, but I'm open to any suggestions.

(I want to include buttons in "info0" so I don't want to just add text to my xml file and load that)

This is what I'm looking to accomplish ... http://coleclark-america.com/sn2010.asp

This is last years version and doesn't use xml, but had a whole lotta repeated code, just trying to expedite.

Hopefuly there's enough code here, if not, let me know.

Thanks in advance,

Ter

TOPICS
ActionScript

Views

2.5K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 03, 2011 Feb 03, 2011

Copy link to clipboard

Copied

This line...

var d = "info" + [e.target.name];

is creating a string.  A string is not a display object.  You mentioned something about it being a library object.  Is that the class name that you have assigned to the object in the library (not its library name)?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 03, 2011 Feb 03, 2011

Copy link to clipboard

Copied

Hey Ned,

Thanks for the quick response.

Yes, that's the class name I've given it (it's also the object name).

I'm assuming I need to somehow convert the string "info0" to reference the object but not sure how.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 03, 2011 Feb 03, 2011

Copy link to clipboard

Copied

I notice if I create a var in my function ...

//Function to load video info
function callDescription(e:MouseEvent):void{

var my_info0:MovieClip = new info0();
//var d = "info" + [e.target.name];
infoloader.addChild(my_info0);
//trace(d);
}

It loads as expected.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 03, 2011 Feb 03, 2011

Copy link to clipboard

Copied

To use a String to dynamically create a class instance, you need to use something like the following...

var ClassRef:Class = Class(getDefinitionByName("className"));  // your string in place of className
var classInstance:* = new ClassRef();
addChild(classInstance);

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 03, 2011 Feb 03, 2011

Copy link to clipboard

Copied

Hmmm, over my head but I get the concept.

If I add your code ...

function callDescription(e:MouseEvent):void{
var d = "info" + [e.target.name];
var ClassRef:Class = Class(getDefinitionByName("d"));
var classInstance:* = new ClassRef();
infoloader.addChild(classInstance);

}

I get ...

Error #1065: Variable d is not defined.
at global/flash.utils::getDefinitionByName()

If I comment out var d and replace d in the next line with "info0" it loads fine.

function callDescription(e:MouseEvent):void{
//var d = "info" + [e.target.name];
var ClassRef:Class = Class(getDefinitionByName("info0"));
var classInstance:* = new ClassRef();
infoloader.addChild(classInstance);

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 03, 2011 Feb 03, 2011

Copy link to clipboard

Copied

Yep, you put quotes around strings and you don't put quotes around variables that have string values.

var ClassRef:Class = Class(getDefinitionByName(d));

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 03, 2011 Feb 03, 2011

Copy link to clipboard

Copied

Ned ... You are the MAN!!

Thanks, that did it.

I thought it was strange that it had quotes, but yours had it so I had it, meant to try a test removing the quotes but forgot.

In case anyone else has this problem ...

function callDescription(e:MouseEvent):void{
var d = "info" + [e.target.name];
var ClassRef:Class = Class(getDefinitionByName(d));
var classInstance:* = new ClassRef();
infoloader.addChild(classInstance);
}

Now I just have to do a little research to understand "why" it works.

Thanks again.

Ter

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 03, 2011 Feb 03, 2011

Copy link to clipboard

Copied

LATEST

You're welcome Ter.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines