Link to home
Start Free TrialLog in
Avatar of BloodGrinder
BloodGrinderFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Using the same function with different extended object types

Hi still being very green with Actionscript, I wonder if you could help with the following,

For the sake of an example think of a page in a book where,

I have 4 seperate classes,  ParagraphData, PartHeadingData, FooterData and ListData each which extend from the PageItemData class, a pageItem being its namesake on a page and each class has a different set of extended properties

Each "page of the book" as such is presented in an array called pageData and contains for example 3 instances of ParagraphData, 1 PartHeadingData , 1 list etc
 
What I need to do is iterate over the pageData array and act accordingly depending on what object type is currently being examined.

I have tried the following but with no success.

for each (var pageItem:PageItemData in pageData){
                        
      //check for prefix span and add if true            
                        if (pageItem.has_Prefix_Span && pageItem.prefix_Span_Text!==""){
                              createParagraphPrefixSpan(pageItem,pElem)
                        }
                              
      //check for inline graphic      
                        if ((pageItem.paragraph_Contains_Figure)as ParagraphData){
                        pElem=figure.checkForFigure(pageItem,pElem,figureData);
                        }

The first portion works because of the properties within the PageItemData class which are common to all , but the second does not ,even if I try to cast to the correct datatype, the compiler keeps complaining about


1118: Implicit coercion of a value with static type vo:PageItemData to a possibly unrelated type vo:ParagraphData

1119: Access of possibly undefined property paragraph_Contains_Figure through a reference with static type vo:PageItemData

I know I could replace the first line with

for each (var pageItem:* in pageData){

but this seems odd to me seing as all the items being iterated over are extended from the type shown.

What am I missing here and thanks in advance

John


}
ASKER CERTIFIED SOLUTION
Avatar of ChristoferDutz
ChristoferDutz
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of BloodGrinder

ASKER

Apologies I thought i had closed this 3 days ago